From bdd0a41aed7edf21ec2a65cfa17a86af2ef8c48a Mon Sep 17 00:00:00 2001 From: dims Date: Tue, 17 Jun 2008 00:23:01 +0000 Subject: Move Tuscany from Incubator to top level. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@668359 13f79535-47bb-0310-9956-ffa450edef68 --- .../1.0-RC1b/modules/assembly-java-dsl/DISCLAIMER | 8 + .../sca/1.0-RC1b/modules/assembly-java-dsl/LICENSE | 205 ++++ .../sca/1.0-RC1b/modules/assembly-java-dsl/NOTICE | 6 + .../sca/1.0-RC1b/modules/assembly-java-dsl/pom.xml | 38 + .../tuscany/sca/assembly/dsl/AssemblyBuilder.java | 37 + .../tuscany/sca/assembly/dsl/ComponentBuilder.java | 34 + .../sca/assembly/dsl/ComponentPropertyBuilder.java | 28 + .../assembly/dsl/ComponentReferenceBuilder.java | 36 + .../sca/assembly/dsl/ComponentServiceBuilder.java | 32 + .../tuscany/sca/assembly/dsl/CompositeBuilder.java | 29 + .../sca/assembly/dsl/impl/AssemblyBuilderImpl.java | 70 ++ .../assembly/dsl/impl/ComponentBuilderImpl.java | 74 ++ .../dsl/impl/ComponentPropertyBuilderImpl.java | 40 + .../dsl/impl/ComponentReferenceBuilderImpl.java | 77 ++ .../dsl/impl/ComponentServiceBuilderImpl.java | 62 + .../assembly/dsl/impl/CompositeBuilderImpl.java | 62 + .../sca/assembly/dsl/AccountDataService.java | 24 + .../sca/assembly/dsl/AccountDataServiceImpl.java | 24 + .../tuscany/sca/assembly/dsl/AccountService.java | 24 + .../sca/assembly/dsl/AccountServiceImpl.java | 24 + .../tuscany/sca/assembly/dsl/BigBankBuilder.java | 59 + .../sca/assembly/dsl/BigBankBuilderTestCase.java | 38 + .../sca/assembly/dsl/StockQuoteService.java | 24 + .../sca/1.0-RC1b/modules/assembly-xml/.checkstyle | 24 + tags/java/sca/1.0-RC1b/modules/assembly-xml/.pmd | 20 + .../sca/1.0-RC1b/modules/assembly-xml/.ruleset | 190 +++ .../sca/1.0-RC1b/modules/assembly-xml/DISCLAIMER | 8 + .../java/sca/1.0-RC1b/modules/assembly-xml/LICENSE | 205 ++++ tags/java/sca/1.0-RC1b/modules/assembly-xml/NOTICE | 6 + .../java/sca/1.0-RC1b/modules/assembly-xml/pom.xml | 104 ++ .../sca/assembly/xml/BaseAssemblyProcessor.java | 597 ++++++++++ .../xml/ComponentTypeDocumentProcessor.java | 124 ++ .../assembly/xml/ComponentTypeModelResolver.java | 63 + .../sca/assembly/xml/ComponentTypeProcessor.java | 354 ++++++ .../assembly/xml/CompositeDocumentProcessor.java | 124 ++ .../sca/assembly/xml/CompositeModelResolver.java | 83 ++ .../sca/assembly/xml/CompositeProcessor.java | 766 ++++++++++++ .../apache/tuscany/sca/assembly/xml/Constants.java | 91 ++ .../xml/ConstrainingTypeDocumentProcessor.java | 121 ++ .../xml/ConstrainingTypeModelResolver.java | 83 ++ .../assembly/xml/ConstrainingTypeProcessor.java | 256 ++++ .../assembly/xml/DefaultBeanModelProcessor.java | 246 ++++ .../assembly/xml/PolicyAttachPointProcessor.java | 255 ++++ ...tuscany.sca.contribution.resolver.ModelResolver | 20 + .../sca/assembly/xml/BuildPolicyTestCase.java | 155 +++ .../sca/assembly/xml/MockPolicyProcessor.java | 72 ++ .../tuscany/sca/assembly/xml/ReadAllTestCase.java | 165 +++ .../sca/assembly/xml/ReadDocumentTestCase.java | 241 ++++ .../tuscany/sca/assembly/xml/ReadTestCase.java | 103 ++ .../sca/assembly/xml/ResolvePolicyTestCase.java | 198 ++++ .../tuscany/sca/assembly/xml/ResolveTestCase.java | 115 ++ .../sca/assembly/xml/TestModelResolver.java | 63 + .../assembly/xml/TestSCABindingFactoryImpl.java | 35 + .../sca/assembly/xml/TestSCABindingImpl.java | 189 +++ .../tuscany/sca/assembly/xml/WireTestCase.java | 123 ++ .../tuscany/sca/assembly/xml/WriteAllTestCase.java | 134 +++ .../sca/assembly/xml/AnotherDefinitions.xml | 84 ++ .../tuscany/sca/assembly/xml/Calculator.composite | 53 + .../xml/CalculatorComponent.constrainingType | 34 + .../sca/assembly/xml/CalculatorImpl.componentType | 31 + .../sca/assembly/xml/JavaScriptReference.composite | 37 + .../sca/assembly/xml/RMIBindingTest.composite | 43 + .../sca/assembly/xml/TestAllCalculator.composite | 128 ++ .../sca/assembly/xml/TestAllDivide.composite | 56 + .../assembly/xml/TestAllPolicyCalculator.composite | 131 +++ .../tuscany/sca/assembly/xml/definitions.xml | 175 +++ .../sca/1.0-RC1b/modules/assembly-xsd/DISCLAIMER | 8 + .../java/sca/1.0-RC1b/modules/assembly-xsd/LICENSE | 244 ++++ tags/java/sca/1.0-RC1b/modules/assembly-xsd/NOTICE | 12 + .../java/sca/1.0-RC1b/modules/assembly-xsd/pom.xml | 31 + .../src/main/resources/sca-binding-ejb.xsd | 43 + .../src/main/resources/sca-binding-jms.xsd | 135 +++ .../src/main/resources/sca-binding-sca.xsd | 23 + .../src/main/resources/sca-binding-webservice.xsd | 26 + .../assembly-xsd/src/main/resources/sca-core.xsd | 350 ++++++ .../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-java.xsd | 24 + .../main/resources/sca-implementation-spring.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 | 76 ++ .../assembly-xsd/src/main/resources/sca.xsd | 22 + .../main/resources/tuscany-sca-binding-atom.xsd | 40 + .../src/main/resources/tuscany-sca-binding-dwr.xsd | 40 + .../main/resources/tuscany-sca-binding-http.xsd | 40 + .../main/resources/tuscany-sca-binding-jsonrpc.xsd | 40 + .../resources/tuscany-sca-binding-notification.xsd | 42 + .../src/main/resources/tuscany-sca-binding-rmi.xsd | 43 + .../src/main/resources/tuscany-sca-binding-rss.xsd | 40 + .../resources/tuscany-sca-implementation-node.xsd | 42 + .../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-xquery.xsd | 42 + .../src/main/resources/tuscany-sca-include.xsd | 31 + .../src/main/resources/tuscany-sca.xsd | 44 + .../java/sca/1.0-RC1b/modules/assembly/.checkstyle | 24 + tags/java/sca/1.0-RC1b/modules/assembly/.pmd | 21 + tags/java/sca/1.0-RC1b/modules/assembly/.ruleset | 190 +++ tags/java/sca/1.0-RC1b/modules/assembly/DISCLAIMER | 8 + tags/java/sca/1.0-RC1b/modules/assembly/LICENSE | 205 ++++ tags/java/sca/1.0-RC1b/modules/assembly/NOTICE | 6 + tags/java/sca/1.0-RC1b/modules/assembly/pom.xml | 44 + .../tuscany/sca/assembly/AbstractContract.java | 77 ++ .../tuscany/sca/assembly/AbstractProperty.java | 122 ++ .../tuscany/sca/assembly/AbstractReference.java | 43 + .../tuscany/sca/assembly/AbstractService.java | 28 + .../tuscany/sca/assembly/AssemblyFactory.java | 156 +++ .../java/org/apache/tuscany/sca/assembly/Base.java | 43 + .../org/apache/tuscany/sca/assembly/Binding.java | 56 + .../org/apache/tuscany/sca/assembly/Callback.java | 40 + .../org/apache/tuscany/sca/assembly/Component.java | 132 +++ .../tuscany/sca/assembly/ComponentProperty.java | 74 ++ .../tuscany/sca/assembly/ComponentReference.java | 73 ++ .../tuscany/sca/assembly/ComponentService.java | 59 + .../apache/tuscany/sca/assembly/ComponentType.java | 77 ++ .../org/apache/tuscany/sca/assembly/Composite.java | 108 ++ .../tuscany/sca/assembly/CompositeReference.java | 37 + .../tuscany/sca/assembly/CompositeService.java | 56 + .../tuscany/sca/assembly/ConstrainingType.java | 72 ++ .../org/apache/tuscany/sca/assembly/Contract.java | 81 ++ .../sca/assembly/DefaultAssemblyFactory.java | 31 + .../apache/tuscany/sca/assembly/Extensible.java | 37 + .../tuscany/sca/assembly/Implementation.java | 28 + .../apache/tuscany/sca/assembly/Multiplicity.java | 49 + .../tuscany/sca/assembly/OptimizableBinding.java | 66 ++ .../org/apache/tuscany/sca/assembly/Property.java | 41 + .../org/apache/tuscany/sca/assembly/Reference.java | 56 + .../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 ++ .../assembly/builder/ComponentPreProcessor.java | 28 + .../sca/assembly/builder/CompositeBuilder.java | 40 + .../builder/CompositeBuilderException.java | 45 + .../assembly/builder/CompositeBuilderMonitor.java | 36 + .../tuscany/sca/assembly/builder/Problem.java | 45 + .../sca/assembly/builder/impl/BindingUtil.java | 125 ++ .../builder/impl/CompositeBuilderImpl.java | 105 ++ .../builder/impl/CompositeCloneBuilderImpl.java | 107 ++ .../impl/CompositeConfigurationBuilderImpl.java | 1065 +++++++++++++++++ .../builder/impl/CompositeIncludeBuilderImpl.java | 81 ++ .../builder/impl/CompositeWireBuilderImpl.java | 1220 ++++++++++++++++++++ .../sca/assembly/builder/impl/PrintUtil.java | 273 +++++ .../sca/assembly/builder/impl/ProblemImpl.java | 117 ++ .../sca/assembly/builder/impl/PropertyUtil.java | 190 +++ .../sca/assembly/builder/impl/ReferenceUtil.java | 94 ++ .../sca/assembly/impl/AbstractPropertyImpl.java | 110 ++ .../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 | 63 + .../tuscany/sca/assembly/impl/ComponentImpl.java | 149 +++ .../sca/assembly/impl/ComponentPropertyImpl.java | 82 ++ .../sca/assembly/impl/ComponentReferenceImpl.java | 86 ++ .../sca/assembly/impl/ComponentServiceImpl.java | 71 ++ .../sca/assembly/impl/ComponentTypeImpl.java | 137 +++ .../tuscany/sca/assembly/impl/CompositeImpl.java | 143 +++ .../sca/assembly/impl/CompositeReferenceImpl.java | 51 + .../sca/assembly/impl/CompositeServiceImpl.java | 62 + .../sca/assembly/impl/ConstrainingTypeImpl.java | 102 ++ .../tuscany/sca/assembly/impl/ContractImpl.java | 77 ++ .../tuscany/sca/assembly/impl/ExtensibleImpl.java | 44 + .../tuscany/sca/assembly/impl/PropertyImpl.java | 51 + .../tuscany/sca/assembly/impl/ReferenceImpl.java | 106 ++ .../tuscany/sca/assembly/impl/ServiceImpl.java | 90 ++ .../apache/tuscany/sca/assembly/impl/WireImpl.java | 83 ++ ...org.apache.tuscany.sca.assembly.AssemblyFactory | 18 + .../sca/assembly/AssemblyFactoryTestCase.java | 214 ++++ .../apache/tuscany/sca/assembly/TestBinding.java | 51 + .../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 | 230 ++++ .../sca/1.0-RC1b/modules/binding-dwr/DISCLAIMER | 8 + tags/java/sca/1.0-RC1b/modules/binding-dwr/LICENSE | 205 ++++ tags/java/sca/1.0-RC1b/modules/binding-dwr/NOTICE | 6 + tags/java/sca/1.0-RC1b/modules/binding-dwr/pom.xml | 76 ++ .../apache/tuscany/sca/binding/dwr/DWRBinding.java | 32 + .../sca/binding/dwr/DWRBindingActivator.java | 51 + .../apache/tuscany/sca/binding/dwr/DWRInvoker.java | 88 ++ .../tuscany/sca/binding/dwr/DWRInvokerFactory.java | 62 + .../apache/tuscany/sca/binding/dwr/DWRService.java | 66 ++ .../apache/tuscany/sca/binding/dwr/DWRServlet.java | 245 ++++ ...e.tuscany.sca.extension.helper.BindingActivator | 19 + .../sca/1.0-RC1b/modules/binding-ejb/DISCLAIMER | 8 + tags/java/sca/1.0-RC1b/modules/binding-ejb/LICENSE | 205 ++++ tags/java/sca/1.0-RC1b/modules/binding-ejb/NOTICE | 6 + tags/java/sca/1.0-RC1b/modules/binding-ejb/pom.xml | 136 +++ .../apache/tuscany/sca/binding/ejb/EJBBinding.java | 102 ++ .../sca/binding/ejb/EJBBindingActivator.java | 53 + .../sca/binding/ejb/EJBBindingsActivator.java | 34 + .../tuscany/sca/binding/ejb/EJBTargetInvoker.java | 79 ++ .../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 ++ .../tuscany/sca/binding/ejb/util/EJBHandler.java | 336 ++++++ .../tuscany/sca/binding/ejb/util/EJBLocator.java | 481 ++++++++ .../sca/binding/ejb/util/EJBObjectFactory.java | 204 ++++ .../sca/binding/ejb/util/EJBStubHelper.java | 69 ++ .../sca/binding/ejb/util/InterfaceInfo.java | 116 ++ .../binding/ejb/util/JavaReflectionAdapter.java | 154 +++ .../tuscany/sca/binding/ejb/util/MethodInfo.java | 187 +++ .../sca/binding/ejb/util/NamingEndpoint.java | 124 ++ .../org.apache.tuscany.sca.core.ModuleActivator | 19 + ...e.tuscany.sca.extension.helper.BindingActivator | 19 + .../src/test/java/account/BankManagerFacade.java | 33 + .../src/test/java/account/Customer.java | 35 + .../src/test/java/account/CustomerImpl.java | 57 + .../src/test/java/calculator/AddService.java | 27 + .../src/test/java/calculator/AddServiceHome.java | 31 + .../samples/bank/ejb/BankManagerFacade.java | 43 + .../samples/bank/ejb/BankManagerFacadeHome.java | 43 + .../binding/ejb/tests/EJBReferenceTestCase.java | 65 ++ .../tuscany/sca/binding/ejb/tests/MockServer.java | 151 +++ .../sca/binding/ejb/tests/SocketTracer.java | 136 +++ .../src/test/resources/account/account.composite | 35 + .../sca/1.0-RC1b/modules/binding-feed/DISCLAIMER | 8 + .../java/sca/1.0-RC1b/modules/binding-feed/LICENSE | 205 ++++ tags/java/sca/1.0-RC1b/modules/binding-feed/NOTICE | 6 + .../java/sca/1.0-RC1b/modules/binding-feed/pom.xml | 105 ++ .../tuscany/sca/binding/feed/AtomBinding.java | 28 + .../sca/binding/feed/AtomBindingFactory.java | 35 + .../tuscany/sca/binding/feed/RSSBinding.java | 28 + .../sca/binding/feed/RSSBindingFactory.java | 35 + .../sca/binding/feed/collection/Collection.java | 73 ++ .../binding/feed/collection/MediaCollection.java | 55 + .../binding/feed/collection/NotFoundException.java | 45 + .../binding/feed/impl/AtomBindingFactoryImpl.java | 36 + .../sca/binding/feed/impl/AtomBindingImpl.java | 83 ++ .../binding/feed/impl/RSSBindingFactoryImpl.java | 36 + .../sca/binding/feed/impl/RSSBindingImpl.java | 81 ++ .../binding/feed/provider/AtomBindingInvoker.java | 350 ++++++ .../feed/provider/AtomBindingProviderFactory.java | 65 ++ .../sca/binding/feed/provider/AtomEntryUtil.java | 104 ++ .../provider/AtomReferenceBindingProvider.java | 110 ++ .../feed/provider/AtomServiceBindingProvider.java | 82 ++ .../feed/provider/FeedBindingListenerServlet.java | 527 +++++++++ .../binding/feed/provider/RSSBindingInvoker.java | 82 ++ .../feed/provider/RSSBindingProviderFactory.java | 65 ++ .../feed/provider/RSSReferenceBindingProvider.java | 63 + .../feed/provider/RSSServiceBindingProvider.java | 76 ++ ...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 | 137 +++ .../apache/tuscany/sca/binding/feed/Provider.java | 41 + .../tuscany/sca/binding/feed/Consumer.composite | 32 + .../tuscany/sca/binding/feed/Provider.composite | 33 + .../sca/1.0-RC1b/modules/binding-http/DISCLAIMER | 8 + .../java/sca/1.0-RC1b/modules/binding-http/LICENSE | 205 ++++ tags/java/sca/1.0-RC1b/modules/binding-http/NOTICE | 6 + .../java/sca/1.0-RC1b/modules/binding-http/pom.xml | 94 ++ .../tuscany/sca/binding/http/HTTPResource.java | 38 + .../sca/binding/http/HTTPResourceBinding.java | 29 + .../binding/http/HTTPResourceBindingFactory.java | 35 + .../http/impl/HTTPResourceBindingFactoryImpl.java | 36 + .../binding/http/impl/HTTPResourceBindingImpl.java | 61 + .../HTTPResourceBindingProviderFactory.java | 62 + .../HTTPResourceServiceBindingProvider.java | 111 ++ ...any.sca.binding.http.HTTPResourceBindingFactory | 19 + ...ca.contribution.processor.StAXArtifactProcessor | 19 + ...che.tuscany.sca.provider.BindingProviderFactory | 19 + .../binding/http/HTTPResourceBindingTestCase.java | 107 ++ .../src/test/resources/content/test.html | 21 + .../src/test/resources/resource.composite | 41 + .../1.0-RC1b/modules/binding-jsonrpc/DISCLAIMER | 8 + .../sca/1.0-RC1b/modules/binding-jsonrpc/LICENSE | 205 ++++ .../sca/1.0-RC1b/modules/binding-jsonrpc/NOTICE | 6 + .../sca/1.0-RC1b/modules/binding-jsonrpc/pom.xml | 103 ++ .../sca/binding/jsonrpc/JSONRPCBinding.java | 30 + .../binding/jsonrpc/JSONRPCBindingActivator.java | 52 + .../sca/binding/jsonrpc/JSONRPCService.java | 127 ++ .../sca/binding/jsonrpc/JSONRPCServiceServlet.java | 160 +++ .../tuscany/sca/binding/jsonrpc/JavaToSmd.java | 54 + .../binding/jsonrpc/ScaDomainScriptServlet.java | 112 ++ ...e.tuscany.sca.extension.helper.BindingActivator | 18 + .../apache/tuscany/sca/binding/jsonrpc/jsonrpc.js | 493 ++++++++ .../apache/tuscany/sca/binding/jsonrpc/Echo.java | 29 + .../sca/binding/jsonrpc/EchoComponentImpl.java | 34 + .../binding/jsonrpc/JSONRPCServiceTestCase.java | 67 ++ .../src/test/resources/JSONRPCBinding.composite | 35 + .../modules/binding-notification/DISCLAIMER | 8 + .../1.0-RC1b/modules/binding-notification/LICENSE | 205 ++++ .../1.0-RC1b/modules/binding-notification/NOTICE | 6 + .../1.0-RC1b/modules/binding-notification/pom.xml | 118 ++ .../DefaultNotificationBindingFactory.java | 31 + .../binding/notification/NotificationBinding.java | 37 + .../notification/NotificationBindingFactory.java | 27 + .../notification/NotificationBindingImpl.java | 75 ++ .../NotificationBindingModuleActivator.java | 225 ++++ .../notification/NotificationBindingProcessor.java | 100 ++ .../NotificationBindingProviderFactory.java | 233 ++++ .../notification/NotificationBrokerManager.java | 40 + .../NotificationReferenceBindingInvoker.java | 131 +++ .../NotificationReferenceBindingProvider.java | 344 ++++++ .../NotificationServiceBindingProvider.java | 317 +++++ .../notification/NotificationTypeManager.java | 43 + .../notification/NotificationTypeManagerImpl.java | 692 +++++++++++ .../notification/encoding/AbstractBroker.java | 44 + .../encoding/AbstractBrokerEnDeCoder.java | 88 ++ .../notification/encoding/AbstractEnDeCoder.java | 63 + .../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 | 91 ++ .../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 | 73 ++ .../binding/notification/encoding/EnDeCoder.java | 46 + .../notification/encoding/EncodingException.java | 49 + .../notification/encoding/EncodingObject.java | 26 + .../notification/encoding/EncodingRegistry.java | 57 + .../notification/encoding/EncodingUtils.java | 85 ++ .../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 | 91 ++ .../notification/encoding/EndpointReference.java | 44 + .../encoding/EndpointReferenceEnDeCoder.java | 101 ++ .../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 | 119 ++ .../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 | 101 ++ .../notification/encoding/RemovedBroker.java | 26 + .../encoding/RemovedBrokerEnDeCoder.java | 44 + .../encoding/ReplaceBrokerConnection.java | 44 + .../encoding/ReplaceBrokerConnectionEnDeCoder.java | 101 ++ .../binding/notification/encoding/Subscribe.java | 35 + .../notification/encoding/SubscribeEnDeCoder.java | 83 ++ .../sca/binding/notification/util/IOUtils.java | 179 +++ .../notification/util/NotificationServlet.java | 91 ++ .../sca/binding/notification/util/URIUtil.java | 42 + .../org.apache.tuscany.sca.core.ModuleActivator | 18 + .../notification/encoding/AxiomTestCase.java | 57 + .../notification/encoding/EncodingTestCase.java | 503 ++++++++ .../sca/1.0-RC1b/modules/binding-osgi/DISCLAIMER | 8 + .../java/sca/1.0-RC1b/modules/binding-osgi/LICENSE | 251 ++++ tags/java/sca/1.0-RC1b/modules/binding-osgi/NOTICE | 17 + .../java/sca/1.0-RC1b/modules/binding-osgi/pom.xml | 57 + .../org.apache.tuscany.sca.core.ModuleActivator | 18 + .../java/sca/1.0-RC1b/modules/binding-rmi/.ruleset | 190 +++ .../sca/1.0-RC1b/modules/binding-rmi/DISCLAIMER | 8 + tags/java/sca/1.0-RC1b/modules/binding-rmi/LICENSE | 205 ++++ tags/java/sca/1.0-RC1b/modules/binding-rmi/NOTICE | 6 + tags/java/sca/1.0-RC1b/modules/binding-rmi/pom.xml | 59 + .../apache/tuscany/sca/binding/rmi/RMIBinding.java | 75 ++ .../sca/binding/rmi/RMIBindingActivator.java | 53 + .../sca/binding/rmi/RMIReferenceInvoker.java | 77 ++ .../binding/rmi/RMIReferenceInvokerFactory.java | 59 + .../apache/tuscany/sca/binding/rmi/RMIService.java | 167 +++ ...e.tuscany.sca.extension.helper.BindingActivator | 18 + .../src/test/java/helloworld/HelloWorldImpl.java | 37 + .../test/java/helloworld/HelloWorldRmiImpl.java | 48 + .../test/java/helloworld/HelloWorldRmiService.java | 29 + .../test/java/helloworld/HelloWorldService.java | 29 + .../tuscany/sca/binding/rmi/BindingTestCase.java | 63 + .../test/resources/HelloWorldImpl.componentType | 23 + .../test/resources/HelloWorldRmiImpl.componentType | 27 + .../src/test/resources/RMIBindingTest.composite | 43 + .../1.0-RC1b/modules/binding-sca-axis2/DISCLAIMER | 8 + .../sca/1.0-RC1b/modules/binding-sca-axis2/LICENSE | 205 ++++ .../sca/1.0-RC1b/modules/binding-sca-axis2/NOTICE | 6 + .../sca/1.0-RC1b/modules/binding-sca-axis2/pom.xml | 90 ++ .../sca/axis2/impl/Axis2SCABindingInvoker.java | 150 +++ .../axis2/impl/Axis2SCABindingProviderFactory.java | 76 ++ .../impl/Axis2SCAReferenceBindingProvider.java | 196 ++++ .../axis2/impl/Axis2SCAServiceBindingProvider.java | 224 ++++ .../sca/axis2/impl/Axis2SCAServiceProvider.java | 79 ++ ...che.tuscany.sca.provider.BindingProviderFactory | 19 + .../sca/binding/sca/axis2/AsynchTestCase.java | 70 ++ .../tuscany/sca/binding/sca/axis2/BaseTest.java | 31 + .../sca/binding/sca/axis2/CallbackTestCase.java | 72 ++ .../sca/binding/sca/axis2/NodeFactoryImpl.java | 47 + .../sca/binding/sca/axis2/PromotionTestCase.java | 66 ++ .../sca/binding/sca/axis2/SimpleTestCase.java | 98 ++ .../tuscany/sca/binding/sca/axis2/TestDomain.java | 268 +++++ .../sca/axis2/TestServiceDiscoveryImpl.java | 148 +++ .../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 | 44 + .../impl/HelloWorldClientCallbackRemoteImpl.java | 42 + .../helloworld/impl/HelloWorldClientLocalImpl.java | 36 + .../impl/HelloWorldClientRemote2Impl.java | 37 + .../impl/HelloWorldClientRemoteImpl.java | 36 + .../HelloWorldServiceCallbackOnewayRemoteImpl.java | 36 + .../impl/HelloWorldServiceCallbackRemoteImpl.java | 35 + .../impl/HelloWorldServiceLocalImpl.java | 30 + .../HelloWorldServiceMultipleServicesImpl.java | 41 + .../impl/HelloWorldServiceRemoteImpl.java | 30 + .../src/test/resources/nodeA/HelloWorld.composite | 71 ++ .../resources/nodeA/META-INF/sca-contribution.xml | 24 + .../src/test/resources/nodeB/HelloWorld.composite | 70 ++ .../resources/nodeB/META-INF/sca-contribution.xml | 24 + .../src/test/resources/nodeC/HelloWorld.composite | 33 + .../resources/nodeC/HelloWorldComponent.composite | 37 + .../resources/nodeC/META-INF/sca-contribution.xml | 24 + .../src/test/resources/nodeD/HelloWorld.composite | 32 + .../resources/nodeD/HelloWorldComponent.composite | 37 + .../resources/nodeD/META-INF/sca-contribution.xml | 24 + .../src/test/resources/nodeE/HelloWorld.composite | 31 + .../resources/nodeE/META-INF/sca-contribution.xml | 24 + .../src/test/resources/nodeF/HelloWorld.composite | 41 + .../resources/nodeF/META-INF/sca-contribution.xml | 24 + .../src/test/resources/nodeG/HelloWorld.composite | 31 + .../resources/nodeG/META-INF/sca-contribution.xml | 24 + .../src/test/resources/nodeH/HelloWorld.composite | 36 + .../resources/nodeH/META-INF/sca-contribution.xml | 24 + .../1.0-RC1b/modules/binding-sca-xml/DISCLAIMER | 8 + .../sca/1.0-RC1b/modules/binding-sca-xml/LICENSE | 205 ++++ .../sca/1.0-RC1b/modules/binding-sca-xml/NOTICE | 6 + .../sca/1.0-RC1b/modules/binding-sca-xml/pom.xml | 57 + .../sca/binding/sca/xml/SCABindingProcessor.java | 128 ++ ...ca.contribution.processor.StAXArtifactProcessor | 19 + .../tuscany/sca/binding/sca/xml/ReadTestCase.java | 129 +++ .../tuscany/sca/binding/sca/xml/WriteTestCase.java | 129 +++ .../src/test/resources/Calculator.composite | 59 + .../resources/CalculatorServiceImpl.componentType | 33 + .../sca/1.0-RC1b/modules/binding-sca/DISCLAIMER | 8 + tags/java/sca/1.0-RC1b/modules/binding-sca/LICENSE | 205 ++++ tags/java/sca/1.0-RC1b/modules/binding-sca/NOTICE | 6 + tags/java/sca/1.0-RC1b/modules/binding-sca/pom.xml | 86 ++ .../sca/binding/sca/DistributedSCABinding.java | 37 + .../sca/impl/DistributedSCABindingImpl.java | 111 ++ .../sca/impl/RuntimeSCABindingProvider.java | 61 + .../sca/impl/RuntimeSCABindingProviderFactory.java | 71 ++ .../impl/RuntimeSCAReferenceBindingProvider.java | 232 ++++ .../sca/impl/RuntimeSCAServiceBindingProvider.java | 138 +++ .../binding/sca/impl/SCABindingFactoryImpl.java | 36 + .../sca/binding/sca/impl/SCABindingImpl.java | 194 ++++ ...g.apache.tuscany.sca.assembly.SCABindingFactory | 18 + ...che.tuscany.sca.provider.BindingProviderFactory | 19 + .../sca/binding/sca/SCABindingTestCase.java | 117 ++ .../src/test/resources/Calculator.composite | 52 + .../1.0-RC1b/modules/binding-ws-axis2/DISCLAIMER | 8 + .../sca/1.0-RC1b/modules/binding-ws-axis2/LICENSE | 205 ++++ .../sca/1.0-RC1b/modules/binding-ws-axis2/NOTICE | 6 + .../sca/1.0-RC1b/modules/binding-ws-axis2/pom.xml | 297 +++++ .../sca/binding/ws/axis2/Axis2BindingInvoker.java | 186 +++ .../ws/axis2/Axis2BindingProviderFactory.java | 63 + .../ws/axis2/Axis2OneWayBindingInvoker.java | 59 + .../ws/axis2/Axis2ReferenceBindingProvider.java | 81 ++ .../ws/axis2/Axis2ServiceBindingProvider.java | 77 ++ .../sca/binding/ws/axis2/Axis2ServiceClient.java | 281 +++++ .../ws/axis2/Axis2ServiceInMessageReceiver.java | 61 + .../Axis2ServiceInOutSyncMessageReceiver.java | 85 ++ .../sca/binding/ws/axis2/Axis2ServiceProvider.java | 532 +++++++++ .../sca/binding/ws/axis2/Axis2ServiceServlet.java | 297 +++++ .../sca/binding/ws/axis2/Java2WSDLHelper.java | 250 ++++ .../binding/ws/axis2/TuscanyAxisConfigurator.java | 44 + .../sca/binding/ws/axis2/TuscanyDispatcher.java | 103 ++ .../sca/binding/ws/axis2/TuscanyListingAgent.java | 411 +++++++ ...che.tuscany.sca.provider.BindingProviderFactory | 19 + .../sca/binding/ws/axis2/engine/config/axis2.xml | 478 ++++++++ .../ws/axis2/engine/config/modules/modules.list | 1 + .../ws/axis2/engine/config/modules/rampart-1.3.mar | Bin 0 -> 2704 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 + .../binding/ws/axis2/Java2WSDLHelperTestCase.java | 75 ++ .../tuscany/sca/binding/ws/axis2/itests/Bar.java | 58 + .../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 | 40 + .../ws/axis2/itests/HelloWorldOMTestCase.java | 58 + .../binding/ws/axis2/itests/HelloWorldService.java | 28 + .../ws/axis2/itests/HelloWorldTestCase.java | 46 + .../itests/HelloWorldWSDLMergedTestCaseFIXME.java | 58 + .../ws/axis2/itests/QuestionMarkWSDLTestCase.java | 100 ++ .../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 + .../policy/AbstractHelloWorldOMTestCase.java | 64 + .../ws/axis2/itests/policy/ClientPWCBHandler.java | 43 + .../axis2/itests/policy/IntegrityPWCBHandler.java | 43 + .../ws/axis2/itests/policy/ServerPWCBHandler.java | 43 + .../policy/WSSecurityAuthenticationTestCase.java | 24 + ...onfidentialityTestCaseFIXBouncyCastleIssue.java | 42 + .../itests/policy/WSSecurityIntegrityTestCase.java | 24 + .../itests/soap12/HelloWorldSOAP12TestCase.java | 58 + .../itests/soap12/QuestionMarkWSDLTestCase.java | 121 ++ .../src/test/resources/definitions.xml | 152 +++ .../binding/ws/axis2/itests/HelloWorld.composite | 50 + .../ws/axis2/itests/HelloWorldNoWSDL.composite | 60 + .../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 | 43 + .../ws/axis2/itests/helloworld-om-porttype.wsdl | 59 + .../binding/ws/axis2/itests/helloworld-om-uri.wsdl | 78 ++ .../ws/axis2/itests/helloworld-om.composite | 44 + .../sca/binding/ws/axis2/itests/helloworld-om.wsdl | 78 ++ .../sca/binding/ws/axis2/itests/helloworld.wsdl | 80 ++ .../policy/WSSecurityAuthentication.composite | 49 + .../policy/WSSecurityConfidentiality.composite | 49 + .../itests/policy/WSSecurityIntegrity.composite | 49 + .../ws/axis2/itests/policy/security.properties | 4 + .../binding/ws/axis2/itests/policy/tuscanyKeys.jks | Bin 0 -> 1365 bytes .../ws/axis2/itests/questionmark-wsdl.composite | 36 + .../axis2/itests/soap12/HelloWorldSOAP12.composite | 71 ++ .../itests/soap12/questionmark-wsdl.composite | 40 + .../1.0-RC1b/modules/binding-ws-xml/.checkstyle | 24 + tags/java/sca/1.0-RC1b/modules/binding-ws-xml/.pmd | 20 + .../sca/1.0-RC1b/modules/binding-ws-xml/.ruleset | 190 +++ .../sca/1.0-RC1b/modules/binding-ws-xml/DISCLAIMER | 8 + .../sca/1.0-RC1b/modules/binding-ws-xml/LICENSE | 205 ++++ .../sca/1.0-RC1b/modules/binding-ws-xml/NOTICE | 6 + .../sca/1.0-RC1b/modules/binding-ws-xml/pom.xml | 75 ++ .../binding/ws/xml/EndPointReferenceHelper.java | 182 +++ .../binding/ws/xml/WebServiceBindingProcessor.java | 312 +++++ .../sca/binding/ws/xml/WebServiceConstants.java | 38 + ...ca.contribution.processor.StAXArtifactProcessor | 19 + .../tuscany/sca/binding/ws/xml/ReadTestCase.java | 118 ++ .../tuscany/sca/binding/ws/xml/WriteTestCase.java | 111 ++ .../sca/binding/ws/xml/Calculator.composite | 58 + .../binding/ws/xml/CalculatorImpl.componentType | 45 + .../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/1.0-RC1b/modules/binding-ws/.checkstyle | 24 + tags/java/sca/1.0-RC1b/modules/binding-ws/.pmd | 20 + tags/java/sca/1.0-RC1b/modules/binding-ws/.ruleset | 190 +++ .../sca/1.0-RC1b/modules/binding-ws/DISCLAIMER | 8 + tags/java/sca/1.0-RC1b/modules/binding-ws/LICENSE | 205 ++++ tags/java/sca/1.0-RC1b/modules/binding-ws/NOTICE | 6 + tags/java/sca/1.0-RC1b/modules/binding-ws/pom.xml | 66 ++ .../ws/DefaultWebServiceBindingFactory.java | 30 + .../tuscany/sca/binding/ws/WebServiceBinding.java | 200 ++++ .../sca/binding/ws/WebServiceBindingFactory.java | 35 + .../binding/ws/addressing/EndPointReference.java | 62 + .../ws/impl/WebServiceBindingFactoryImpl.java | 35 + .../sca/binding/ws/impl/WebServiceBindingImpl.java | 263 +++++ .../1.0-RC1b/modules/contribution-impl/.checkstyle | 25 + .../sca/1.0-RC1b/modules/contribution-impl/.pmd | 20 + .../1.0-RC1b/modules/contribution-impl/.ruleset | 190 +++ .../1.0-RC1b/modules/contribution-impl/DISCLAIMER | 8 + .../sca/1.0-RC1b/modules/contribution-impl/LICENSE | 205 ++++ .../sca/1.0-RC1b/modules/contribution-impl/NOTICE | 6 + .../sca/1.0-RC1b/modules/contribution-impl/pom.xml | 57 + .../sca/contribution/impl/ArtifactImpl.java | 71 ++ .../contribution/impl/ContributionFactoryImpl.java | 41 + .../sca/contribution/impl/ContributionImpl.java | 74 ++ .../contribution/impl/DeployedArtifactImpl.java | 43 + .../impl/FolderContributionProcessor.java | 122 ++ .../impl/InvalidFolderContributionException.java | 38 + .../InvalidFolderContributionURIException.java | 38 + .../processor/impl/JarContributionProcessor.java | 127 ++ .../resolver/impl/ModelResolverImpl.java | 92 ++ .../service/impl/ArtifactTypeDescriberImpl.java | 106 ++ .../ContributionMetadataDocumentProcessor.java | 108 ++ .../impl/ContributionMetadataProcessor.java | 163 +++ .../service/impl/ContributionRepositoryImpl.java | 297 +++++ .../service/impl/ContributionServiceImpl.java | 411 +++++++ .../impl/InvalidContributionMetadataException.java | 54 + .../impl/InvalidContributionURIException.java | 54 + .../service/impl/PackageTypeDescriberImpl.java | 98 ++ .../sca/contribution/service/util/FileHelper.java | 704 +++++++++++ .../sca/contribution/service/util/IOHelper.java | 191 +++ ...he.tuscany.sca.contribution.ContributionFactory | 18 + ...any.sca.contribution.processor.PackageProcessor | 19 + ...FolderContributionPackageProcessorTestCase.java | 51 + .../JarContributionPackageProcessorTestCase.java | 59 + ...URLartifactProcessorExtensionPointTestCase.java | 124 ++ .../resolver/ArtifactResolverTestCase.java | 104 ++ .../ExtensibleArtifactResolverTestCase.java | 130 +++ .../contribution/resolver/TestModelResolver.java | 62 + .../services/ContentTypeDescriberImplTestCase.java | 53 + ...tributionMetadataDocumentProcessorTestCase.java | 93 ++ .../services/ContributionRepositoryTestCase.java | 81 ++ .../services/PackageTypeDescriberImplTestCase.java | 63 + .../resources/deployables/sample-calculator.jar | Bin 0 -> 26901 bytes .../resources/repository/sample-calculator.jar | Bin 0 -> 29164 bytes .../src/test/resources/test.composite | 22 + .../contribution-impl/src/test/resources/test.ext | 0 .../1.0-RC1b/modules/contribution-java/.checkstyle | 25 + .../sca/1.0-RC1b/modules/contribution-java/.pmd | 20 + .../1.0-RC1b/modules/contribution-java/.ruleset | 190 +++ .../sca/1.0-RC1b/modules/contribution-java/pom.xml | 51 + .../tuscany/sca/contribution/java/JavaExport.java | 43 + .../tuscany/sca/contribution/java/JavaImport.java | 58 + .../contribution/java/JavaImportExportFactory.java | 42 + .../java/impl/ClassReferenceModelResolver.java | 144 +++ .../sca/contribution/java/impl/JavaExportImpl.java | 57 + .../java/impl/JavaExportProcessor.java | 120 ++ .../java/impl/JavaImportExportFactoryImpl.java | 41 + .../java/impl/JavaImportExportListener.java | 94 ++ .../sca/contribution/java/impl/JavaImportImpl.java | 87 ++ .../java/impl/JavaImportProcessor.java | 127 ++ ...y.sca.contribution.java.JavaImportExportFactory | 18 + ...ca.contribution.processor.StAXArtifactProcessor | 19 + ...tuscany.sca.contribution.resolver.ModelResolver | 18 + ...y.sca.contribution.service.ContributionListener | 18 + .../ClassReferenceArtifactResolverTestCase.java | 75 ++ .../java/impl/JavaExportProcessorTestCase.java | 92 ++ .../java/impl/JavaImportProcessorTestCase.java | 93 ++ .../modules/contribution-namespace/.checkstyle | 25 + .../1.0-RC1b/modules/contribution-namespace/.pmd | 20 + .../modules/contribution-namespace/.ruleset | 190 +++ .../modules/contribution-namespace/pom.xml | 51 + .../contribution/namespace/NamespaceExport.java | 46 + .../contribution/namespace/NamespaceImport.java | 59 + .../namespace/NamespaceImportExportFactory.java | 42 + .../namespace/impl/NamespaceExportImpl.java | 56 + .../namespace/impl/NamespaceExportProcessor.java | 118 ++ .../impl/NamespaceImportExportFactoryImpl.java | 41 + .../impl/NamespaceImportExportListener.java | 97 ++ .../namespace/impl/NamespaceImportImpl.java | 88 ++ .../namespace/impl/NamespaceImportProcessor.java | 127 ++ ...ribution.namespace.NamespaceImportExportFactory | 18 + ...ca.contribution.processor.StAXArtifactProcessor | 19 + ...tuscany.sca.contribution.resolver.ModelResolver | 18 + ...y.sca.contribution.service.ContributionListener | 18 + .../impl/NamespaceExportProcessorTestCase.java | 94 ++ .../impl/NamespaceImportProcessorTestCase.java | 95 ++ .../1.0-RC1b/modules/contribution-osgi/.checkstyle | 25 + .../sca/1.0-RC1b/modules/contribution-osgi/.pmd | 20 + .../1.0-RC1b/modules/contribution-osgi/.ruleset | 190 +++ .../sca/1.0-RC1b/modules/contribution-osgi/pom.xml | 65 ++ .../sca/contribution/osgi/BundleReference.java | 138 +++ .../osgi/impl/OSGiBundleProcessor.java | 140 +++ .../impl/OSGiBundleReferenceModelResolver.java | 152 +++ .../osgi/impl/OSGiClassReferenceModelResolver.java | 136 +++ .../osgi/impl/OSGiImportExportListener.java | 203 ++++ .../osgi/impl/OSGiModelResolverImpl.java | 118 ++ ...tuscany.sca.contribution.resolver.ModelResolver | 18 + ...y.sca.contribution.service.ContributionListener | 18 + .../sca/1.0-RC1b/modules/contribution/.checkstyle | 24 + tags/java/sca/1.0-RC1b/modules/contribution/.pmd | 20 + .../sca/1.0-RC1b/modules/contribution/.ruleset | 190 +++ .../sca/1.0-RC1b/modules/contribution/DISCLAIMER | 8 + .../java/sca/1.0-RC1b/modules/contribution/LICENSE | 205 ++++ tags/java/sca/1.0-RC1b/modules/contribution/NOTICE | 6 + .../java/sca/1.0-RC1b/modules/contribution/pom.xml | 44 + .../apache/tuscany/sca/contribution/Artifact.java | 57 + .../tuscany/sca/contribution/ContentType.java | 56 + .../tuscany/sca/contribution/Contribution.java | 91 ++ .../sca/contribution/ContributionFactory.java | 42 + .../DefaultModelFactoryExtensionPoint.java | 134 +++ .../tuscany/sca/contribution/DeployedArtifact.java | 43 + .../apache/tuscany/sca/contribution/Export.java | 47 + .../apache/tuscany/sca/contribution/Import.java | 54 + .../contribution/ModelFactoryExtensionPoint.java | 54 + .../contribution/processor/ArtifactProcessor.java | 48 + .../processor/ArtifactProcessorExtensionPoint.java | 58 + .../processor/BaseStAXArtifactProcessor.java | 486 ++++++++ .../DefaultArtifactProcessorExtensionPoint.java | 66 ++ .../DefaultPackageProcessorExtensionPoint.java | 130 +++ ...DefaultStAXArtifactProcessorExtensionPoint.java | 215 ++++ .../DefaultURLArtifactProcessorExtensionPoint.java | 165 +++ .../processor/ExtensiblePackageProcessor.java | 79 ++ .../processor/ExtensibleStAXArtifactProcessor.java | 173 +++ .../processor/ExtensibleURLArtifactProcessor.java | 121 ++ .../contribution/processor/PackageProcessor.java | 67 ++ .../processor/PackageProcessorExtensionPoint.java | 50 + .../processor/StAXArtifactProcessor.java | 61 + .../StAXArtifactProcessorExtensionPoint.java | 29 + .../processor/URLArtifactProcessor.java | 51 + .../URLArtifactProcessorExtensionPoint.java | 29 + .../processor/ValidatingXMLStreamReader.java | 319 +++++ .../sca/contribution/resolver/ClassReference.java | 103 ++ .../resolver/DefaultImportAllModelResolver.java | 84 ++ .../DefaultModelResolverExtensionPoint.java | 113 ++ .../resolver/ExtensibleModelResolver.java | 152 +++ .../sca/contribution/resolver/ModelResolver.java | 66 ++ .../resolver/ModelResolverExtensionPoint.java | 52 + .../service/AbstractContributionException.java | 124 ++ .../service/ContributionException.java | 53 + .../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 | 142 +++ .../service/ContributionWireException.java | 42 + .../service/ContributionWriteException.java | 61 + .../DefaultContributionListenerExtensionPoint.java | 86 ++ .../service/ExtensibleContributionListener.java | 77 ++ .../sca/contribution/service/TypeDescriber.java | 38 + .../service/UnrecognizedElementException.java | 48 + .../service/UnsupportedContentTypeException.java | 49 + .../util/ServiceConfigurationUtil.java | 98 ++ ...any.sca.contribution.ModelFactoryExtensionPoint | 18 + ...ocessor.ContributionPostProcessorExtensionPoint | 18 + ...bution.processor.PackageProcessorExtensionPoint | 18 + ...n.processor.StAXArtifactProcessorExtensionPoint | 18 + ...on.processor.URLArtifactProcessorExtensionPoint | 18 + ...ntribution.resolver.ModelResolverExtensionPoint | 18 + ...tion.service.ContributionListenerExtensionPoint | 18 + .../1.0-RC1b/modules/core-databinding/.checkstyle | 25 + .../sca/1.0-RC1b/modules/core-databinding/.pmd | 20 + .../sca/1.0-RC1b/modules/core-databinding/.ruleset | 190 +++ .../1.0-RC1b/modules/core-databinding/DISCLAIMER | 8 + .../sca/1.0-RC1b/modules/core-databinding/LICENSE | 205 ++++ .../sca/1.0-RC1b/modules/core-databinding/NOTICE | 6 + .../sca/1.0-RC1b/modules/core-databinding/pom.xml | 69 ++ .../module/DataBindingModuleActivator.java | 76 ++ .../DataBindingJavaInterfaceProcessor.java | 185 +++ .../Exception2ExceptionTransformer.java | 127 ++ .../transformers/Input2InputTransformer.java | 214 ++++ .../transformers/Output2OutputTransformer.java | 206 ++++ .../wire/DataBindingRuntimeWireProcessor.java | 220 ++++ .../wire/DataTransformationInteceptor.java | 261 +++++ .../databinding/wire/PassByValueInteceptor.java | 113 ++ .../org.apache.tuscany.sca.core.ModuleActivator | 18 + .../DataBindingJavaInterfaceProcessorTestCase.java | 83 ++ .../transformers/IDLTransformerTestCase.java.fixme | 229 ++++ .../java/sca/1.0-RC1b/modules/core-spi/.checkstyle | 24 + tags/java/sca/1.0-RC1b/modules/core-spi/.pmd | 20 + tags/java/sca/1.0-RC1b/modules/core-spi/.ruleset | 190 +++ tags/java/sca/1.0-RC1b/modules/core-spi/DISCLAIMER | 8 + tags/java/sca/1.0-RC1b/modules/core-spi/LICENSE | 205 ++++ tags/java/sca/1.0-RC1b/modules/core-spi/NOTICE | 6 + tags/java/sca/1.0-RC1b/modules/core-spi/pom.xml | 111 ++ .../modules/core-spi/src/doc/Context Model.emx | 673 +++++++++++ .../sca/context/ComponentContextFactory.java | 38 + .../sca/context/ContextFactoryExtensionPoint.java | 50 + .../DefaultContextFactoryExtensionPoint.java | 67 ++ .../tuscany/sca/context/RequestContextFactory.java | 33 + .../sca/core/DefaultExtensionPointRegistry.java | 155 +++ .../tuscany/sca/core/ExtensionPointRegistry.java | 50 + .../apache/tuscany/sca/core/ModuleActivator.java | 60 + .../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 + .../apache/tuscany/sca/invocation/Interceptor.java | 40 + .../tuscany/sca/invocation/InvocationChain.java | 90 ++ .../org/apache/tuscany/sca/invocation/Invoker.java | 36 + .../org/apache/tuscany/sca/invocation/Message.java | 107 ++ .../tuscany/sca/invocation/MessageFactory.java | 36 + .../tuscany/sca/management/ManagementService.java | 39 + .../sca/provider/BindingProviderFactory.java | 60 + .../DefaultProviderFactoryExtensionPoint.java | 263 +++++ .../sca/provider/ImplementationProvider.java | 68 ++ .../provider/ImplementationProviderFactory.java | 42 + .../tuscany/sca/provider/ProviderFactory.java | 36 + .../provider/ProviderFactoryExtensionPoint.java | 55 + .../sca/provider/ReferenceBindingProvider.java | 76 ++ .../sca/provider/ServiceBindingProvider.java | 63 + .../DefaultWireProcessorExtensionPoint.java | 63 + .../tuscany/sca/runtime/EndpointReference.java | 93 ++ .../tuscany/sca/runtime/ReferenceParameters.java | 69 ++ .../tuscany/sca/runtime/RuntimeComponent.java | 68 ++ .../sca/runtime/RuntimeComponentContext.java | 104 ++ .../sca/runtime/RuntimeComponentReference.java | 84 ++ .../sca/runtime/RuntimeComponentService.java | 102 ++ .../apache/tuscany/sca/runtime/RuntimeWire.java | 101 ++ .../tuscany/sca/runtime/RuntimeWireProcessor.java | 35 + .../RuntimeWireProcessorExtensionPoint.java | 53 + .../sca/store/DuplicateRecordException.java | 45 + .../apache/tuscany/sca/store/RecoveryListener.java | 46 + .../java/org/apache/tuscany/sca/store/Store.java | 96 ++ .../apache/tuscany/sca/store/StoreException.java | 46 + .../tuscany/sca/store/StoreExpirationEvent.java | 71 ++ .../org/apache/tuscany/sca/store/StoreMonitor.java | 71 ++ .../tuscany/sca/store/StoreReadException.java | 45 + .../tuscany/sca/store/StoreWriteException.java | 45 + .../tuscany/sca/work/NotificationListener.java | 66 ++ .../org/apache/tuscany/sca/work/WorkScheduler.java | 57 + .../tuscany/sca/work/WorkSchedulerException.java | 47 + ...cany.sca.provider.ProviderFactoryExtensionPoint | 18 + ....sca.runtime.RuntimeWireProcessorExtensionPoint | 18 + .../org.apache.tuscany.sca.work.WorkScheduler | 18 + .../sca/1.0-RC1b/modules/core-spring/DISCLAIMER | 8 + tags/java/sca/1.0-RC1b/modules/core-spring/LICENSE | 205 ++++ tags/java/sca/1.0-RC1b/modules/core-spring/NOTICE | 6 + tags/java/sca/1.0-RC1b/modules/core-spring/pom.xml | 107 ++ .../spring/assembly/impl/BeanAssemblyFactory.java | 134 +++ .../spring/assembly/impl/BeanComponentImpl.java | 214 ++++ .../spring/assembly/impl/BeanReferenceImpl.java | 67 ++ .../sca/core/spring/context/ModelResolverImpl.java | 88 ++ .../sca/core/spring/context/SCADomainContext.java | 193 ++++ .../java/impl/BeanBaseJavaImplementationImpl.java | 171 +++ .../java/impl/BeanJavaImplementationFactory.java | 75 ++ .../java/impl/BeanJavaImplementationImpl.java | 164 +++ .../java/impl/BeanJavaInterfaceContractImpl.java | 34 + .../java/impl/BeanJavaInterfaceFactory.java | 75 ++ .../java/impl/BeanJavaInterfaceImpl.java | 127 ++ .../src/test/java/calculator/AddService.java | 25 + .../src/test/java/calculator/AddServiceImpl.java | 35 + .../src/test/java/calculator/CalculatorClient.java | 41 + .../test/java/calculator/CalculatorService.java | 34 + .../java/calculator/CalculatorServiceImpl.java | 71 ++ .../src/test/java/calculator/DivideService.java | 25 + .../test/java/calculator/DivideServiceImpl.java | 33 + .../src/test/java/calculator/MultiplyService.java | 25 + .../test/java/calculator/MultiplyServiceImpl.java | 33 + .../java/calculator/NestedCalculatorClient.java | 44 + .../src/test/java/calculator/SubtractService.java | 25 + .../test/java/calculator/SubtractServiceImpl.java | 33 + .../sca/core/spring/CalculatorTestCase.java | 54 + .../core/spring/NestedCalculatorTestCaseFIXME.java | 57 + .../tuscany/sca/core/spring/Calculator.composite | 52 + .../sca/core/spring/InnerCalculator.composite | 42 + .../sca/core/spring/InnerOperations.composite | 57 + .../sca/core/spring/OuterCalculator.composite | 41 + tags/java/sca/1.0-RC1b/modules/core/.checkstyle | 24 + tags/java/sca/1.0-RC1b/modules/core/.pmd | 20 + tags/java/sca/1.0-RC1b/modules/core/.ruleset | 190 +++ tags/java/sca/1.0-RC1b/modules/core/DISCLAIMER | 8 + tags/java/sca/1.0-RC1b/modules/core/LICENSE | 205 ++++ tags/java/sca/1.0-RC1b/modules/core/NOTICE | 6 + tags/java/sca/1.0-RC1b/modules/core/pom.xml | 76 ++ .../sca/core/assembly/ActivationException.java | 37 + .../sca/core/assembly/CompositeActivator.java | 154 +++ .../sca/core/assembly/CompositeActivatorImpl.java | 841 ++++++++++++++ .../sca/core/assembly/EndpointReferenceImpl.java | 184 +++ .../core/assembly/ReferenceParameterProcessor.java | 89 ++ .../sca/core/assembly/ReferenceParametersImpl.java | 139 +++ .../sca/core/assembly/RuntimeAssemblyFactory.java | 53 + .../sca/core/assembly/RuntimeComponentImpl.java | 81 ++ .../assembly/RuntimeComponentReferenceImpl.java | 105 ++ .../core/assembly/RuntimeComponentServiceImpl.java | 119 ++ .../tuscany/sca/core/assembly/RuntimeWireImpl.java | 279 +++++ .../sca/core/context/CallableReferenceImpl.java | 349 ++++++ .../sca/core/context/ComponentContextHelper.java | 295 +++++ .../sca/core/context/ComponentContextImpl.java | 356 ++++++ .../context/DefaultComponentContextFactory.java | 70 ++ .../tuscany/sca/core/context/InstanceWrapper.java | 48 + .../sca/core/context/RequestContextImpl.java | 101 ++ .../sca/core/context/ServiceReferenceImpl.java | 119 ++ .../core/conversation/ConversationListener.java | 40 + .../sca/core/conversation/ConversationManager.java | 61 + .../core/conversation/ConversationManagerImpl.java | 107 ++ .../sca/core/conversation/ConversationState.java | 29 + .../core/conversation/ExtendedConversation.java | 50 + .../conversation/ExtendedConversationImpl.java | 76 ++ .../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 | 62 + .../invocation/CallbackInterfaceInterceptor.java | 57 + .../core/invocation/CallbackWireObjectFactory.java | 183 +++ .../sca/core/invocation/CglibProxyFactory.java | 139 +++ .../DefaultProxyFactoryExtensionPoint.java | 144 +++ .../core/invocation/ExtensibleWireProcessor.java | 44 + .../sca/core/invocation/InvocationChainImpl.java | 130 +++ .../invocation/JDKCallbackInvocationHandler.java | 131 +++ .../sca/core/invocation/JDKInvocationHandler.java | 411 +++++++ .../sca/core/invocation/JDKProxyFactory.java | 90 ++ .../sca/core/invocation/MessageFactoryImpl.java | 36 + .../tuscany/sca/core/invocation/MessageImpl.java | 96 ++ .../invocation/NoMethodForOperationException.java | 43 + .../core/invocation/NonBlockingInterceptor.java | 159 +++ .../core/invocation/ProxyCreationException.java | 48 + .../tuscany/sca/core/invocation/ProxyFactory.java | 78 ++ .../invocation/ProxyFactoryExtensionPoint.java | 58 + .../sca/core/invocation/RuntimeWireInvoker.java | 295 +++++ .../core/invocation/TargetInvocationException.java | 45 + .../sca/core/invocation/ThreadMessageContext.java | 72 ++ .../sca/core/invocation/WireObjectFactory.java | 43 + .../sca/core/scope/AbstractScopeContainer.java | 201 ++++ .../sca/core/scope/CompositeScopeContainer.java | 77 ++ .../core/scope/CompositeScopeContainerFactory.java | 37 + .../core/scope/ConversationalScopeContainer.java | 405 +++++++ .../scope/ConversationalScopeContainerFactory.java | 44 + .../sca/core/scope/HttpSessionScopeContainer.java | 83 ++ .../scope/HttpSessionScopeContainerFactory.java | 41 + .../sca/core/scope/RequestScopeContainer.java | 86 ++ .../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 | 55 + .../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 ++++ .../apache/tuscany/sca/core/work/Jsr237Work.java | 63 + .../tuscany/sca/core/work/Jsr237WorkScheduler.java | 165 +++ .../sca/core/work/ThreadPoolWorkManager.java | 219 ++++ .../tuscany/sca/core/work/WorkEventImpl.java | 74 ++ .../apache/tuscany/sca/core/work/WorkItemImpl.java | 168 +++ .../DefaultExtensionPointRegistryTestCase.java | 52 + .../sca/core/event/BaseEventPublisherTestCase.java | 98 ++ .../tuscany/sca/core/event/EventTestCase.java | 69 ++ .../core/scope/AbstractScopeContainerTestCase.java | 69 ++ .../sca/core/store/MemoryStoreTestCase.java | 165 +++ .../wire/CallbackInterfaceInterceptorTestCase.java | 62 + .../sca/core/wire/InvocationChainImplTestCase.java | 66 ++ .../core/wire/NonBlockingInterceptorTestCase.java | 73 ++ .../apache/tuscany/sca/scope/ScopeTestCase.java | 61 + .../1.0-RC1b/modules/databinding-axiom/.ruleset | 191 +++ .../1.0-RC1b/modules/databinding-axiom/DISCLAIMER | 8 + .../sca/1.0-RC1b/modules/databinding-axiom/LICENSE | 205 ++++ .../sca/1.0-RC1b/modules/databinding-axiom/NOTICE | 6 + .../sca/1.0-RC1b/modules/databinding-axiom/pom.xml | 91 ++ .../sca/databinding/axiom/AxiomDataBinding.java | 65 ++ .../databinding/axiom/AxiomExceptionHandler.java | 61 + .../tuscany/sca/databinding/axiom/AxiomHelper.java | 142 +++ .../sca/databinding/axiom/OMElement2Object.java | 48 + .../sca/databinding/axiom/OMElement2String.java | 62 + .../axiom/OMElement2XMLStreamReader.java | 50 + .../databinding/axiom/OMElementWrapperHandler.java | 140 +++ .../sca/databinding/axiom/Object2OMElement.java | 61 + .../sca/databinding/axiom/String2OMElement.java | 60 + .../axiom/XMLStreamReader2OMElement.java | 63 + .../org.apache.tuscany.sca.databinding.DataBinding | 20 + ....apache.tuscany.sca.databinding.PullTransformer | 24 + .../axiom/AxiomExceptionHandlerTestCase.java | 109 ++ .../sca/databinding/axiom/OMElementTestCase.java | 125 ++ .../databinding-axiom/src/test/resources/ipo.xml | 51 + .../databinding-axiom/src/test/resources/ipo.xsd | 137 +++ .../src/test/resources/order.wsdl | 76 ++ .../sca/1.0-RC1b/modules/databinding-jaxb/.ruleset | 191 +++ .../1.0-RC1b/modules/databinding-jaxb/DISCLAIMER | 8 + .../sca/1.0-RC1b/modules/databinding-jaxb/LICENSE | 205 ++++ .../sca/1.0-RC1b/modules/databinding-jaxb/NOTICE | 6 + .../sca/1.0-RC1b/modules/databinding-jaxb/pom.xml | 155 +++ .../tuscany/sca/databinding/jaxb/JAXB2Node.java | 72 ++ .../sca/databinding/jaxb/JAXBContextHelper.java | 176 +++ .../sca/databinding/jaxb/JAXBDataBinding.java | 114 ++ .../sca/databinding/jaxb/JAXBExceptionHandler.java | 107 ++ .../sca/databinding/jaxb/JAXBWrapperHandler.java | 175 +++ .../jaxb/JAXWSJavaInterfaceProcessor.java | 117 ++ .../tuscany/sca/databinding/jaxb/Node2JAXB.java | 69 ++ .../tuscany/sca/databinding/jaxb/Reader2JAXB.java | 70 ++ .../sca/databinding/jaxb/XMLStreamReader2JAXB.java | 71 ++ .../org.apache.tuscany.sca.databinding.DataBinding | 19 + ....apache.tuscany.sca.databinding.PullTransformer | 22 + ...terfacedef.java.introspect.JavaInterfaceVisitor | 18 + .../databinding/jaxb/JAXBDataBindingTestCase.java | 129 +++ .../jaxb/JAXBExceptionHandlerTestCase.java | 81 ++ .../tuscany/databinding/jaxb/JAXBTestCase.java | 160 +++ .../jaxb/JAXBWrapperHandlerTestCase.java | 72 ++ .../jaxb/JAXWSJavaInterfaceProcessorTestCase.java | 102 ++ .../databinding/jaxb/fault/InvalidSymbolFault.java | 78 ++ .../jaxb/fault/InvalidSymbolFault_Exception.java | 64 + .../databinding-jaxb/src/test/resources/ipo.xsd | 136 +++ .../sca/1.0-RC1b/modules/databinding-json/.ruleset | 172 +++ .../1.0-RC1b/modules/databinding-json/LICENSE.txt | 202 ++++ .../1.0-RC1b/modules/databinding-json/NOTICE.txt | 14 + .../sca/1.0-RC1b/modules/databinding-json/pom.xml | 76 ++ .../tuscany/sca/databinding/json/JSON2String.java | 57 + .../sca/databinding/json/JSON2XMLStreamReader.java | 60 + .../sca/databinding/json/JSONDataBinding.java | 52 + .../tuscany/sca/databinding/json/String2JSON.java | 57 + .../sca/databinding/json/XMLStreamReader2JSON.java | 68 ++ .../sca/databinding/json/XMLStreamSerializer.java | 291 +++++ .../sca/databinding/json/axiom/JSON2OMElement.java | 84 ++ .../json/axiom/JSONBadgerfishDataSource.java | 57 + .../sca/databinding/json/axiom/JSONDataSource.java | 174 +++ .../org.apache.tuscany.sca.databinding.DataBinding | 19 + ....apache.tuscany.sca.databinding.PullTransformer | 21 + .../databinding/json/JSONTransformerTestCase.java | 129 +++ .../databinding-json/src/test/resources/ipo.xsd | 136 +++ .../1.0-RC1b/modules/databinding-saxon/LICENSE.txt | 202 ++++ .../1.0-RC1b/modules/databinding-saxon/NOTICE.txt | 14 + .../modules/databinding-saxon/mvn-install-saxon.sh | 37 + .../sca/1.0-RC1b/modules/databinding-saxon/pom.xml | 76 ++ .../saxon/DataObject2NodeInfoTransformer.java | 118 ++ .../saxon/Node2NodeInfoTransformer.java | 73 ++ .../saxon/NodeInfo2DataObjectTransformer.java | 108 ++ .../saxon/NodeInfo2NodeTransformer.java | 70 ++ .../databinding/saxon/Object2ValueTransformer.java | 53 + .../databinding/saxon/SaxonDataBindingHelper.java | 41 + .../databinding/saxon/SaxonNodeDataBinding.java | 53 + .../databinding/saxon/SaxonValueDataBinding.java | 52 + .../saxon/SimpleType2ValueTransformer.java | 88 ++ .../databinding/saxon/Value2ObjectTransformer.java | 60 + .../saxon/Value2SimpleTypeTransformer.java | 65 ++ .../module/SaxonDataBindingModuleActivator.java | 70 ++ .../org.apache.tuscany.sca.core.ModuleActivator | 18 + .../modules/databinding-sdo-axiom/.checkstyle | 25 + .../modules/databinding-sdo-axiom/.ruleset | 191 +++ .../modules/databinding-sdo-axiom/DISCLAIMER | 8 + .../1.0-RC1b/modules/databinding-sdo-axiom/LICENSE | 205 ++++ .../1.0-RC1b/modules/databinding-sdo-axiom/NOTICE | 6 + .../1.0-RC1b/modules/databinding-sdo-axiom/pom.xml | 131 +++ .../sca/databinding/sdo2om/AxiomHelper.java | 142 +++ .../databinding/sdo2om/DataObject2OMElement.java | 86 ++ .../databinding/sdo2om/DataObjectSerializer.java | 427 +++++++ .../sca/databinding/sdo2om/SDODataSource.java | 85 ++ .../databinding/sdo2om/XMLDocument2OMElement.java | 65 ++ ....apache.tuscany.sca.databinding.PullTransformer | 20 + .../sdo2om/DataObject2OMElementTestCase.java | 77 ++ .../sdo2om/SDOTransformerTestCaseBase.java | 80 ++ .../sdo2om/XMLDocument2OMElementTestCase.java | 62 + .../src/test/resources/ipo.xsd | 136 +++ .../src/test/resources/stock.xsd | 33 + .../1.0-RC1b/modules/databinding-sdo/.checkstyle | 25 + .../sca/1.0-RC1b/modules/databinding-sdo/.ruleset | 191 +++ .../1.0-RC1b/modules/databinding-sdo/DISCLAIMER | 8 + .../sca/1.0-RC1b/modules/databinding-sdo/LICENSE | 205 ++++ .../sca/1.0-RC1b/modules/databinding-sdo/NOTICE | 6 + .../sca/1.0-RC1b/modules/databinding-sdo/pom.xml | 119 ++ .../sca/databinding/sdo/DataObject2String.java | 61 + .../sdo/DataObject2XMLStreamReader.java | 70 ++ .../tuscany/sca/databinding/sdo/ImportSDO.java | 78 ++ .../sca/databinding/sdo/ImportSDOProcessor.java | 162 +++ .../sca/databinding/sdo/SDOContextHelper.java | 154 +++ .../sca/databinding/sdo/SDODataBinding.java | 119 ++ .../sca/databinding/sdo/SDOExceptionHandler.java | 124 ++ .../sca/databinding/sdo/SDOSimpleTypeMapper.java | 66 ++ .../sca/databinding/sdo/SDOWrapperHandler.java | 168 +++ .../sca/databinding/sdo/String2DataObject.java | 58 + .../sca/databinding/sdo/XMLDocument2String.java | 62 + .../sdo/XMLDocument2XMLStreamReader.java | 66 ++ .../sdo/XMLStreamReader2DataObject.java | 69 ++ .../sdo/XMLStreamReader2XMLDocument.java | 63 + ...ca.contribution.processor.StAXArtifactProcessor | 18 + .../org.apache.tuscany.sca.databinding.DataBinding | 19 + ....apache.tuscany.sca.databinding.PullTransformer | 25 + .../sdo/fault/InvalidSymbolFault_Exception.java | 69 ++ .../databinding/sdo/DataObject2StringTestCase.java | 64 + .../sdo/DataObject2XMLStreamReaderTestCase.java | 58 + .../sdo/ImportSDOProcessorTestCase.java | 83 ++ .../databinding/sdo/SDODataBindingTestCase.java | 111 ++ .../sdo/SDOExceptionHandlerTestCase.java | 83 ++ .../sdo/SDOTransformerTestCaseBase.java | 80 ++ .../databinding/sdo/SDOWrapperHandlerTestCase.java | 75 ++ .../sca/databinding/sdo/TestModelResolver.java | 63 + .../sdo/XMLDocument2XMLStreamReaderTestCase.java | 61 + .../databinding-sdo/src/test/resources/ipo.xsd | 136 +++ .../src/test/resources/model/sca-core.xsd | 233 ++++ .../resources/model/sca-implementation-mock.xsd | 43 + .../databinding-sdo/src/test/resources/stock.xsd | 33 + .../databinding-sdo/src/test/resources/wrapper.xml | 27 + .../databinding-sdo/src/test/resources/wrapper.xsd | 38 + .../1.0-RC1b/modules/databinding-xmlbeans/.ruleset | 172 +++ .../modules/databinding-xmlbeans/LICENSE.txt | 202 ++++ .../modules/databinding-xmlbeans/NOTICE.txt | 14 + .../1.0-RC1b/modules/databinding-xmlbeans/pom.xml | 111 ++ .../sca/databinding/xmlbeans/Node2XmlObject.java | 56 + .../databinding/xmlbeans/XMLBeansDataBinding.java | 41 + .../xmlbeans/XMLStreamReader2XmlObject.java | 57 + .../sca/databinding/xmlbeans/XmlObject2Node.java | 55 + .../xmlbeans/XmlObject2XMLStreamReader.java | 50 + .../org.apache.tuscany.sca.databinding.DataBinding | 19 + ....apache.tuscany.sca.databinding.PullTransformer | 22 + .../databinding/xmlbeans/XmlObjectTestCase.java | 100 ++ .../src/test/resources/ipo.xsd | 136 +++ .../src/test/resources/ipo.xsdconfig | 21 + .../sca/1.0-RC1b/modules/databinding/.checkstyle | 25 + tags/java/sca/1.0-RC1b/modules/databinding/.pmd | 20 + .../java/sca/1.0-RC1b/modules/databinding/.ruleset | 190 +++ .../sca/1.0-RC1b/modules/databinding/DISCLAIMER | 8 + tags/java/sca/1.0-RC1b/modules/databinding/LICENSE | 205 ++++ tags/java/sca/1.0-RC1b/modules/databinding/NOTICE | 6 + tags/java/sca/1.0-RC1b/modules/databinding/pom.xml | 51 + .../tuscany/sca/databinding/DataBinding.java | 99 ++ .../sca/databinding/DataBindingExtensionPoint.java | 82 ++ .../apache/tuscany/sca/databinding/DataPipe.java | 44 + .../sca/databinding/DataPipeTransformer.java | 28 + .../DefaultDataBindingExtensionPoint.java | 254 ++++ .../DefaultTransformerExtensionPoint.java | 257 +++++ .../tuscany/sca/databinding/ExceptionHandler.java | 57 + .../apache/tuscany/sca/databinding/Mediator.java | 67 ++ .../tuscany/sca/databinding/PullTransformer.java | 36 + .../tuscany/sca/databinding/PushTransformer.java | 34 + .../tuscany/sca/databinding/SimpleTypeMapper.java | 44 + .../sca/databinding/TransformationContext.java | 79 ++ .../sca/databinding/TransformationException.java | 63 + .../tuscany/sca/databinding/Transformer.java | 49 + .../sca/databinding/TransformerExtensionPoint.java | 76 ++ .../tuscany/sca/databinding/WrapperHandler.java | 82 ++ .../sca/databinding/annotation/DataBinding.java | 44 + .../sca/databinding/annotation/DataType.java | 49 + .../sca/databinding/impl/BaseDataBinding.java | 130 +++ .../sca/databinding/impl/BaseTransformer.java | 52 + .../tuscany/sca/databinding/impl/DOMHelper.java | 76 ++ .../sca/databinding/impl/DirectedGraph.java | 363 ++++++ .../databinding/impl/Group2GroupTransformer.java | 92 ++ .../sca/databinding/impl/GroupDataBinding.java | 97 ++ .../impl/Java2SimpleTypeTransformer.java | 68 ++ .../tuscany/sca/databinding/impl/MediatorImpl.java | 165 +++ .../sca/databinding/impl/PipedTransformer.java | 68 ++ .../databinding/impl/ServiceConfigurationUtil.java | 98 ++ .../impl/SimpleType2JavaTransformer.java | 87 ++ .../sca/databinding/impl/SimpleTypeMapperImpl.java | 396 +++++++ .../impl/TransformationContextImpl.java | 113 ++ .../sca/databinding/impl/XSDDataTypeConverter.java | 943 +++++++++++++++ .../javabeans/DOMNode2JavaBeanTransformer.java | 76 ++ .../javabeans/Java2XMLMapperException.java | 67 ++ .../javabeans/JavaBean2DOMNodeTransformer.java | 75 ++ .../javabeans/JavaBean2XMLStreamReader.java | 56 + .../javabeans/JavaBean2XMLTransformer.java | 228 ++++ .../javabeans/JavaBeansDataBinding.java | 112 ++ .../javabeans/JavaBeansExceptionHandler.java | 50 + .../javabeans/SimpleJavaDataBinding.java | 65 ++ .../javabeans/XML2JavaBeanTransformer.java | 296 +++++ .../javabeans/XML2JavaMapperException.java | 74 ++ .../tuscany/sca/databinding/xml/BeanUtil.java | 198 ++++ .../sca/databinding/xml/DOMDataBinding.java | 70 ++ .../sca/databinding/xml/DOMWrapperHandler.java | 120 ++ .../sca/databinding/xml/DOMXMLStreamReader.java | 129 +++ .../xml/DelegatingNamespaceContext.java | 310 +++++ .../sca/databinding/xml/InputSource2Node.java | 65 ++ .../sca/databinding/xml/InputSource2SAX.java | 63 + .../sca/databinding/xml/InputStream2Node.java | 67 ++ .../sca/databinding/xml/InputStream2SAX.java | 62 + .../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 | 66 ++ .../sca/databinding/xml/Node2SimpleJavaType.java | 43 + .../tuscany/sca/databinding/xml/Node2String.java | 60 + .../tuscany/sca/databinding/xml/Node2Writer.java | 65 ++ .../sca/databinding/xml/Node2XMLStreamReader.java | 59 + .../tuscany/sca/databinding/xml/Reader2Node.java | 65 ++ .../tuscany/sca/databinding/xml/Reader2SAX.java | 58 + .../tuscany/sca/databinding/xml/SAX2DOM.java | 244 ++++ .../tuscany/sca/databinding/xml/SAX2DOMPipe.java | 81 ++ .../sca/databinding/xml/SimpleJavaType2Node.java | 69 ++ .../databinding/xml/Source2ResultTransformer.java | 61 + .../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 | 59 + .../databinding/xml/String2XMLStreamReader.java | 55 + .../databinding/xml/WrappingXMLStreamReader.java | 230 ++++ .../sca/databinding/xml/Writer2ReaderDataPipe.java | 63 + .../databinding/xml/XMLDocumentStreamReader.java | 451 ++++++++ .../databinding/xml/XMLFragmentStreamReader.java | 53 + .../xml/XMLFragmentStreamReaderImpl.java | 857 ++++++++++++++ .../sca/databinding/xml/XMLGroupDataBinding.java | 58 + .../sca/databinding/xml/XMLStreamReader2Node.java | 66 ++ .../sca/databinding/xml/XMLStreamReader2SAX.java | 74 ++ .../databinding/xml/XMLStreamReader2String.java | 57 + .../sca/databinding/xml/XMLStreamSerializer.java | 285 +++++ .../tuscany/sca/databinding/xml/XMLStreamable.java | 37 + .../sca/databinding/xml/XMLStringDataBinding.java | 51 + .../org.apache.tuscany.sca.databinding.DataBinding | 23 + ...scany.sca.databinding.DataBindingExtensionPoint | 18 + ....apache.tuscany.sca.databinding.PullTransformer | 34 + ....apache.tuscany.sca.databinding.PushTransformer | 26 + ...scany.sca.databinding.TransformerExtensionPoint | 18 + .../databinding/extension/DOMHelperTestCase.java | 57 + .../extension/DataBindingExtensionTestCase.java | 85 ++ .../SimpleTypeMapperExtensionTestCase.java | 121 ++ .../extension/TransformerExtensionTestCase.java | 75 ++ .../extension/XSDDataTypeConverterTestCase.java | 63 + .../impl/DataBindingRegistryImplTestCase.java | 103 ++ .../sca/databinding/impl/DataBindingTestCase.java | 45 + .../databinding/impl/DirectedGraphTestCase.java | 91 ++ .../sca/databinding/impl/MediatorImplTestCase.java | 120 ++ .../impl/TransformerRegistryImplTestCase.java | 108 ++ .../sca/databinding/xml/DOM2StAXTestCase.java | 90 ++ .../sca/databinding/xml/DataPipeTestCase.java | 91 ++ .../xml/JavaBean2XMLStreamReaderTestCase.java | 134 +++ .../sca/databinding/xml/Node2StringTestCase.java | 35 + .../xml/PushTransformationTestCase.java | 82 ++ .../sca/databinding/xml/StAXHelperTestCase.java | 48 + .../databinding/xml/TraxTransformerTestCase.java | 100 ++ .../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/1.0-RC1b/modules/definitions/DISCLAIMER | 8 + tags/java/sca/1.0-RC1b/modules/definitions/LICENSE | 205 ++++ tags/java/sca/1.0-RC1b/modules/definitions/NOTICE | 6 + tags/java/sca/1.0-RC1b/modules/definitions/pom.xml | 77 ++ .../tuscany/sca/definitions/SCADefinitions.java | 74 ++ .../sca/definitions/SCADefinitionsBuilder.java | 34 + .../SCADefinitionsBuilderException.java | 42 + .../sca/definitions/SCADefinitionsBuilderImpl.java | 298 +++++ .../SCADefinitionsDocumentProcessor.java | 145 +++ .../sca/definitions/SCADefinitionsProcessor.java | 196 ++++ .../sca/definitions/SCADefinitionsResolver.java | 52 + .../sca/definitions/impl/BindingTypeImpl.java | 63 + .../definitions/impl/ImplementationTypeImpl.java | 62 + .../sca/definitions/impl/SCADefinitionsImpl.java | 66 ++ .../sca/definitions/MockPolicyProcessor.java | 74 ++ .../org/apache/tuscany/sca/definitions/Policy.java | 32 + .../sca/definitions/ReadDocumentTestCase.java | 203 ++++ .../tuscany/sca/definitions/test_definitions.xml | 220 ++++ .../sca/1.0-RC1b/modules/domain-api/DISCLAIMER | 8 + tags/java/sca/1.0-RC1b/modules/domain-api/LICENSE | 205 ++++ tags/java/sca/1.0-RC1b/modules/domain-api/NOTICE | 6 + tags/java/sca/1.0-RC1b/modules/domain-api/pom.xml | 42 + .../org/apache/tuscany/sca/domain/SCADomain.java | 256 ++++ .../sca/1.0-RC1b/modules/domain-impl/DISCLAIMER | 8 + tags/java/sca/1.0-RC1b/modules/domain-impl/LICENSE | 205 ++++ tags/java/sca/1.0-RC1b/modules/domain-impl/NOTICE | 6 + tags/java/sca/1.0-RC1b/modules/domain-impl/pom.xml | 101 ++ .../sca/domain/impl/DomainManagerServiceImpl.java | 94 ++ .../tuscany/sca/domain/impl/NodeInfoImpl.java | 71 ++ .../sca/domain/impl/SCADomainServiceImpl.java | 200 ++++ .../tuscany/sca/domain/impl/ServiceInfoImpl.java | 84 ++ .../main/resources/META-INF/sca-contribution.xml | 24 + .../src/main/resources/domain.composite | 53 + .../src/main/resources/webroot/domain.png | Bin 0 -> 718 bytes .../src/main/resources/webroot/index.html | 354 ++++++ .../src/main/resources/webroot/node.png | Bin 0 -> 296 bytes .../src/main/resources/webroot/style.css | 176 +++ tags/java/sca/1.0-RC1b/modules/domain/DISCLAIMER | 8 + tags/java/sca/1.0-RC1b/modules/domain/LICENSE | 205 ++++ tags/java/sca/1.0-RC1b/modules/domain/NOTICE | 6 + tags/java/sca/1.0-RC1b/modules/domain/pom.xml | 67 ++ .../tuscany/sca/domain/DomainManagerService.java | 81 ++ .../org/apache/tuscany/sca/domain/NodeInfo.java | 70 ++ .../tuscany/sca/domain/SCADomainService.java | 78 ++ .../org/apache/tuscany/sca/domain/ServiceInfo.java | 40 + .../1.0-RC1b/modules/extension-helper/DISCLAIMER | 8 + .../sca/1.0-RC1b/modules/extension-helper/LICENSE | 205 ++++ .../sca/1.0-RC1b/modules/extension-helper/NOTICE | 6 + .../sca/1.0-RC1b/modules/extension-helper/pom.xml | 69 ++ .../sca/extension/helper/BindingActivator.java | 67 ++ .../sca/extension/helper/ComponentLifecycle.java | 28 + .../extension/helper/ImplementationActivator.java | 62 + .../sca/extension/helper/InvokerFactory.java | 29 + .../helper/impl/BindingSCDLProcessor.java | 192 +++ .../extension/helper/impl/BindingsActivator.java | 259 +++++ .../sca/extension/helper/impl/DiscoveryUtils.java | 164 +++ .../impl/ImplementationImplementationProvider.java | 97 ++ .../helper/impl/ImplementationsActivator.java | 138 +++ .../sca/extension/helper/impl/PojoBinding.java | 36 + .../extension/helper/impl/PojoImplementation.java | 42 + .../sca/extension/helper/impl/SCDLProcessor.java | 246 ++++ .../extension/helper/utils/AbstractBinding.java | 65 ++ .../helper/utils/AbstractImplementation.java | 114 ++ .../utils/AbstractStAXArtifactProcessor.java | 115 ++ .../utils/DefaultPropertyValueObjectFactory.java | 229 ++++ .../helper/utils/DynamicImplementation.java | 92 ++ .../helper/utils/PropertyValueObjectFactory.java | 29 + .../sca/extension/helper/utils/ResourceHelper.java | 72 ++ .../org.apache.tuscany.sca.core.ModuleActivator | 20 + .../sca/1.0-RC1b/modules/host-embedded/.checkstyle | 24 + tags/java/sca/1.0-RC1b/modules/host-embedded/.pmd | 21 + .../sca/1.0-RC1b/modules/host-embedded/.ruleset | 190 +++ .../sca/1.0-RC1b/modules/host-embedded/DISCLAIMER | 8 + .../sca/1.0-RC1b/modules/host-embedded/LICENSE | 205 ++++ .../java/sca/1.0-RC1b/modules/host-embedded/NOTICE | 6 + .../sca/1.0-RC1b/modules/host-embedded/pom.xml | 89 ++ .../tuscany/sca/host/embedded/SCADomain.java | 272 +++++ .../tuscany/sca/host/embedded/SCADomainBean.java | 121 ++ .../sca/host/embedded/SCATestCaseRunner.java | 213 ++++ .../host/embedded/impl/ComponentManagerImpl.java | 115 ++ .../sca/host/embedded/impl/DefaultSCADomain.java | 563 +++++++++ .../sca/host/embedded/impl/EmbeddedSCADomain.java | 230 ++++ .../host/embedded/impl/HotUpdatableSCADomain.java | 391 +++++++ .../sca/host/embedded/impl/ReallySmallRuntime.java | 263 +++++ .../embedded/impl/ReallySmallRuntimeBuilder.java | 270 +++++ .../embedded/management/ComponentListener.java | 29 + .../host/embedded/management/ComponentManager.java | 43 + .../sca/host/embedded/SCADomainBeanTestCase.java | 65 ++ .../sca/host/embedded/SCADomainTestCase.java | 64 + .../embedded/impl/DefaultSCADomainTestCase.java | 67 ++ .../embedded/impl/EmbeddedSCADomainTestCase.java | 199 ++++ .../sca/host/embedded/impl/TestModelResolver.java | 104 ++ .../src/test/java/test/crud/CRUD.java | 56 + .../test/java/test/crud/CRUDImplementation.java | 51 + .../java/test/crud/CRUDImplementationFactory.java | 38 + .../crud/DefaultCRUDImplementationFactory.java | 50 + .../java/test/crud/backend/ResourceManager.java | 92 ++ .../test/crud/impl/CRUDImplementationImpl.java | 118 ++ .../crud/impl/CRUDImplementationProcessor.java | 102 ++ .../java/test/crud/module/CRUDModuleActivator.java | 69 ++ .../crud/provider/CRUDImplementationProvider.java | 73 ++ .../CRUDImplementationProviderFactory.java | 49 + .../test/java/test/crud/provider/CRUDInvoker.java | 80 ++ .../org.apache.tuscany.sca.core.ModuleActivator | 18 + .../src/test/resources/crud.composite | 30 + .../host-embedded/src/test/resources/test.txt | 16 + .../java/sca/1.0-RC1b/modules/host-http/DISCLAIMER | 8 + tags/java/sca/1.0-RC1b/modules/host-http/LICENSE | 205 ++++ tags/java/sca/1.0-RC1b/modules/host-http/NOTICE | 6 + tags/java/sca/1.0-RC1b/modules/host-http/pom.xml | 46 + .../sca/host/http/DefaultResourceServlet.java | 85 ++ .../http/DefaultServletHostExtensionPoint.java | 45 + .../sca/host/http/ExtensibleServletHost.java | 82 ++ .../apache/tuscany/sca/host/http/ServletHost.java | 82 ++ .../sca/host/http/ServletHostExtensionPoint.java | 51 + .../sca/host/http/ServletMappingException.java | 44 + ...tuscany.sca.host.http.ServletHostExtensionPoint | 18 + tags/java/sca/1.0-RC1b/modules/host-jetty/.ruleset | 190 +++ .../sca/1.0-RC1b/modules/host-jetty/DISCLAIMER | 8 + tags/java/sca/1.0-RC1b/modules/host-jetty/LICENSE | 205 ++++ tags/java/sca/1.0-RC1b/modules/host-jetty/NOTICE | 6 + tags/java/sca/1.0-RC1b/modules/host-jetty/pom.xml | 63 + .../sca/http/jetty/JettyDefaultServlet.java | 91 ++ .../apache/tuscany/sca/http/jetty/JettyLogger.java | 87 ++ .../apache/tuscany/sca/http/jetty/JettyServer.java | 345 ++++++ .../jetty/module/JettyRuntimeModuleActivator.java | 49 + .../org.apache.tuscany.sca.core.ModuleActivator | 18 + .../sca/http/jetty/JettyServerTestCase.java | 278 +++++ .../src/test/resources/content/test.html | 21 + tags/java/sca/1.0-RC1b/modules/host-rmi/DISCLAIMER | 8 + tags/java/sca/1.0-RC1b/modules/host-rmi/LICENSE | 205 ++++ tags/java/sca/1.0-RC1b/modules/host-rmi/NOTICE | 6 + tags/java/sca/1.0-RC1b/modules/host-rmi/pom.xml | 38 + .../tuscany/sca/host/rmi/DefaultRMIHost.java | 130 +++ .../sca/host/rmi/DefaultRMIHostExtensionPoint.java | 49 + .../tuscany/sca/host/rmi/ExtensibleRMIHost.java | 73 ++ .../org/apache/tuscany/sca/host/rmi/RMIHost.java | 88 ++ .../tuscany/sca/host/rmi/RMIHostException.java | 45 + .../sca/host/rmi/RMIHostExtensionPoint.java | 51 + .../sca/host/rmi/RMIHostRuntimeException.java | 45 + ...ache.tuscany.sca.host.rmi.RMIHostExtensionPoint | 18 + .../tuscany/sca/host/rmi/RMIHostImplTestCase.java | 79 ++ .../java/sca/1.0-RC1b/modules/host-tomcat/.ruleset | 190 +++ .../sca/1.0-RC1b/modules/host-tomcat/DISCLAIMER | 8 + tags/java/sca/1.0-RC1b/modules/host-tomcat/LICENSE | 205 ++++ tags/java/sca/1.0-RC1b/modules/host-tomcat/NOTICE | 6 + tags/java/sca/1.0-RC1b/modules/host-tomcat/pom.xml | 83 ++ .../tuscany/sca/http/tomcat/ServletWrapper.java | 58 + .../sca/http/tomcat/TomcatDefaultServlet.java | 99 ++ .../tuscany/sca/http/tomcat/TomcatServer.java | 374 ++++++ .../module/TomcatRuntimeModuleActivator.java | 49 + .../org.apache.tuscany.sca.core.ModuleActivator | 18 + .../sca/http/tomcat/TomcatServerTestCase.java | 279 +++++ .../src/test/resources/content/test.html | 21 + .../sca/1.0-RC1b/modules/host-webapp/DISCLAIMER | 8 + tags/java/sca/1.0-RC1b/modules/host-webapp/LICENSE | 205 ++++ tags/java/sca/1.0-RC1b/modules/host-webapp/NOTICE | 6 + tags/java/sca/1.0-RC1b/modules/host-webapp/pom.xml | 59 + .../sca/host/webapp/HotUpdateContextListener.java | 55 + .../tuscany/sca/host/webapp/SCADomainHelper.java | 71 ++ .../sca/host/webapp/TuscanyContextListener.java | 54 + .../tuscany/sca/host/webapp/TuscanyServlet.java | 66 ++ .../sca/host/webapp/TuscanyServletFilter.java | 97 ++ .../sca/host/webapp/WebAppModuleActivator.java | 42 + .../sca/host/webapp/WebAppRequestDispatcher.java | 84 ++ .../tuscany/sca/host/webapp/WebAppServletHost.java | 213 ++++ .../org.apache.tuscany.sca.core.ModuleActivator | 18 + .../modules/implementation-bpel/DISCLAIMER | 8 + .../1.0-RC1b/modules/implementation-bpel/LICENSE | 251 ++++ .../1.0-RC1b/modules/implementation-bpel/NOTICE | 17 + .../1.0-RC1b/modules/implementation-bpel/pom.xml | 430 +++++++ .../sca/implementation/bpel/BPELFactory.java | 41 + .../implementation/bpel/BPELImplementation.java | 55 + .../implementation/bpel/BPELProcessDefinition.java | 58 + .../implementation/bpel/DefaultBPELFactory.java | 53 + .../bpel/impl/BPELDocumentProcessor.java | 131 +++ .../bpel/impl/BPELImplementationImpl.java | 195 ++++ .../bpel/impl/BPELImplementationProcessor.java | 223 ++++ .../bpel/impl/BPELProcessDefinitionImpl.java | 101 ++ .../bpel/impl/ODEProcessException.java | 42 + .../implementation/bpel/ode/EmbeddedODEServer.java | 232 ++++ .../implementation/bpel/ode/GeronimoTxFactory.java | 48 + .../implementation/bpel/ode/ODEBindingContext.java | 43 + .../sca/implementation/bpel/ode/ODEDeployment.java | 43 + .../bpel/ode/ODEInitializationException.java | 41 + .../bpel/ode/ODEMessageExchangeContext.java | 23 + .../bpel/ode/ODEShutdownException.java | 41 + .../bpel/provider/BPELImplementationProvider.java | 116 ++ .../BPELImplementationProviderFactory.java | 61 + .../implementation/bpel/provider/BPELInvoker.java | 214 ++++ ...ca.contribution.processor.StAXArtifactProcessor | 20 + ...sca.contribution.processor.URLArtifactProcessor | 19 + ...che.tuscany.sca.implementation.bpel.BPELFactory | 18 + ...cany.sca.provider.ImplementationProviderFactory | 19 + .../bpel/BPELDocumentProcessorTestCase.java | 67 ++ .../bpel/BPELHelloWorldTestCase.java | 59 + .../bpel/BPELImplementationProcessorTestCase.java | 122 ++ .../bpel/EmbeddedODEServerTestCase.java | 128 ++ .../src/test/resources/deploy.xml | 30 + .../src/test/resources/helloworld.bpel | 66 ++ .../src/test/resources/helloworld.componentType | 30 + .../src/test/resources/helloworld.composite | 29 + .../src/test/resources/helloworld.wsdl | 82 ++ .../src/test/resources/log4j.properties | 33 + .../implementation-java-runtime/.checkstyle | 24 + .../modules/implementation-java-runtime/.pmd | 20 + .../modules/implementation-java-runtime/.ruleset | 190 +++ .../modules/implementation-java-runtime/DISCLAIMER | 8 + .../modules/implementation-java-runtime/LICENSE | 205 ++++ .../modules/implementation-java-runtime/NOTICE | 6 + .../modules/implementation-java-runtime/pom.xml | 74 ++ .../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 | 33 + .../java/injection/FieldInjector.java | 57 + .../java/injection/InjectionRuntimeException.java | 45 + .../implementation/java/injection/Injector.java | 35 + .../java/injection/InvalidAccessorException.java | 43 + .../injection/JavaPropertyValueObjectFactory.java | 202 ++++ .../injection/ListMultiplicityObjectFactory.java | 50 + .../java/injection/MethodInjector.java | 55 + .../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 | 105 ++ .../invocation/JavaComponentContextFactory.java | 40 + .../invocation/JavaComponentContextProvider.java | 278 +++++ .../java/invocation/JavaComponentNameFactory.java | 40 + .../java/invocation/JavaImplementationInvoker.java | 125 ++ .../invocation/JavaImplementationProvider.java | 173 +++ .../JavaImplementationProviderFactory.java | 64 + .../invocation/JavaInstanceFactoryProvider.java | 183 +++ .../java/invocation/MethodEventInvoker.java | 56 + .../NoConversationalContractException.java | 34 + .../java/module/JavaRuntimeModuleActivator.java | 132 +++ .../org.apache.tuscany.sca.core.ModuleActivator | 18 + .../java/context/MultiplicityTestCase.java | 34 + .../context/ReflectiveInstanceWrapperTestCase.java | 84 ++ .../CallbackWireObjectFactoryTestCase.java | 54 + .../java/injection/FieldInjectorTestCase.java | 49 + .../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 | 46 + .../sca/implementation/java/util/Bean2.java | 47 + .../sca/implementation/java/util/Entry.java | 32 + .../java/util/JavaIntrospectionHelperTestCase.java | 181 +++ .../sca/implementation/java/util/SuperBean.java | 48 + .../modules/implementation-java-xml/.checkstyle | 24 + .../1.0-RC1b/modules/implementation-java-xml/.pmd | 20 + .../modules/implementation-java-xml/.ruleset | 190 +++ .../modules/implementation-java-xml/DISCLAIMER | 8 + .../modules/implementation-java-xml/LICENSE | 205 ++++ .../modules/implementation-java-xml/NOTICE | 6 + .../modules/implementation-java-xml/pom.xml | 65 ++ .../java/xml/JavaImplementationConstants.java | 31 + .../java/xml/JavaImplementationProcessor.java | 239 ++++ ...ca.contribution.processor.StAXArtifactProcessor | 19 + .../src/test/java/calculator/AddService.java | 25 + .../src/test/java/calculator/AddServiceImpl.java | 35 + .../test/java/calculator/CalculatorService.java | 34 + .../java/calculator/CalculatorServiceImpl.java | 71 ++ .../src/test/java/calculator/DivideService.java | 25 + .../test/java/calculator/DivideServiceImpl.java | 33 + .../src/test/java/calculator/MultiplyService.java | 25 + .../test/java/calculator/MultiplyServiceImpl.java | 33 + .../src/test/java/calculator/SubtractService.java | 25 + .../test/java/calculator/SubtractServiceImpl.java | 33 + .../sca/implementation/java/xml/ReadTestCase.java | 125 ++ .../implementation/java/xml/TestModelResolver.java | 88 ++ .../sca/implementation/java/xml/WriteTestCase.java | 101 ++ .../implementation/java/xml/Calculator.composite | 53 + .../modules/implementation-java/.checkstyle | 24 + .../sca/1.0-RC1b/modules/implementation-java/.pmd | 21 + .../1.0-RC1b/modules/implementation-java/.ruleset | 190 +++ .../modules/implementation-java/DISCLAIMER | 8 + .../1.0-RC1b/modules/implementation-java/LICENSE | 205 ++++ .../1.0-RC1b/modules/implementation-java/NOTICE | 6 + .../1.0-RC1b/modules/implementation-java/pom.xml | 50 + .../java/BaseJavaImplementation.java | 59 + .../java/DefaultJavaImplementationFactory.java | 31 + .../java/IntrospectionException.java | 60 + .../implementation/java/JavaImplementation.java | 186 +++ .../java/JavaImplementationFactory.java | 75 ++ .../java/impl/BaseJavaImplementationImpl.java | 84 ++ .../java/impl/JavaClassIntrospectorImpl.java | 125 ++ .../java/impl/JavaConstructorImpl.java | 53 + .../implementation/java/impl/JavaElementImpl.java | 224 ++++ .../java/impl/JavaImplementationFactoryImpl.java | 68 ++ .../java/impl/JavaImplementationImpl.java | 156 +++ .../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 | 168 +++ .../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 | 68 ++ .../introspect/impl/ConversationProcessor.java | 136 +++ .../java/introspect/impl/DestroyProcessor.java | 58 + .../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 | 600 ++++++++++ .../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 | 58 + .../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 | 495 ++++++++ .../introspect/impl/NoConstructorException.java | 37 + .../java/introspect/impl/PolicyProcessor.java | 171 +++ .../java/introspect/impl/PropertyProcessor.java | 46 + .../java/introspect/impl/ReferenceProcessor.java | 178 +++ .../java/introspect/impl/Resource.java | 49 + .../java/introspect/impl/ResourceProcessor.java | 137 +++ .../java/introspect/impl/ScopeProcessor.java | 61 + .../java/introspect/impl/ServiceProcessor.java | 165 +++ .../impl/ServiceTypeNotFoundException.java | 35 + .../impl/UnknownContextTypeException.java | 33 + ...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 | 92 ++ .../impl/ConversationProcessorTestCase.java | 142 +++ .../introspect/impl/ConvertTimeMillisTestCase.java | 117 ++ .../introspect/impl/DestroyProcessorTestCase.java | 99 ++ .../impl/EagerInitProcessorTestCase.java | 59 + .../impl/HeuristicAndPropertyTestCase.java | 71 ++ .../impl/HeuristicConstructorTestCase.java | 310 +++++ .../impl/HeuristicPojoProcessorTestCase.java | 407 +++++++ .../HeutisticExtensibleConstructorTestCase.java | 148 +++ .../introspect/impl/InitProcessorTestCase.java | 99 ++ .../impl/JavaClassIntrospectorImplTestCase.java | 95 ++ .../java/introspect/impl/ModelHelper.java | 99 ++ .../introspect/impl/PolicyProcessorTestCase.java | 404 +++++++ .../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 | 143 +++ .../modules/implementation-node-runtime/DISCLAIMER | 8 + .../modules/implementation-node-runtime/LICENSE | 205 ++++ .../modules/implementation-node-runtime/NOTICE | 6 + .../modules/implementation-node-runtime/pom.xml | 61 + .../node/provider/NodeImplementationInvoker.java | 42 + .../node/provider/NodeImplementationProvider.java | 57 + .../NodeImplementationProviderFactory.java | 45 + ...cany.sca.provider.ImplementationProviderFactory | 19 + .../node/NodeImplementationTestCase.java | 45 + .../src/test/resources/TestComposite.composite | 29 + .../src/test/resources/TestNode.composite | 30 + .../modules/implementation-node-xml/DISCLAIMER | 8 + .../modules/implementation-node-xml/LICENSE | 205 ++++ .../modules/implementation-node-xml/NOTICE | 6 + .../modules/implementation-node-xml/pom.xml | 61 + .../node/xml/NodeImplementationProcessor.java | 119 ++ ...ca.contribution.processor.StAXArtifactProcessor | 19 + .../sca/implementation/node/xml/ReadTestCase.java | 101 ++ .../sca/implementation/node/xml/WriteTestCase.java | 99 ++ .../node/xml/TestComposite.composite | 29 + .../sca/implementation/node/xml/TestNode.composite | 30 + .../modules/implementation-node/DISCLAIMER | 8 + .../1.0-RC1b/modules/implementation-node/LICENSE | 205 ++++ .../1.0-RC1b/modules/implementation-node/NOTICE | 6 + .../1.0-RC1b/modules/implementation-node/pom.xml | 48 + .../implementation/node/NodeImplementation.java | 43 + .../node/NodeImplementationFactory.java | 36 + .../node/impl/NodeImplementationFactoryImpl.java | 39 + .../node/impl/NodeImplementationImpl.java | 95 ++ ...a.implementation.node.NodeImplementationFactory | 19 + .../modules/implementation-notification/DISCLAIMER | 8 + .../modules/implementation-notification/LICENSE | 205 ++++ .../modules/implementation-notification/NOTICE | 6 + .../modules/implementation-notification/pom.xml | 96 ++ .../DefaultNotificationImplementationFactory.java | 33 + .../notification/ImmutableMessage.java | 90 ++ .../notification/NotificationComponentInvoker.java | 112 ++ .../NotificationImplementationFactory.java | 27 + .../NotificationImplementationImpl.java | 96 ++ .../NotificationImplementationProcessor.java | 103 ++ .../NotificationImplementationProvider.java | 67 ++ .../NotificationImplementationProviderFactory.java | 38 + .../notification/NotificationModuleActivator.java | 49 + .../org.apache.tuscany.sca.core.ModuleActivator | 19 + .../NotificationComponentTestCase.java | 137 +++ .../NotificationImplementationLoaderTestCase.java | 58 + ...afficAdvisoryNotificationTestCase.componentType | 30 + .../modules/implementation-osgi/DISCLAIMER | 8 + .../1.0-RC1b/modules/implementation-osgi/LICENSE | 203 ++++ .../1.0-RC1b/modules/implementation-osgi/NOTICE | 11 + .../1.0-RC1b/modules/implementation-osgi/pom.xml | 143 +++ .../osgi/OSGiImplementationInterface.java | 44 + .../osgi/context/OSGiAnnotations.java | 315 +++++ .../osgi/context/OSGiPropertyInjector.java | 289 +++++ .../context/OSGiPropertyValueObjectFactory.java | 225 ++++ .../invocation/OSGiImplementationProvider.java | 1196 +++++++++++++++++++ .../OSGiImplementationProviderFactory.java | 95 ++ .../osgi/invocation/OSGiInstanceWrapper.java | 285 +++++ .../osgi/invocation/OSGiRemotableInvoker.java | 131 +++ .../osgi/invocation/OSGiTargetInvoker.java | 202 ++++ .../osgi/runtime/EquinoxRuntime.java | 0 .../implementation/osgi/runtime/FelixRuntime.java | 0 .../osgi/runtime/KnopflerfishRuntime.java | 0 .../implementation/osgi/runtime/OSGiRuntime.java | 0 .../osgi/xml/OSGiImplementation.java | 158 +++ .../osgi/xml/OSGiImplementationProcessor.java | 508 ++++++++ ...ca.contribution.processor.StAXArtifactProcessor | 19 + ...cany.sca.provider.ImplementationProviderFactory | 19 + .../osgi/invocation/OSGiPropertyTestCase.java | 48 + .../osgi/invocation/OSGiTestCase.java | 73 ++ .../osgi/runtime/OSGiRuntimeTestCase.java | 0 .../implementation/osgi/test/OSGiTestBundles.java | 110 ++ .../sca/implementation/osgi/test/OSGiTestImpl.java | 50 + .../osgi/test/OSGiTestInterface.java | 31 + .../osgi/test/OSGiTestWithPropertyImpl.java | 65 ++ .../osgi/xml/OSGiReadImplTestCase.java | 158 +++ .../implementation/osgi/xml/TestModelResolver.java | 104 ++ .../test/resources/OSGiTestService.componentType | 28 + .../src/test/resources/osgiproptest.composite | 37 + .../src/test/resources/osgitest.composite | 36 + .../modules/implementation-resource/DISCLAIMER | 8 + .../modules/implementation-resource/LICENSE | 205 ++++ .../modules/implementation-resource/NOTICE | 6 + .../modules/implementation-resource/pom.xml | 67 ++ .../sca/implementation/resource/Resource.java | 38 + .../resource/ResourceImplementation.java | 39 + .../resource/ResourceImplementationFactory.java | 35 + .../impl/ResourceImplementationFactoryImpl.java | 47 + .../resource/impl/ResourceImplementationImpl.java | 128 ++ .../impl/ResourceImplementationProcessor.java | 118 ++ .../provider/ResourceImplementationInvoker.java | 43 + .../provider/ResourceImplementationProvider.java | 57 + .../ResourceImplementationProviderFactory.java | 45 + ...ca.contribution.processor.StAXArtifactProcessor | 19 + ...entation.resource.ResourceImplementationFactory | 19 + ...cany.sca.provider.ImplementationProviderFactory | 19 + .../resource/ResourceImplementationTestCase.java | 51 + .../src/test/resources/content/test.html | 21 + .../src/test/resources/resource.composite | 30 + .../modules/implementation-script/DISCLAIMER | 8 + .../1.0-RC1b/modules/implementation-script/LICENSE | 251 ++++ .../1.0-RC1b/modules/implementation-script/NOTICE | 17 + .../1.0-RC1b/modules/implementation-script/pom.xml | 144 +++ .../script/ScriptImplementation.java | 69 ++ .../script/ScriptImplementationActivator.java | 45 + .../sca/implementation/script/ScriptInvoker.java | 82 ++ .../script/ScriptInvokerFactory.java | 147 +++ .../script/engines/TuscanyJRubyScriptEngine.java | 454 ++++++++ ...ny.sca.extension.helper.ImplementationActivator | 18 + .../script/itests/AbstractSCATestCase.java | 50 + .../itests/dynamic/AbstractHelloWorldTestCase.java | 34 + .../script/itests/dynamic/HelloWorld.java | 27 + .../dynamic/JavaScriptDynamicRefTestCase.java | 25 + .../dynamic/JavaScriptHelloWorldTestCase.java | 30 + .../helloworld/AbstractHelloWorldTestCase.java | 34 + .../helloworld/GroovyHelloWorldTestCase.java | 25 + .../script/itests/helloworld/HelloWorld.java | 26 + .../script/itests/helloworld/HelloWorldProxy.java | 33 + .../itests/helloworld/JRubyHelloWorldTestCase.java | 25 + .../JavaScripInlineHelloWorldTestCase.java | 25 + .../helloworld/JavaScriptHelloWorldTestCase.java | 25 + .../helloworld/JythonHelloWorldTestCase.java | 25 + .../properties/AbstractHelloWorldTestCase.java | 34 + .../properties/GroovyHelloWorldTestCase.java | 25 + .../script/itests/properties/HelloWorld.java | 26 + .../script/itests/properties/HelloWorldProxy.java | 33 + .../itests/properties/JRubyHelloWorldTestCase.java | 24 + .../properties/JavaScriptHelloWorldTestCase.java | 25 + .../properties/JythonHelloWorldTestCase.java | 25 + .../itests/references/GroovyReferenceTestCase.java | 25 + .../script/itests/references/HelloWorldTarget.java | 30 + .../itests/references/JRubyReferenceTestCase.java | 25 + .../references/JavaScriptReferenceTestCase.java | 25 + .../itests/references/JythonReferenceTestCase.java | 25 + .../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/.ruleset | 190 +++ .../modules/implementation-spring/DISCLAIMER | 8 + .../1.0-RC1b/modules/implementation-spring/LICENSE | 205 ++++ .../1.0-RC1b/modules/implementation-spring/NOTICE | 6 + .../1.0-RC1b/modules/implementation-spring/pom.xml | 107 ++ .../spring/SCAApplicationContext.java | 53 + .../spring/SCANamespaceHandlerResolver.java | 53 + .../spring/SCAParentApplicationContext.java | 262 +++++ .../implementation/spring/ScaNamespaceHandler.java | 39 + .../spring/ScaPropertyBeanDefinitionParser.java | 36 + .../spring/ScaReferenceBeanDefinitionParser.java | 38 + .../spring/ScaServiceBeanDefinitionParser.java | 38 + .../spring/SpringBeanNotFoundException.java | 32 + .../spring/SpringImplementation.java | 149 +++ .../spring/SpringImplementationProcessor.java | 189 +++ .../spring/SpringImplementationProvider.java | 87 ++ .../SpringImplementationProviderFactory.java | 76 ++ .../spring/SpringInvocationException.java | 32 + .../sca/implementation/spring/SpringInvoker.java | 125 ++ .../spring/SpringOperationNotFoundException.java | 32 + .../spring/SpringPropertyValueObjectFactory.java | 45 + .../spring/xml/SpringBeanElement.java | 58 + .../spring/xml/SpringBeanIntrospector.java | 140 +++ .../spring/xml/SpringPropertyElement.java | 45 + .../spring/xml/SpringSCAPropertyElement.java | 44 + .../spring/xml/SpringSCAReferenceElement.java | 46 + .../spring/xml/SpringSCAServiceElement.java | 52 + .../spring/xml/SpringXMLComponentTypeLoader.java | 563 +++++++++ ...ca.contribution.processor.StAXArtifactProcessor | 19 + ...cany.sca.provider.ImplementationProviderFactory | 19 + .../src/main/resources/META-INF/spring.handlers | 3 + .../src/main/resources/META-INF/spring.schemas | 1 + .../org/springframework/sca/xml/spring-sca.xsd | 99 ++ .../spring/itests/AbstractSCATestCase.java | 51 + .../helloworld/AbstractHelloWorldTestCase.java | 41 + .../spring/itests/helloworld/HelloWorld.java | 34 + .../spring/itests/helloworld/HelloWorldImpl.java | 37 + .../spring/itests/helloworld/HelloWorldProxy.java | 41 + .../SpringExplicitHelloWorldTestCase.java | 33 + .../SpringExplicitReferenceTestCase.java | 38 + .../helloworld/SpringHelloWorldTestCase.java | 31 + .../SpringImplicitReferenceTestCase.java | 41 + .../helloworld/SpringSCAPropertyTestCase.java | 38 + .../spring/itests/mock/TestBean.java | 31 + .../spring/itests/mock/TestBeanImpl.java | 42 + .../spring/itests/mock/TestHelloWorldBean.java | 38 + .../spring/itests/mock/TestReference.java | 27 + .../spring/itests/mock/TestReferenceBean.java | 56 + .../spring/itests/mock/TestSCAPropertyBean.java | 54 + .../sca/SpringExplicitHelloWorld-context.xml | 39 + .../sca/SpringExplicitReference-context.xml | 33 + .../META-INF/sca/SpringHelloWorld-context.xml | 31 + .../sca/SpringImplicitReference-context.xml | 34 + .../META-INF/sca/SpringSCAProperty-context.xml | 34 + .../META-INF/sca/testReferenceContext.xml | 33 + .../resources/META-INF/sca/testServiceContext.xml | 31 + .../helloworld/SpringExplicitHelloWorld.composite | 33 + .../helloworld/SpringExplicitReference.composite | 32 + .../itests/helloworld/SpringHelloWorld.composite | 32 + .../helloworld/SpringImplicitReference.composite | 39 + .../itests/helloworld/SpringSCAProperty.composite | 39 + .../src/test/resources/test.xml | 27 + .../modules/implementation-xquery/LICENSE.txt | 202 ++++ .../modules/implementation-xquery/NOTICE.txt | 14 + .../1.0-RC1b/modules/implementation-xquery/pom.xml | 79 ++ .../xquery/XQueryImplementation.java | 71 ++ .../xquery/XQueryImplementationFactory.java | 32 + .../xquery/XQueryImplementationProvider.java | 166 +++ .../XQueryImplementationProviderFactory.java | 47 + .../xquery/XQueryInvokationException.java | 33 + .../sca/implementation/xquery/XQueryInvoker.java | 302 +++++ .../xquery/XQueryModuleActivator.java | 84 ++ .../impl/XQueryImplementationFactoryImpl.java | 35 + .../xquery/impl/XQueryImplementationImpl.java | 93 ++ .../xquery/xml/XQueryImplementationProcessor.java | 122 ++ .../xquery/xml/XQueryIntrospector.java | 304 +++++ .../org.apache.tuscany.sca.core.ModuleActivator | 18 + .../modules/interface-java-xml/.checkstyle | 24 + .../sca/1.0-RC1b/modules/interface-java-xml/.pmd | 20 + .../1.0-RC1b/modules/interface-java-xml/.ruleset | 190 +++ .../1.0-RC1b/modules/interface-java-xml/DISCLAIMER | 8 + .../1.0-RC1b/modules/interface-java-xml/LICENSE | 205 ++++ .../sca/1.0-RC1b/modules/interface-java-xml/NOTICE | 6 + .../1.0-RC1b/modules/interface-java-xml/pom.xml | 64 + .../sca/interfacedef/java/xml/JavaConstants.java | 32 + .../java/xml/JavaInterfaceProcessor.java | 150 +++ ...ca.contribution.processor.StAXArtifactProcessor | 19 + .../sca/interfacedef/java/xml/ReadTestCase.java | 127 ++ .../sca/interfacedef/java/xml/WriteTestCase.java | 118 ++ .../sca/interfacedef/java/xml/Calculator.composite | 53 + .../java/xml/CalculatorComponent.constrainingType | 34 + .../java/xml/CalculatorImpl.componentType | 31 + .../1.0-RC1b/modules/interface-java/.checkstyle | 24 + tags/java/sca/1.0-RC1b/modules/interface-java/.pmd | 20 + .../sca/1.0-RC1b/modules/interface-java/.ruleset | 190 +++ .../sca/1.0-RC1b/modules/interface-java/DISCLAIMER | 8 + .../sca/1.0-RC1b/modules/interface-java/LICENSE | 205 ++++ .../sca/1.0-RC1b/modules/interface-java/NOTICE | 6 + .../sca/1.0-RC1b/modules/interface-java/pom.xml | 51 + .../java/DefaultJavaInterfaceFactory.java | 122 ++ .../sca/interfacedef/java/JavaInterface.java | 72 ++ .../interfacedef/java/JavaInterfaceContract.java | 32 + .../interfacedef/java/JavaInterfaceFactory.java | 82 ++ .../java/impl/JavaInterfaceContractImpl.java | 39 + .../java/impl/JavaInterfaceFactoryImpl.java | 71 ++ .../interfacedef/java/impl/JavaInterfaceImpl.java | 101 ++ .../java/impl/JavaInterfaceIntrospectorImpl.java | 148 +++ .../interfacedef/java/impl/JavaInterfaceUtil.java | 130 +++ .../java/introspect/JavaInterfaceVisitor.java | 39 + ...cany.sca.interfacedef.java.JavaInterfaceFactory | 18 + .../java/impl/JavaInterfaceUtilTestCase.java | 115 ++ .../impl/ConversationalIntrospectionTestCase.java | 98 ++ ...JavaInterfaceProcessorRegistryImplTestCase.java | 100 ++ .../modules/interface-wsdl-xml/.checkstyle | 24 + .../sca/1.0-RC1b/modules/interface-wsdl-xml/.pmd | 20 + .../1.0-RC1b/modules/interface-wsdl-xml/.ruleset | 190 +++ .../1.0-RC1b/modules/interface-wsdl-xml/DISCLAIMER | 8 + .../1.0-RC1b/modules/interface-wsdl-xml/LICENSE | 205 ++++ .../sca/1.0-RC1b/modules/interface-wsdl-xml/NOTICE | 6 + .../1.0-RC1b/modules/interface-wsdl-xml/pom.xml | 70 ++ .../sca/interfacedef/wsdl/xml/WSDLConstants.java | 35 + .../wsdl/xml/WSDLDocumentProcessor.java | 183 +++ .../wsdl/xml/WSDLInterfaceProcessor.java | 182 +++ .../interfacedef/wsdl/xml/WSDLModelResolver.java | 350 ++++++ .../interfacedef/wsdl/xml/XMLDocumentHelper.java | 181 +++ .../wsdl/xml/XSDDocumentProcessor.java | 77 ++ .../interfacedef/wsdl/xml/XSDModelResolver.java | 206 ++++ ...ca.contribution.processor.StAXArtifactProcessor | 19 + ...sca.contribution.processor.URLArtifactProcessor | 20 + ...tuscany.sca.contribution.resolver.ModelResolver | 19 + .../wsdl/introspect/TestModelResolver.java | 63 + .../WSDLInterfaceIntrospectorTestCase.java | 97 ++ .../WSDLOperationIntrospectorTestCase.java | 142 +++ .../introspect/WrapperStyleOperationTestCase.java | 96 ++ .../sca/interfacedef/wsdl/xml/ReadTestCase.java | 127 ++ .../wsdl/xml/WSDLDocumentProcessorTestCase.java | 92 ++ .../sca/interfacedef/wsdl/xml/WSDLTestCase.java | 116 ++ .../sca/interfacedef/wsdl/xml/WriteTestCase.java | 117 ++ .../wsdl/xml/XMLDocumentHelperTestCase.java | 53 + .../wsdl/xml/XSDDocumentProcessorTestCase.java | 97 ++ .../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/wsdl/helloworld-interface.wsdl | 64 + .../test/resources/wsdl/helloworld-service.wsdl | 49 + .../src/test/resources/xsd/greeting.xsd | 29 + .../src/test/resources/xsd/name.xsd | 29 + .../1.0-RC1b/modules/interface-wsdl/.checkstyle | 24 + tags/java/sca/1.0-RC1b/modules/interface-wsdl/.pmd | 20 + .../sca/1.0-RC1b/modules/interface-wsdl/.ruleset | 190 +++ .../sca/1.0-RC1b/modules/interface-wsdl/DISCLAIMER | 8 + .../sca/1.0-RC1b/modules/interface-wsdl/LICENSE | 205 ++++ .../sca/1.0-RC1b/modules/interface-wsdl/NOTICE | 6 + .../sca/1.0-RC1b/modules/interface-wsdl/pom.xml | 72 ++ .../sca/interfacedef/wsdl/DefaultWSDLFactory.java | 30 + .../sca/interfacedef/wsdl/WSDLDefinition.java | 75 ++ .../tuscany/sca/interfacedef/wsdl/WSDLFactory.java | 78 ++ .../sca/interfacedef/wsdl/WSDLInterface.java | 67 ++ .../interfacedef/wsdl/WSDLInterfaceContract.java | 43 + .../sca/interfacedef/wsdl/XSDefinition.java | 60 + .../wsdl/impl/InvalidWSDLException.java | 35 + .../interfacedef/wsdl/impl/WSDLDefinitionImpl.java | 131 +++ .../interfacedef/wsdl/impl/WSDLFactoryImpl.java | 71 ++ .../wsdl/impl/WSDLInterfaceContractImpl.java | 47 + .../interfacedef/wsdl/impl/WSDLInterfaceImpl.java | 99 ++ .../wsdl/impl/WSDLInterfaceIntrospectorImpl.java | 62 + .../wsdl/impl/WSDLOperationIntrospectorImpl.java | 557 +++++++++ .../interfacedef/wsdl/impl/XSDefinitionImpl.java | 89 ++ ...pache.tuscany.sca.interfacedef.wsdl.WSDLFactory | 18 + .../sca/1.0-RC1b/modules/interface/.checkstyle | 24 + tags/java/sca/1.0-RC1b/modules/interface/.pmd | 20 + tags/java/sca/1.0-RC1b/modules/interface/.ruleset | 190 +++ .../java/sca/1.0-RC1b/modules/interface/DISCLAIMER | 8 + tags/java/sca/1.0-RC1b/modules/interface/LICENSE | 205 ++++ tags/java/sca/1.0-RC1b/modules/interface/NOTICE | 6 + tags/java/sca/1.0-RC1b/modules/interface/pom.xml | 38 + .../sca/interfacedef/ConversationSequence.java | 24 + .../apache/tuscany/sca/interfacedef/DataType.java | 89 ++ .../IncompatibleInterfaceContractException.java | 69 ++ .../apache/tuscany/sca/interfacedef/Interface.java | 84 ++ .../sca/interfacedef/InterfaceContract.java | 81 ++ .../sca/interfacedef/InterfaceContractMapper.java | 115 ++ .../sca/interfacedef/InvalidCallbackException.java | 34 + .../interfacedef/InvalidInterfaceException.java | 40 + .../interfacedef/InvalidOperationException.java | 42 + .../apache/tuscany/sca/interfacedef/Operation.java | 179 +++ .../interfacedef/OverloadedOperationException.java | 42 + .../sca/interfacedef/impl/DataTypeImpl.java | 189 +++ .../interfacedef/impl/InterfaceContractImpl.java | 128 ++ .../impl/InterfaceContractMapperImpl.java | 291 +++++ .../sca/interfacedef/impl/InterfaceImpl.java | 215 ++++ .../sca/interfacedef/impl/OperationImpl.java | 316 +++++ .../tuscany/sca/interfacedef/util/ElementInfo.java | 61 + .../sca/interfacedef/util/FaultException.java | 82 ++ .../sca/interfacedef/util/JavaXMLMapper.java | 115 ++ .../tuscany/sca/interfacedef/util/TypeInfo.java | 73 ++ .../tuscany/sca/interfacedef/util/WrapperInfo.java | 140 +++ .../tuscany/sca/interfacedef/util/XMLType.java | 124 ++ .../impl/ContractCompatibilityTestCase.java | 365 ++++++ .../impl/InterfaceContractTestCase.java | 72 ++ .../java/sca/1.0-RC1b/modules/java2wsdl/DISCLAIMER | 8 + tags/java/sca/1.0-RC1b/modules/java2wsdl/LICENSE | 205 ++++ tags/java/sca/1.0-RC1b/modules/java2wsdl/NOTICE | 6 + tags/java/sca/1.0-RC1b/modules/java2wsdl/pom.xml | 209 ++++ .../java2wsdl/generate/GenerationParameters.java | 423 +++++++ .../tools/java2wsdl/generate/Java2WSDL.java | 82 ++ .../java2wsdl/generate/Java2WSDLGenerator.java | 46 + .../generate/Java2WSDLGeneratorFactory.java | 89 ++ .../java2wsdl/generate/Java2WSDLGeneratorImpl.java | 244 ++++ .../tools/java2wsdl/generate/SchemaBuilder.java | 608 ++++++++++ .../java2wsdl/generate/TuscanyJava2OMBuilder.java | 428 +++++++ .../generate/TuscanyJava2WSDLBuilder.java | 81 ++ .../generate/TuscanyJava2WSDLConstants.java | 56 + .../generate/TuscanyJava2WSDLOptionsValidator.java | 73 ++ .../java2wsdl/generate/TuscanySchemaGenerator.java | 348 ++++++ .../tools/java2wsdl/generate/TuscanyTypeTable.java | 220 ++++ .../generate/TuscanyWSDLTypesGenerator.java | 375 ++++++ .../tools/java2wsdl/generate/WSDLGenEvent.java | 42 + .../tools/java2wsdl/generate/WSDLGenListener.java | 39 + .../tuscany/tools/java2wsdl/util/XMLNameUtil.java | 143 +++ .../src/main/resources/META-INF/LICENSE.txt | 202 ++++ .../tools/java2wsdl/generate/CustomerValue.java | 41 + .../java2wsdl/generate/CustomerWithAccount.java | 49 + .../generate/TuscanyJava2WSDLTestCase.java | 100 ++ .../tools/java2wsdl/generate/account/Account.java | 53 + .../java2wsdl/generate/customer/Customer.java | 29 + .../java2wsdl/generate/extra/GoldCustomer.java | 33 + .../java/org/soapinterop/CreditScoreDocLit.java | 24 + .../src/test/resources/AccountService.wsdl | 242 ++++ .../src/test/resources/CreditScoreDocLit.wsdl | 76 ++ .../java2wsdl/src/test/resources/helloworld.wsdl | 121 ++ .../java2wsdl/src/test/resources/interopdoc.wsdl | 180 +++ .../java2wsdl/src/test/resources/sequences.xsd | 100 ++ .../1.0-RC1b/modules/maven-java2wsdl/DISCLAIMER | 8 + .../sca/1.0-RC1b/modules/maven-java2wsdl/LICENSE | 205 ++++ .../sca/1.0-RC1b/modules/maven-java2wsdl/NOTICE | 6 + .../sca/1.0-RC1b/modules/maven-java2wsdl/pom.xml | 45 + .../java2wsdl/plugin/Java2WSDLGeneratorMojo.java | 153 +++ .../1.0-RC1b/modules/maven-wsdl2java/DISCLAIMER | 8 + .../sca/1.0-RC1b/modules/maven-wsdl2java/LICENSE | 205 ++++ .../sca/1.0-RC1b/modules/maven-wsdl2java/NOTICE | 6 + .../sca/1.0-RC1b/modules/maven-wsdl2java/pom.xml | 45 + .../wsdl2java/plugin/WSDL2JavaGeneratorMojo.java | 152 +++ .../tools/wsdl2java/plugin/WSDLFileOption.java | 92 ++ tags/java/sca/1.0-RC1b/modules/node-api/DISCLAIMER | 8 + tags/java/sca/1.0-RC1b/modules/node-api/LICENSE | 205 ++++ tags/java/sca/1.0-RC1b/modules/node-api/NOTICE | 6 + tags/java/sca/1.0-RC1b/modules/node-api/pom.xml | 66 ++ .../org/apache/tuscany/sca/node/ComponentInfo.java | 57 + .../apache/tuscany/sca/node/ComponentListener.java | 47 + .../apache/tuscany/sca/node/ComponentManager.java | 85 ++ .../tuscany/sca/node/ComponentManagerService.java | 66 ++ .../apache/tuscany/sca/node/CompositeManager.java | 50 + .../tuscany/sca/node/ContributionManager.java | 72 ++ .../org/apache/tuscany/sca/node/SCADomain.java | 112 ++ .../java/org/apache/tuscany/sca/node/SCANode.java | 100 ++ .../java/sca/1.0-RC1b/modules/node-impl/DISCLAIMER | 8 + tags/java/sca/1.0-RC1b/modules/node-impl/LICENSE | 205 ++++ tags/java/sca/1.0-RC1b/modules/node-impl/NOTICE | 6 + tags/java/sca/1.0-RC1b/modules/node-impl/pom.xml | 134 +++ .../tuscany/sca/node/impl/ComponentInfoImpl.java | 47 + .../sca/node/impl/ComponentManagerServiceImpl.java | 111 ++ .../sca/node/impl/ContributionManagerImpl.java | 332 ++++++ .../sca/node/impl/DomainManagerServiceImpl.java | 85 ++ .../tuscany/sca/node/impl/NodeFactoryImpl.java | 48 + .../sca/node/impl/NodeManagerServiceImpl.java | 84 ++ .../sca/node/impl/SCADomainServiceImpl.java | 158 +++ .../apache/tuscany/sca/node/impl/SCANodeImpl.java | 551 +++++++++ .../apache/tuscany/sca/node/impl/SCANodeUtil.java | 456 ++++++++ .../src/test/java/calculator/AddService.java | 31 + .../src/test/java/calculator/AddServiceImpl.java | 31 + .../test/java/calculator/CalculatorService.java | 35 + .../java/calculator/CalculatorServiceImpl.java | 74 ++ .../src/test/java/calculator/DivideService.java | 28 + .../test/java/calculator/DivideServiceImpl.java | 30 + .../src/test/java/calculator/MultiplyService.java | 28 + .../test/java/calculator/MultiplyServiceImpl.java | 30 + .../src/test/java/calculator/SubtractService.java | 31 + .../test/java/calculator/SubtractServiceImpl.java | 31 + .../tuscany/sca/node/impl/InMemoryTestCase.java | 102 ++ .../src/test/resources/nodeA/Calculator.composite | 41 + .../resources/nodeA/META-INF/sca-contribution.xml | 24 + .../src/test/resources/nodeA/wsdl/add.wsdl | 88 ++ .../src/test/resources/nodeA/wsdl/multiply.wsdl | 81 ++ .../src/test/resources/nodeA/wsdl/subtract.wsdl | 87 ++ .../src/test/resources/nodeB/Calculator.composite | 45 + .../resources/nodeB/META-INF/sca-contribution.xml | 24 + .../src/test/resources/nodeC/Calculator.composite | 32 + .../resources/nodeC/META-INF/sca-contribution.xml | 24 + tags/java/sca/1.0-RC1b/modules/node/DISCLAIMER | 8 + tags/java/sca/1.0-RC1b/modules/node/LICENSE | 205 ++++ tags/java/sca/1.0-RC1b/modules/node/NOTICE | 6 + tags/java/sca/1.0-RC1b/modules/node/pom.xml | 72 ++ .../org/apache/tuscany/sca/node/ComponentInfo.java | 57 + .../apache/tuscany/sca/node/ComponentListener.java | 47 + .../apache/tuscany/sca/node/ComponentManager.java | 85 ++ .../tuscany/sca/node/ComponentManagerService.java | 66 ++ .../apache/tuscany/sca/node/CompositeManager.java | 85 ++ .../tuscany/sca/node/ContributionManager.java | 55 + .../org/apache/tuscany/sca/node/NodeFactory.java | 38 + .../tuscany/sca/node/NodeManagerInitService.java | 38 + .../tuscany/sca/node/NodeManagerService.java | 49 + .../java/org/apache/tuscany/sca/node/SCANode.java | 126 ++ .../main/resources/META-INF/sca-contribution.xml | 24 + .../modules/node/src/main/resources/node.composite | 72 ++ .../node/src/main/resources/webroot/index.html | 69 ++ .../node/src/main/resources/webroot/node.png | Bin 0 -> 296 bytes .../node/src/main/resources/webroot/style.css | 176 +++ .../sca/1.0-RC1b/modules/osgi-runtime/DISCLAIMER | 8 + .../java/sca/1.0-RC1b/modules/osgi-runtime/LICENSE | 203 ++++ tags/java/sca/1.0-RC1b/modules/osgi-runtime/NOTICE | 11 + .../java/sca/1.0-RC1b/modules/osgi-runtime/pom.xml | 58 + .../tuscany/sca/osgi/runtime/EquinoxRuntime.java | 106 ++ .../tuscany/sca/osgi/runtime/FelixRuntime.java | 193 ++++ .../sca/osgi/runtime/KnopflerfishRuntime.java | 156 +++ .../tuscany/sca/osgi/runtime/OSGiRuntime.java | 170 +++ .../sca/osgi/runtime/OSGiRuntimeTestCase.java | 58 + .../1.0-RC1b/modules/policy-security/DISCLAIMER | 8 + .../sca/1.0-RC1b/modules/policy-security/LICENSE | 205 ++++ .../sca/1.0-RC1b/modules/policy-security/NOTICE | 6 + .../sca/1.0-RC1b/modules/policy-security/pom.xml | 63 + .../policy/security/ws/Axis2ConfigParamPolicy.java | 38 + .../ws/Axis2ConfigParamPolicyProcessor.java | 154 +++ ...ca.contribution.processor.StAXArtifactProcessor | 19 + .../src/main/resources/policy_definitions.xml | 222 ++++ .../sca/policy/security/ws/PolicyReadTestCase.java | 40 + .../sca/policy/security/ws/mock_policies.xml | 36 + .../sca/1.0-RC1b/modules/policy-xml/DISCLAIMER | 8 + tags/java/sca/1.0-RC1b/modules/policy-xml/LICENSE | 205 ++++ tags/java/sca/1.0-RC1b/modules/policy-xml/NOTICE | 6 + tags/java/sca/1.0-RC1b/modules/policy-xml/pom.xml | 95 ++ .../sca/policy/xml/BindingTypeProcessor.java | 41 + .../policy/xml/ImplementationTypeProcessor.java | 41 + .../policy/xml/IntentAttachPointTypeProcessor.java | 224 ++++ .../tuscany/sca/policy/xml/PolicyConstants.java | 75 ++ .../sca/policy/xml/PolicyIntentProcessor.java | 303 +++++ .../tuscany/sca/policy/xml/PolicySetProcessor.java | 430 +++++++ .../sca/policy/xml/ProfileIntentProcessor.java | 39 + .../sca/policy/xml/QualifiedIntentProcessor.java | 39 + .../sca/policy/xml/SimpleIntentProcessor.java | 39 + ...ca.contribution.processor.StAXArtifactProcessor | 22 + .../sca/policy/xml/MockPolicyProcessor.java | 74 ++ .../org/apache/tuscany/sca/policy/xml/Policy.java | 32 + .../sca/policy/xml/ReadDocumentTestCase.java | 243 ++++ .../tuscany/sca/policy/xml/TestModelResolver.java | 63 + .../tuscany/sca/policy/xml/test_definitions.xml | 220 ++++ tags/java/sca/1.0-RC1b/modules/policy/DISCLAIMER | 8 + tags/java/sca/1.0-RC1b/modules/policy/LICENSE | 205 ++++ tags/java/sca/1.0-RC1b/modules/policy/NOTICE | 6 + tags/java/sca/1.0-RC1b/modules/policy/pom.xml | 30 + .../DefaultIntentAttachPointTypeFactory.java | 27 + .../tuscany/sca/policy/DefaultPolicyFactory.java | 30 + .../java/org/apache/tuscany/sca/policy/Intent.java | 107 ++ .../tuscany/sca/policy/IntentAttachPoint.java | 49 + .../tuscany/sca/policy/IntentAttachPointType.java | 69 ++ .../sca/policy/IntentAttachPointTypeFactory.java | 42 + .../org/apache/tuscany/sca/policy/IntentMap.java | 87 ++ .../java/org/apache/tuscany/sca/policy/Policy.java | 32 + .../apache/tuscany/sca/policy/PolicyFactory.java | 67 ++ .../org/apache/tuscany/sca/policy/PolicySet.java | 125 ++ .../tuscany/sca/policy/PolicySetAttachPoint.java | 37 + .../tuscany/sca/policy/PolicySetReference.java | 42 + .../apache/tuscany/sca/policy/ProfileIntent.java | 35 + .../apache/tuscany/sca/policy/QualifiedIntent.java | 40 + .../tuscany/sca/policy/impl/BindingTypeImpl.java | 63 + .../sca/policy/impl/ImplementationTypeImpl.java | 62 + .../impl/IntentAttachPointTypeFactoryImpl.java | 39 + .../apache/tuscany/sca/policy/impl/IntentImpl.java | 146 +++ .../tuscany/sca/policy/impl/IntentMapImpl.java | 73 ++ .../tuscany/sca/policy/impl/PolicyFactoryImpl.java | 60 + .../tuscany/sca/policy/impl/PolicySetImpl.java | 119 ++ .../sca/policy/impl/PolicySetReferenceImpl.java | 47 + .../tuscany/sca/policy/impl/ProfileIntentImpl.java | 38 + .../sca/policy/impl/QualifiedIntentImpl.java | 49 + ...tuscany.sca.policy.IntentAttachPointTypeFactory | 18 + .../org.apache.tuscany.sca.policy.PolicyFactory | 18 + .../tuscany/sca/policy/PolicyFactoryTestCase.java | 55 + tags/java/sca/1.0-RC1b/modules/pom.xml | 150 +++ tags/java/sca/1.0-RC1b/modules/sca-api/DISCLAIMER | 8 + tags/java/sca/1.0-RC1b/modules/sca-api/LICENSE | 205 ++++ tags/java/sca/1.0-RC1b/modules/sca-api/NOTICE | 6 + tags/java/sca/1.0-RC1b/modules/sca-api/pom.xml | 59 + .../main/java/org/osoa/sca/CallableReference.java | 65 ++ .../main/java/org/osoa/sca/ComponentContext.java | 109 ++ .../src/main/java/org/osoa/sca/Constants.java | 34 + .../src/main/java/org/osoa/sca/Conversation.java | 41 + .../org/osoa/sca/ConversationEndedException.java | 67 ++ .../osoa/sca/NoRegisteredCallbackException.java | 68 ++ .../src/main/java/org/osoa/sca/RequestContext.java | 66 ++ .../main/java/org/osoa/sca/ServiceReference.java | 65 ++ .../java/org/osoa/sca/ServiceRuntimeException.java | 69 ++ .../org/osoa/sca/ServiceUnavailableException.java | 65 ++ .../sca/annotations/AllowsPassByReference.java | 39 + .../org/osoa/sca/annotations/Authentication.java | 69 ++ .../java/org/osoa/sca/annotations/Callback.java | 50 + .../org/osoa/sca/annotations/ComponentName.java | 36 + .../org/osoa/sca/annotations/Confidentiality.java | 69 ++ .../java/org/osoa/sca/annotations/Constructor.java | 36 + .../java/org/osoa/sca/annotations/Context.java | 39 + .../sca/annotations/ConversationAttributes.java | 57 + .../org/osoa/sca/annotations/ConversationID.java | 36 + .../org/osoa/sca/annotations/Conversational.java | 38 + .../java/org/osoa/sca/annotations/Destroy.java | 36 + .../java/org/osoa/sca/annotations/EagerInit.java | 36 + .../org/osoa/sca/annotations/EndsConversation.java | 35 + .../main/java/org/osoa/sca/annotations/Init.java | 37 + .../java/org/osoa/sca/annotations/Integrity.java | 69 ++ .../main/java/org/osoa/sca/annotations/Intent.java | 59 + .../main/java/org/osoa/sca/annotations/OneWay.java | 36 + .../java/org/osoa/sca/annotations/PolicySets.java | 46 + .../java/org/osoa/sca/annotations/Property.java | 52 + .../java/org/osoa/sca/annotations/Qualifier.java | 36 + .../java/org/osoa/sca/annotations/Reference.java | 51 + .../java/org/osoa/sca/annotations/Remotable.java | 37 + .../java/org/osoa/sca/annotations/Requires.java | 57 + .../main/java/org/osoa/sca/annotations/Scope.java | 49 + .../java/org/osoa/sca/annotations/Service.java | 48 + .../sca/1.0-RC1b/modules/topology-xml/DISCLAIMER | 8 + .../java/sca/1.0-RC1b/modules/topology-xml/LICENSE | 205 ++++ tags/java/sca/1.0-RC1b/modules/topology-xml/NOTICE | 6 + .../java/sca/1.0-RC1b/modules/topology-xml/pom.xml | 44 + .../xml/BaseTopologyArtifactProcessor.java | 141 +++ .../apache/tuscany/sca/topology/xml/Constants.java | 48 + .../topology/xml/TopologyDocumentProcessor.java | 93 ++ .../sca/topology/xml/TopologyProcessor.java | 176 +++ .../sca/topology/xml/ReadDocumentTestCase.java | 89 ++ .../sca/topology/xml/TestModelResolver.java | 63 + .../tuscany/sca/topology/xml/runtime.topology | 35 + tags/java/sca/1.0-RC1b/modules/topology/DISCLAIMER | 8 + tags/java/sca/1.0-RC1b/modules/topology/LICENSE | 205 ++++ tags/java/sca/1.0-RC1b/modules/topology/NOTICE | 6 + tags/java/sca/1.0-RC1b/modules/topology/pom.xml | 44 + .../org/apache/tuscany/sca/topology/Component.java | 63 + .../sca/topology/DefaultTopologyFactory.java | 31 + .../java/org/apache/tuscany/sca/topology/Node.java | 73 ++ .../org/apache/tuscany/sca/topology/Runtime.java | 48 + .../org/apache/tuscany/sca/topology/Scheme.java | 72 ++ .../tuscany/sca/topology/TopologyFactory.java | 55 + .../tuscany/sca/topology/impl/ComponentImpl.java | 72 ++ .../apache/tuscany/sca/topology/impl/NodeImpl.java | 120 ++ .../tuscany/sca/topology/impl/RuntimeImpl.java | 55 + .../tuscany/sca/topology/impl/SchemeImpl.java | 91 ++ .../sca/topology/impl/TopologyFactoryImpl.java | 50 + .../sca/topology/TopologyFactoryTestCase.java | 105 ++ .../java/sca/1.0-RC1b/modules/wsdl2java/DISCLAIMER | 8 + tags/java/sca/1.0-RC1b/modules/wsdl2java/LICENSE | 205 ++++ tags/java/sca/1.0-RC1b/modules/wsdl2java/NOTICE | 6 + tags/java/sca/1.0-RC1b/modules/wsdl2java/pom.xml | 221 ++++ .../wsdl2java/generate/JavaInterfaceEmitter.java | 267 +++++ .../wsdl2java/generate/JavaInterfaceGenerator.java | 326 ++++++ .../generate/RemotableInterfaceWritter.java | 53 + .../generate/SDODataBindingCodegenExtension.java | 63 + .../generate/SDODataBindingTypeMappingEntry.java | 51 + .../wsdl2java/generate/WSDL2JavaGenerator.java | 529 +++++++++ .../tuscany/tools/wsdl2java/util/XMLNameUtil.java | 143 +++ .../src/main/resources/META-INF/LICENSE.txt | 202 ++++ .../main/resources/RemotableInterfaceTemplate.xsl | 121 ++ .../generate/WSDL2JavaGeneratorTestCase.java | 80 ++ .../java/org/soapinterop/CreditScoreDocLit.java | 25 + .../src/test/resources/AccountService.wsdl | 242 ++++ .../test/resources/AccountServiceWithFault.wsdl | 475 ++++++++ .../src/test/resources/CreditScoreDocLit.wsdl | 76 ++ .../wsdl2java/src/test/resources/helloworld.wsdl | 121 ++ .../wsdl2java/src/test/resources/interopdoc.wsdl | 180 +++ .../wsdl2java/src/test/resources/sequences.xsd | 100 ++ 2263 files changed, 199827 insertions(+) create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-java-dsl/DISCLAIMER create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-java-dsl/LICENSE create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-java-dsl/NOTICE create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-java-dsl/pom.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-java-dsl/src/main/java/org/apache/tuscany/sca/assembly/dsl/AssemblyBuilder.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-java-dsl/src/main/java/org/apache/tuscany/sca/assembly/dsl/ComponentBuilder.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-java-dsl/src/main/java/org/apache/tuscany/sca/assembly/dsl/ComponentPropertyBuilder.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-java-dsl/src/main/java/org/apache/tuscany/sca/assembly/dsl/ComponentReferenceBuilder.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-java-dsl/src/main/java/org/apache/tuscany/sca/assembly/dsl/ComponentServiceBuilder.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-java-dsl/src/main/java/org/apache/tuscany/sca/assembly/dsl/CompositeBuilder.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-java-dsl/src/main/java/org/apache/tuscany/sca/assembly/dsl/impl/AssemblyBuilderImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-java-dsl/src/main/java/org/apache/tuscany/sca/assembly/dsl/impl/ComponentBuilderImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-java-dsl/src/main/java/org/apache/tuscany/sca/assembly/dsl/impl/ComponentPropertyBuilderImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-java-dsl/src/main/java/org/apache/tuscany/sca/assembly/dsl/impl/ComponentReferenceBuilderImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-java-dsl/src/main/java/org/apache/tuscany/sca/assembly/dsl/impl/ComponentServiceBuilderImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-java-dsl/src/main/java/org/apache/tuscany/sca/assembly/dsl/impl/CompositeBuilderImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-java-dsl/src/test/java/org/apache/tuscany/sca/assembly/dsl/AccountDataService.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-java-dsl/src/test/java/org/apache/tuscany/sca/assembly/dsl/AccountDataServiceImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-java-dsl/src/test/java/org/apache/tuscany/sca/assembly/dsl/AccountService.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-java-dsl/src/test/java/org/apache/tuscany/sca/assembly/dsl/AccountServiceImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-java-dsl/src/test/java/org/apache/tuscany/sca/assembly/dsl/BigBankBuilder.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-java-dsl/src/test/java/org/apache/tuscany/sca/assembly/dsl/BigBankBuilderTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-java-dsl/src/test/java/org/apache/tuscany/sca/assembly/dsl/StockQuoteService.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-xml/.checkstyle create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-xml/.pmd create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-xml/.ruleset create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-xml/DISCLAIMER create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-xml/LICENSE create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-xml/NOTICE create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-xml/pom.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/BaseAssemblyProcessor.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ComponentTypeDocumentProcessor.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ComponentTypeModelResolver.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ComponentTypeProcessor.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeDocumentProcessor.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeModelResolver.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeProcessor.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/Constants.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConstrainingTypeDocumentProcessor.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConstrainingTypeModelResolver.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConstrainingTypeProcessor.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/DefaultBeanModelProcessor.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/PolicyAttachPointProcessor.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/BuildPolicyTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/MockPolicyProcessor.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadAllTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadDocumentTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ResolvePolicyTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ResolveTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestModelResolver.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestSCABindingFactoryImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestSCABindingImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/WireTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/WriteAllTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/AnotherDefinitions.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/Calculator.composite create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/CalculatorComponent.constrainingType create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/CalculatorImpl.componentType create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/JavaScriptReference.composite create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/RMIBindingTest.composite create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/TestAllCalculator.composite create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/TestAllDivide.composite create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/TestAllPolicyCalculator.composite create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/definitions.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-xsd/DISCLAIMER create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-xsd/LICENSE create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-xsd/NOTICE create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-xsd/pom.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/sca-binding-ejb.xsd create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/sca-binding-jms.xsd create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/sca-binding-sca.xsd create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/sca-binding-webservice.xsd create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/sca-core.xsd create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/sca-definitions.xsd create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/sca-implementation-bpel.xsd create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/sca-implementation-composite.xsd create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/sca-implementation-cpp.xsd create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/sca-implementation-java.xsd create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/sca-implementation-spring.xsd create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/sca-interface-cpp.xsd create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/sca-interface-java.xsd create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/sca-interface-wsdl.xsd create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/sca-policy.xsd create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/sca.xsd create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-atom.xsd create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-dwr.xsd create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-http.xsd create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-jsonrpc.xsd create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-notification.xsd create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-rmi.xsd create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-rss.xsd create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/tuscany-sca-implementation-node.xsd create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/tuscany-sca-implementation-notification.xsd create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/tuscany-sca-implementation-osgi.xsd create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/tuscany-sca-implementation-resource.xsd create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/tuscany-sca-implementation-script.xsd create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/tuscany-sca-implementation-xquery.xsd create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/tuscany-sca-include.xsd create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/tuscany-sca.xsd create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly/.checkstyle create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly/.pmd create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly/.ruleset create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly/DISCLAIMER create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly/LICENSE create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly/NOTICE create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly/pom.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/AbstractContract.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/AbstractProperty.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/AbstractReference.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/AbstractService.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/AssemblyFactory.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Base.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Binding.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Callback.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Component.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ComponentProperty.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ComponentReference.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ComponentService.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ComponentType.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Composite.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/CompositeReference.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/CompositeService.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ConstrainingType.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Contract.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/DefaultAssemblyFactory.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Extensible.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Implementation.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Multiplicity.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/OptimizableBinding.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Property.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Reference.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/SCABinding.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/SCABindingFactory.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Service.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Wire.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/ComponentPreProcessor.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/CompositeBuilder.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/CompositeBuilderException.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/CompositeBuilderMonitor.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/Problem.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BindingUtil.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBuilderImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeCloneBuilderImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeConfigurationBuilderImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeIncludeBuilderImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeWireBuilderImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/PrintUtil.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ProblemImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/PropertyUtil.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ReferenceUtil.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/AbstractPropertyImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/AbstractReferenceImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/AbstractServiceImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/AssemblyFactoryImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/BaseImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/CallbackImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentPropertyImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentReferenceImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentServiceImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentTypeImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/CompositeImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/CompositeReferenceImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/CompositeServiceImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ConstrainingTypeImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ContractImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ExtensibleImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/PropertyImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ReferenceImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ServiceImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/WireImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly/src/main/resources/META-INF/services/org.apache.tuscany.sca.assembly.AssemblyFactory create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/AssemblyFactoryTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestBinding.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestImplementation.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestInterface.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestInterfaceContract.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestOperation.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBuilderTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/builder/impl/PrintUtilTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-dwr/DISCLAIMER create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-dwr/LICENSE create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-dwr/NOTICE create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-dwr/pom.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRBinding.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRBindingActivator.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRInvoker.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRInvokerFactory.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRService.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRServlet.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-dwr/src/main/resources/META-INF/services/org.apache.tuscany.sca.extension.helper.BindingActivator create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ejb/DISCLAIMER create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ejb/LICENSE create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ejb/NOTICE create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ejb/pom.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/EJBBinding.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/EJBBindingActivator.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/EJBBindingsActivator.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/EJBTargetInvoker.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/corba/ClassLoadingUtil.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/corba/DynamicStubClassLoader.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/corba/Java2IDLUtil.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/corba/ObjectInputStreamExt.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/corba/StubMethodInterceptor.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/corba/UtilInitializer.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/util/EJBHandler.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/util/EJBLocator.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/util/EJBObjectFactory.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/util/EJBStubHelper.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/util/InterfaceInfo.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/util/JavaReflectionAdapter.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/util/MethodInfo.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/util/NamingEndpoint.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ejb/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ejb/src/main/resources/META-INF/services/org.apache.tuscany.sca.extension.helper.BindingActivator create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ejb/src/test/java/account/BankManagerFacade.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ejb/src/test/java/account/Customer.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ejb/src/test/java/account/CustomerImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ejb/src/test/java/calculator/AddService.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ejb/src/test/java/calculator/AddServiceHome.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ejb/src/test/java/org/apache/geronimo/samples/bank/ejb/BankManagerFacade.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ejb/src/test/java/org/apache/geronimo/samples/bank/ejb/BankManagerFacadeHome.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ejb/src/test/java/org/apache/tuscany/sca/binding/ejb/tests/EJBReferenceTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ejb/src/test/java/org/apache/tuscany/sca/binding/ejb/tests/MockServer.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ejb/src/test/java/org/apache/tuscany/sca/binding/ejb/tests/SocketTracer.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ejb/src/test/resources/account/account.composite create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-feed/DISCLAIMER create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-feed/LICENSE create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-feed/NOTICE create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-feed/pom.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/AtomBinding.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/AtomBindingFactory.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/RSSBinding.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/RSSBindingFactory.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/collection/Collection.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/collection/MediaCollection.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/collection/NotFoundException.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/impl/AtomBindingFactoryImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/impl/AtomBindingImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/impl/RSSBindingFactoryImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/impl/RSSBindingImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/AtomBindingInvoker.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/AtomBindingProviderFactory.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/AtomEntryUtil.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/AtomReferenceBindingProvider.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/AtomServiceBindingProvider.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/FeedBindingListenerServlet.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/RSSBindingInvoker.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/RSSBindingProviderFactory.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/RSSReferenceBindingProvider.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/RSSServiceBindingProvider.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-feed/src/main/resources/META-INF/services/org.apache.tuscany.sca.binding.feed.AtomBindingFactory create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-feed/src/main/resources/META-INF/services/org.apache.tuscany.sca.binding.feed.RSSBindingFactory create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-feed/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-feed/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-feed/src/test/java/org/apache/tuscany/sca/binding/feed/Consumer.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-feed/src/test/java/org/apache/tuscany/sca/binding/feed/CustomerClient.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-feed/src/test/java/org/apache/tuscany/sca/binding/feed/CustomerClientImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-feed/src/test/java/org/apache/tuscany/sca/binding/feed/CustomerCollectionImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-feed/src/test/java/org/apache/tuscany/sca/binding/feed/Provider.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-feed/src/test/resources/org/apache/tuscany/sca/binding/feed/Consumer.composite create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-feed/src/test/resources/org/apache/tuscany/sca/binding/feed/Provider.composite create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-http/DISCLAIMER create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-http/LICENSE create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-http/NOTICE create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-http/pom.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-http/src/main/java/org/apache/tuscany/sca/binding/http/HTTPResource.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-http/src/main/java/org/apache/tuscany/sca/binding/http/HTTPResourceBinding.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-http/src/main/java/org/apache/tuscany/sca/binding/http/HTTPResourceBindingFactory.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-http/src/main/java/org/apache/tuscany/sca/binding/http/impl/HTTPResourceBindingFactoryImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-http/src/main/java/org/apache/tuscany/sca/binding/http/impl/HTTPResourceBindingImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-http/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPResourceBindingProviderFactory.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-http/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPResourceServiceBindingProvider.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-http/src/main/resources/META-INF/services/org.apache.tuscany.sca.binding.http.HTTPResourceBindingFactory create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-http/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-http/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-http/src/test/java/org/apache/tuscany/sca/binding/http/HTTPResourceBindingTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-http/src/test/resources/content/test.html create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-http/src/test/resources/resource.composite create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-jsonrpc/DISCLAIMER create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-jsonrpc/LICENSE create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-jsonrpc/NOTICE create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-jsonrpc/pom.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCBinding.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCBindingActivator.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCService.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCServiceServlet.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/JavaToSmd.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/ScaDomainScriptServlet.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-jsonrpc/src/main/resources/META-INF/services/org.apache.tuscany.sca.extension.helper.BindingActivator create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-jsonrpc/src/main/resources/org/apache/tuscany/sca/binding/jsonrpc/jsonrpc.js create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-jsonrpc/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/Echo.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-jsonrpc/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/EchoComponentImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-jsonrpc/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCServiceTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-jsonrpc/src/test/resources/JSONRPCBinding.composite create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-notification/DISCLAIMER create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-notification/LICENSE create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-notification/NOTICE create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-notification/pom.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/DefaultNotificationBindingFactory.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/NotificationBinding.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/NotificationBindingFactory.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/NotificationBindingImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/NotificationBindingModuleActivator.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/NotificationBindingProcessor.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/NotificationBindingProviderFactory.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/NotificationBrokerManager.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/NotificationReferenceBindingInvoker.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/NotificationReferenceBindingProvider.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/NotificationServiceBindingProvider.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/NotificationTypeManager.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/NotificationTypeManagerImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/AbstractBroker.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/AbstractBrokerEnDeCoder.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/AbstractEnDeCoder.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/Broker.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/BrokerConsumerReference.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/BrokerConsumerReferenceEnDeCoder.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/BrokerEnDeCoder.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/BrokerID.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/BrokerIDEnDeCoder.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/BrokerProducerReference.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/BrokerProducerReferenceEnDeCoder.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/Brokers.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/BrokersEnDeCoder.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/ConnectionOverride.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/ConnectionOverrideEnDeCoder.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/ConnectionOverrideResponse.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/ConnectionOverrideResponseEnDeCoder.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/Constants.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/ConsumerReference.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/ConsumerReferenceEnDeCoder.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/DefaultEncodingRegistry.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EnDeCoder.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EncodingException.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EncodingObject.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EncodingRegistry.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EncodingUtils.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EndConsumers.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EndConsumersEnDeCoder.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EndProducers.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EndProducersEnDeCoder.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EndpointAddress.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EndpointAddressEnDeCoder.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EndpointReference.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EndpointReferenceEnDeCoder.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EndpointReferenceSequence.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EndpointReferenceSequenceEnDeCoder.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EndpointReferenceWrapper.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EndpointReferenceWrapperEnDeCoder.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NeighborBrokerConsumers.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NeighborBrokerConsumersEnDeCoder.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/Neighbors.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NeighborsEnDeCoder.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NewBroker.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NewBrokerAck.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NewBrokerAckEnDeCoder.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NewBrokerEnDeCoder.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NewBrokerResponse.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NewBrokerResponseEnDeCoder.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NewConsumer.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NewConsumerEnDeCoder.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NewConsumerResponse.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NewConsumerResponseEnDeCoder.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NewProducer.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NewProducerEnDeCoder.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NewProducerResponse.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NewProducerResponseEnDeCoder.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/ReferenceProperties.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/ReferencePropertiesEnDeCoder.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/RemoveBroker.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/RemoveBrokerEnDeCoder.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/RemovedBroker.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/RemovedBrokerEnDeCoder.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/ReplaceBrokerConnection.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/ReplaceBrokerConnectionEnDeCoder.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/Subscribe.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/SubscribeEnDeCoder.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/util/IOUtils.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/util/NotificationServlet.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/util/URIUtil.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-notification/src/test/java/org/apache/tuscany/sca/binding/notification/encoding/AxiomTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-notification/src/test/java/org/apache/tuscany/sca/binding/notification/encoding/EncodingTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-osgi/DISCLAIMER create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-osgi/LICENSE create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-osgi/NOTICE create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-osgi/pom.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-osgi/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-rmi/.ruleset create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-rmi/DISCLAIMER create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-rmi/LICENSE create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-rmi/NOTICE create mode 100755 tags/java/sca/1.0-RC1b/modules/binding-rmi/pom.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/RMIBinding.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/RMIBindingActivator.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/RMIReferenceInvoker.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/RMIReferenceInvokerFactory.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/RMIService.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-rmi/src/main/resources/META-INF/services/org.apache.tuscany.sca.extension.helper.BindingActivator create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-rmi/src/test/java/helloworld/HelloWorldImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-rmi/src/test/java/helloworld/HelloWorldRmiImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-rmi/src/test/java/helloworld/HelloWorldRmiService.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-rmi/src/test/java/helloworld/HelloWorldService.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-rmi/src/test/java/org/apache/tuscany/sca/binding/rmi/BindingTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-rmi/src/test/resources/HelloWorldImpl.componentType create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-rmi/src/test/resources/HelloWorldRmiImpl.componentType create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-rmi/src/test/resources/RMIBindingTest.composite create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/DISCLAIMER create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/LICENSE create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/NOTICE create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/pom.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/main/java/org/apache/tuscany/sca/binding/sca/axis2/impl/Axis2SCABindingInvoker.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/main/java/org/apache/tuscany/sca/binding/sca/axis2/impl/Axis2SCABindingProviderFactory.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/main/java/org/apache/tuscany/sca/binding/sca/axis2/impl/Axis2SCAReferenceBindingProvider.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/main/java/org/apache/tuscany/sca/binding/sca/axis2/impl/Axis2SCAServiceBindingProvider.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/main/java/org/apache/tuscany/sca/binding/sca/axis2/impl/Axis2SCAServiceProvider.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/AsynchTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/BaseTest.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/CallbackTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/NodeFactoryImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/PromotionTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/SimpleTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/TestDomain.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/TestServiceDiscoveryImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/HelloWorldCallbackRemote.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/HelloWorldClient.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/HelloWorldServiceCallbackOnewayRemote.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/HelloWorldServiceCallbackRemote.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/HelloWorldServiceLocal.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/HelloWorldServiceRemote.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/HelloWorldServiceRemote2.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/impl/HelloWorldClientCallbackOnewayRemoteImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/impl/HelloWorldClientCallbackRemoteImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/impl/HelloWorldClientLocalImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/impl/HelloWorldClientRemote2Impl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/impl/HelloWorldClientRemoteImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/impl/HelloWorldServiceCallbackOnewayRemoteImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/impl/HelloWorldServiceCallbackRemoteImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/impl/HelloWorldServiceLocalImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/impl/HelloWorldServiceMultipleServicesImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/impl/HelloWorldServiceRemoteImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/resources/nodeA/HelloWorld.composite create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/resources/nodeA/META-INF/sca-contribution.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/resources/nodeB/HelloWorld.composite create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/resources/nodeB/META-INF/sca-contribution.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/resources/nodeC/HelloWorld.composite create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/resources/nodeC/HelloWorldComponent.composite create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/resources/nodeC/META-INF/sca-contribution.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/resources/nodeD/HelloWorld.composite create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/resources/nodeD/HelloWorldComponent.composite create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/resources/nodeD/META-INF/sca-contribution.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/resources/nodeE/HelloWorld.composite create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/resources/nodeE/META-INF/sca-contribution.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/resources/nodeF/HelloWorld.composite create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/resources/nodeF/META-INF/sca-contribution.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/resources/nodeG/HelloWorld.composite create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/resources/nodeG/META-INF/sca-contribution.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/resources/nodeH/HelloWorld.composite create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/resources/nodeH/META-INF/sca-contribution.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-sca-xml/DISCLAIMER create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-sca-xml/LICENSE create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-sca-xml/NOTICE create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-sca-xml/pom.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-sca-xml/src/main/java/org/apache/tuscany/sca/binding/sca/xml/SCABindingProcessor.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-sca-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-sca-xml/src/test/java/org/apace/tuscany/sca/binding/sca/xml/ReadTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-sca-xml/src/test/java/org/apace/tuscany/sca/binding/sca/xml/WriteTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-sca-xml/src/test/resources/Calculator.composite create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-sca-xml/src/test/resources/CalculatorServiceImpl.componentType create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-sca/DISCLAIMER create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-sca/LICENSE create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-sca/NOTICE create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-sca/pom.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/DistributedSCABinding.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/DistributedSCABindingImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/RuntimeSCABindingProvider.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/RuntimeSCABindingProviderFactory.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/RuntimeSCAReferenceBindingProvider.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/RuntimeSCAServiceBindingProvider.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/SCABindingFactoryImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/SCABindingImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-sca/src/main/resources/META-INF/services/org.apache.tuscany.sca.assembly.SCABindingFactory create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-sca/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-sca/src/test/java/org/apace/tuscany/sca/binding/sca/SCABindingTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-sca/src/test/resources/Calculator.composite create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/DISCLAIMER create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/LICENSE create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/NOTICE create mode 100755 tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/pom.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2BindingInvoker.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2BindingProviderFactory.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2OneWayBindingInvoker.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ReferenceBindingProvider.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceBindingProvider.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceClient.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceInMessageReceiver.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceInOutSyncMessageReceiver.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceProvider.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceServlet.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Java2WSDLHelper.java create mode 100755 tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/TuscanyAxisConfigurator.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/TuscanyDispatcher.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/TuscanyListingAgent.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory create mode 100755 tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/main/resources/org/apache/tuscany/sca/binding/ws/axis2/engine/config/axis2.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/main/resources/org/apache/tuscany/sca/binding/ws/axis2/engine/config/modules/modules.list create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/main/resources/org/apache/tuscany/sca/binding/ws/axis2/engine/config/modules/rampart-1.3.mar create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/main/resources/org/apache/tuscany/sca/binding/ws/axis2/engine/config/services/services.list create mode 100755 tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ReferenceTestCase.java create mode 100755 tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceTestCase.java create mode 100755 tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/Greeter.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/GreetingCallback.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/Java2WSDLHelperTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/Bar.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/Echo.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/EchoComponent.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/EchoImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/Foo.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/HelloWorld.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/HelloWorldComponent.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/HelloWorldMultiService.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/HelloWorldNoWSDLTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/HelloWorldOM.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/HelloWorldOM2.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/HelloWorldOMComponent.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/HelloWorldOMService.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/HelloWorldOMTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/HelloWorldService.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/HelloWorldTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/HelloWorldWSDLMergedTestCaseFIXME.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/QuestionMarkWSDLTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/endpoints/AbstractHelloWorldOMTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/endpoints/DefaultMultiServiceTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/endpoints/DefaultSingleServiceTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/endpoints/WSDLExplicitURITestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/endpoints/WSDLRelativeURITestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/epr/HelloWorldTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/AbstractHelloWorldOMTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/ClientPWCBHandler.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/IntegrityPWCBHandler.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/ServerPWCBHandler.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/WSSecurityAuthenticationTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/WSSecurityConfidentialityTestCaseFIXBouncyCastleIssue.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/WSSecurityIntegrityTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/soap12/HelloWorldSOAP12TestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/soap12/QuestionMarkWSDLTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/resources/definitions.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/HelloWorld.composite create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/HelloWorldNoWSDL.composite create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/endpoints/DefaultMultiService.composite create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/endpoints/DefaultSingleService.composite create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/endpoints/WSDLExplicitURI.composite create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/endpoints/WSDLRelativeURI.composite create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/endpoints/helloworld-om-relative-uri.wsdl create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/epr/HelloWorld.composite create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/helloworld-om-binding.wsdl create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/helloworld-om-merged.composite create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/helloworld-om-porttype.wsdl create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/helloworld-om-uri.wsdl create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/helloworld-om.composite create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/helloworld-om.wsdl create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/helloworld.wsdl create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/WSSecurityAuthentication.composite create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/WSSecurityConfidentiality.composite create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/WSSecurityIntegrity.composite create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/security.properties create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/tuscanyKeys.jks create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/questionmark-wsdl.composite create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/soap12/HelloWorldSOAP12.composite create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/soap12/questionmark-wsdl.composite create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-xml/.checkstyle create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-xml/.pmd create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-xml/.ruleset create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-xml/DISCLAIMER create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-xml/LICENSE create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-xml/NOTICE create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-xml/pom.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-xml/src/main/java/org/apache/tuscany/sca/binding/ws/xml/EndPointReferenceHelper.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-xml/src/main/java/org/apache/tuscany/sca/binding/ws/xml/WebServiceBindingProcessor.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-xml/src/main/java/org/apache/tuscany/sca/binding/ws/xml/WebServiceConstants.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-xml/src/test/java/org/apache/tuscany/sca/binding/ws/xml/ReadTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-xml/src/test/java/org/apache/tuscany/sca/binding/ws/xml/WriteTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/Calculator.composite create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/CalculatorImpl.componentType create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/example.wsdl create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/invalid-stockquote.wsdl create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/ipo.xsd create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/stockquote.wsdl create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/test1.wsdl create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/test1.xsd create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/test2.wsdl create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/unwrapped-stockquote.wsdl create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws/.checkstyle create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws/.pmd create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws/.ruleset create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws/DISCLAIMER create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws/LICENSE create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws/NOTICE create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws/pom.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/DefaultWebServiceBindingFactory.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/WebServiceBinding.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/WebServiceBindingFactory.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/addressing/EndPointReference.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/impl/WebServiceBindingFactoryImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/impl/WebServiceBindingImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution-impl/.checkstyle create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution-impl/.pmd create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution-impl/.ruleset create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution-impl/DISCLAIMER create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution-impl/LICENSE create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution-impl/NOTICE create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution-impl/pom.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/impl/ArtifactImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/impl/ContributionFactoryImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/impl/ContributionImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/impl/DeployedArtifactImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/FolderContributionProcessor.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/InvalidFolderContributionException.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/InvalidFolderContributionURIException.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/JarContributionProcessor.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/resolver/impl/ModelResolverImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/ArtifactTypeDescriberImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/ContributionMetadataDocumentProcessor.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/ContributionMetadataProcessor.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/ContributionRepositoryImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/ContributionServiceImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/InvalidContributionMetadataException.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/InvalidContributionURIException.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/PackageTypeDescriberImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/util/FileHelper.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/util/IOHelper.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution-impl/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.ContributionFactory create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution-impl/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.PackageProcessor create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/processor/FolderContributionPackageProcessorTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/processor/JarContributionPackageProcessorTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/processor/URLartifactProcessorExtensionPointTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/resolver/ArtifactResolverTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/resolver/ExtensibleArtifactResolverTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/resolver/TestModelResolver.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/services/ContentTypeDescriberImplTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/services/ContributionMetadataDocumentProcessorTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/services/ContributionRepositoryTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/services/PackageTypeDescriberImplTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution-impl/src/test/resources/deployables/sample-calculator.jar create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution-impl/src/test/resources/repository/sample-calculator.jar create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution-impl/src/test/resources/test.composite create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution-impl/src/test/resources/test.ext create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution-java/.checkstyle create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution-java/.pmd create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution-java/.ruleset create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution-java/pom.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/JavaExport.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/JavaImport.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/JavaImportExportFactory.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/ClassReferenceModelResolver.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportProcessor.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportExportFactoryImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportExportListener.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportProcessor.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution-java/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.java.JavaImportExportFactory create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution-java/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution-java/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution-java/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.service.ContributionListener create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution-java/src/test/java/org/apache/tuscany/sca/contribution/java/impl/ClassReferenceArtifactResolverTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution-java/src/test/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportProcessorTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution-java/src/test/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportProcessorTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution-namespace/.checkstyle create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution-namespace/.pmd create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution-namespace/.ruleset create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution-namespace/pom.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/NamespaceExport.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/NamespaceImport.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/NamespaceImportExportFactory.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportProcessor.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportExportFactoryImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportExportListener.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportProcessor.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution-namespace/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.namespace.NamespaceImportExportFactory create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution-namespace/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution-namespace/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution-namespace/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.service.ContributionListener create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution-namespace/src/test/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportProcessorTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution-namespace/src/test/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportProcessorTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution-osgi/.checkstyle create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution-osgi/.pmd create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution-osgi/.ruleset create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution-osgi/pom.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution-osgi/src/main/java/org/apache/tuscany/sca/contribution/osgi/BundleReference.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution-osgi/src/main/java/org/apache/tuscany/sca/contribution/osgi/impl/OSGiBundleProcessor.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution-osgi/src/main/java/org/apache/tuscany/sca/contribution/osgi/impl/OSGiBundleReferenceModelResolver.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution-osgi/src/main/java/org/apache/tuscany/sca/contribution/osgi/impl/OSGiClassReferenceModelResolver.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution-osgi/src/main/java/org/apache/tuscany/sca/contribution/osgi/impl/OSGiImportExportListener.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution-osgi/src/main/java/org/apache/tuscany/sca/contribution/osgi/impl/OSGiModelResolverImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution-osgi/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution-osgi/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.service.ContributionListener create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution/.checkstyle create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution/.pmd create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution/.ruleset create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution/DISCLAIMER create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution/LICENSE create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution/NOTICE create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution/pom.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/Artifact.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/ContentType.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/Contribution.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/ContributionFactory.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/DefaultModelFactoryExtensionPoint.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/DeployedArtifact.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/Export.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/Import.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/ModelFactoryExtensionPoint.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ArtifactProcessor.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ArtifactProcessorExtensionPoint.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/BaseStAXArtifactProcessor.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultArtifactProcessorExtensionPoint.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultPackageProcessorExtensionPoint.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultStAXArtifactProcessorExtensionPoint.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultURLArtifactProcessorExtensionPoint.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensiblePackageProcessor.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleStAXArtifactProcessor.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleURLArtifactProcessor.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/PackageProcessor.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/PackageProcessorExtensionPoint.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/StAXArtifactProcessor.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/StAXArtifactProcessorExtensionPoint.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/URLArtifactProcessor.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/URLArtifactProcessorExtensionPoint.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ValidatingXMLStreamReader.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/ClassReference.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultImportAllModelResolver.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultModelResolverExtensionPoint.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/ExtensibleModelResolver.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/ModelResolver.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/ModelResolverExtensionPoint.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/AbstractContributionException.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionException.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionListener.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionListenerExtensionPoint.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionReadException.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionRepository.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionResolveException.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionRuntimeException.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionService.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionWireException.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionWriteException.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/DefaultContributionListenerExtensionPoint.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ExtensibleContributionListener.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/TypeDescriber.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/UnrecognizedElementException.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/UnsupportedContentTypeException.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/util/ServiceConfigurationUtil.java create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.ContributionPostProcessorExtensionPoint create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.PackageProcessorExtensionPoint create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.URLArtifactProcessorExtensionPoint create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolverExtensionPoint create mode 100644 tags/java/sca/1.0-RC1b/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.service.ContributionListenerExtensionPoint create mode 100644 tags/java/sca/1.0-RC1b/modules/core-databinding/.checkstyle create mode 100644 tags/java/sca/1.0-RC1b/modules/core-databinding/.pmd create mode 100644 tags/java/sca/1.0-RC1b/modules/core-databinding/.ruleset create mode 100644 tags/java/sca/1.0-RC1b/modules/core-databinding/DISCLAIMER create mode 100644 tags/java/sca/1.0-RC1b/modules/core-databinding/LICENSE create mode 100644 tags/java/sca/1.0-RC1b/modules/core-databinding/NOTICE create mode 100644 tags/java/sca/1.0-RC1b/modules/core-databinding/pom.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/module/DataBindingModuleActivator.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/processor/DataBindingJavaInterfaceProcessor.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Exception2ExceptionTransformer.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Input2InputTransformer.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Output2OutputTransformer.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/DataBindingRuntimeWireProcessor.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/DataTransformationInteceptor.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/PassByValueInteceptor.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core-databinding/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator create mode 100644 tags/java/sca/1.0-RC1b/modules/core-databinding/src/test/java/org/apache/tuscany/sca/core/databinding/processor/DataBindingJavaInterfaceProcessorTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core-databinding/src/test/java/org/apache/tuscany/sca/core/databinding/transformers/IDLTransformerTestCase.java.fixme create mode 100644 tags/java/sca/1.0-RC1b/modules/core-spi/.checkstyle create mode 100644 tags/java/sca/1.0-RC1b/modules/core-spi/.pmd create mode 100644 tags/java/sca/1.0-RC1b/modules/core-spi/.ruleset create mode 100644 tags/java/sca/1.0-RC1b/modules/core-spi/DISCLAIMER create mode 100644 tags/java/sca/1.0-RC1b/modules/core-spi/LICENSE create mode 100644 tags/java/sca/1.0-RC1b/modules/core-spi/NOTICE create mode 100644 tags/java/sca/1.0-RC1b/modules/core-spi/pom.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/core-spi/src/doc/Context Model.emx create mode 100644 tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/context/ComponentContextFactory.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/context/ContextFactoryExtensionPoint.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/context/DefaultContextFactoryExtensionPoint.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/context/RequestContextFactory.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/core/DefaultExtensionPointRegistry.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/core/ExtensionPointRegistry.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/core/ModuleActivator.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/event/Event.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/event/EventFilter.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/event/EventPublisher.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/event/RuntimeEventListener.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/event/TrueFilter.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/Interceptor.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/InvocationChain.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/Invoker.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/Message.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/MessageFactory.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/management/ManagementService.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/BindingProviderFactory.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/DefaultProviderFactoryExtensionPoint.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ImplementationProvider.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ImplementationProviderFactory.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ProviderFactory.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ProviderFactoryExtensionPoint.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ReferenceBindingProvider.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ServiceBindingProvider.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/DefaultWireProcessorExtensionPoint.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/EndpointReference.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/ReferenceParameters.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponent.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponentContext.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponentReference.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponentService.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeWire.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeWireProcessor.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeWireProcessorExtensionPoint.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/DuplicateRecordException.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/RecoveryListener.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/Store.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/StoreException.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/StoreExpirationEvent.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/StoreMonitor.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/StoreReadException.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/StoreWriteException.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/work/NotificationListener.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/work/WorkScheduler.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/work/WorkSchedulerException.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core-spi/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.ProviderFactoryExtensionPoint create mode 100644 tags/java/sca/1.0-RC1b/modules/core-spi/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.RuntimeWireProcessorExtensionPoint create mode 100644 tags/java/sca/1.0-RC1b/modules/core-spi/src/main/resources/META-INF/services/org.apache.tuscany.sca.work.WorkScheduler create mode 100644 tags/java/sca/1.0-RC1b/modules/core-spring/DISCLAIMER create mode 100644 tags/java/sca/1.0-RC1b/modules/core-spring/LICENSE create mode 100644 tags/java/sca/1.0-RC1b/modules/core-spring/NOTICE create mode 100644 tags/java/sca/1.0-RC1b/modules/core-spring/pom.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/assembly/impl/BeanAssemblyFactory.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/assembly/impl/BeanComponentImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/assembly/impl/BeanReferenceImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/context/ModelResolverImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/context/SCADomainContext.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/implementation/java/impl/BeanBaseJavaImplementationImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/implementation/java/impl/BeanJavaImplementationFactory.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/implementation/java/impl/BeanJavaImplementationImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/implementation/java/impl/BeanJavaInterfaceContractImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/implementation/java/impl/BeanJavaInterfaceFactory.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/implementation/java/impl/BeanJavaInterfaceImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core-spring/src/test/java/calculator/AddService.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core-spring/src/test/java/calculator/AddServiceImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core-spring/src/test/java/calculator/CalculatorClient.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core-spring/src/test/java/calculator/CalculatorService.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core-spring/src/test/java/calculator/CalculatorServiceImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core-spring/src/test/java/calculator/DivideService.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core-spring/src/test/java/calculator/DivideServiceImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core-spring/src/test/java/calculator/MultiplyService.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core-spring/src/test/java/calculator/MultiplyServiceImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core-spring/src/test/java/calculator/NestedCalculatorClient.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core-spring/src/test/java/calculator/SubtractService.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core-spring/src/test/java/calculator/SubtractServiceImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core-spring/src/test/java/org/apache/tuscany/sca/core/spring/CalculatorTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core-spring/src/test/java/org/apache/tuscany/sca/core/spring/NestedCalculatorTestCaseFIXME.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core-spring/src/test/resources/org/apache/tuscany/sca/core/spring/Calculator.composite create mode 100644 tags/java/sca/1.0-RC1b/modules/core-spring/src/test/resources/org/apache/tuscany/sca/core/spring/InnerCalculator.composite create mode 100644 tags/java/sca/1.0-RC1b/modules/core-spring/src/test/resources/org/apache/tuscany/sca/core/spring/InnerOperations.composite create mode 100644 tags/java/sca/1.0-RC1b/modules/core-spring/src/test/resources/org/apache/tuscany/sca/core/spring/OuterCalculator.composite create mode 100644 tags/java/sca/1.0-RC1b/modules/core/.checkstyle create mode 100644 tags/java/sca/1.0-RC1b/modules/core/.pmd create mode 100644 tags/java/sca/1.0-RC1b/modules/core/.ruleset create mode 100644 tags/java/sca/1.0-RC1b/modules/core/DISCLAIMER create mode 100644 tags/java/sca/1.0-RC1b/modules/core/LICENSE create mode 100644 tags/java/sca/1.0-RC1b/modules/core/NOTICE create mode 100644 tags/java/sca/1.0-RC1b/modules/core/pom.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/ActivationException.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/CompositeActivator.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/CompositeActivatorImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/EndpointReferenceImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/ReferenceParameterProcessor.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/ReferenceParametersImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/RuntimeAssemblyFactory.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/RuntimeComponentImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/RuntimeComponentReferenceImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/RuntimeComponentServiceImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/RuntimeWireImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/context/CallableReferenceImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/context/ComponentContextHelper.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/context/ComponentContextImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/context/DefaultComponentContextFactory.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/context/InstanceWrapper.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/context/RequestContextImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/context/ServiceReferenceImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/conversation/ConversationListener.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/conversation/ConversationManager.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/conversation/ConversationManagerImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/conversation/ConversationState.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/conversation/ExtendedConversation.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/conversation/ExtendedConversationImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/event/BaseEventPublisher.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/event/ComponentStart.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/event/ComponentStop.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/event/ConversationEnd.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/event/ConversationStart.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/event/HttpSessionEnd.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/event/HttpSessionStart.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/event/RequestEnd.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/event/RequestStart.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/factory/ObjectCreationException.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/factory/ObjectFactory.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallableReferenceObjectFactory.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallbackInterfaceInterceptor.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallbackWireObjectFactory.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CglibProxyFactory.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/DefaultProxyFactoryExtensionPoint.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ExtensibleWireProcessor.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/InvocationChainImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/JDKCallbackInvocationHandler.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/JDKInvocationHandler.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/JDKProxyFactory.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/MessageFactoryImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/MessageImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/NoMethodForOperationException.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/NonBlockingInterceptor.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ProxyCreationException.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ProxyFactory.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ProxyFactoryExtensionPoint.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/RuntimeWireInvoker.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/TargetInvocationException.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ThreadMessageContext.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/WireObjectFactory.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/AbstractScopeContainer.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/CompositeScopeContainer.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/CompositeScopeContainerFactory.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ConversationalScopeContainer.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ConversationalScopeContainerFactory.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/HttpSessionScopeContainer.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/HttpSessionScopeContainerFactory.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/RequestScopeContainer.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/RequestScopeContainerFactory.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/Scope.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ScopeContainer.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ScopeContainerFactory.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ScopeRegistry.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ScopeRegistryImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ScopedImplementationProvider.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ScopedRuntimeComponent.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/StatelessScopeContainer.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/StatelessScopeContainerFactory.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/TargetDestructionException.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/TargetInitializationException.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/TargetNotFoundException.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/TargetResolutionException.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/store/MemoryStore.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/work/Jsr237Work.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/work/Jsr237WorkScheduler.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/work/ThreadPoolWorkManager.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/work/WorkEventImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/work/WorkItemImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core/src/test/java/org/apache/tuscany/sca/core/DefaultExtensionPointRegistryTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core/src/test/java/org/apache/tuscany/sca/core/event/BaseEventPublisherTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core/src/test/java/org/apache/tuscany/sca/core/event/EventTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core/src/test/java/org/apache/tuscany/sca/core/scope/AbstractScopeContainerTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core/src/test/java/org/apache/tuscany/sca/core/store/MemoryStoreTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core/src/test/java/org/apache/tuscany/sca/core/wire/CallbackInterfaceInterceptorTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core/src/test/java/org/apache/tuscany/sca/core/wire/InvocationChainImplTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core/src/test/java/org/apache/tuscany/sca/core/wire/NonBlockingInterceptorTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/core/src/test/java/org/apache/tuscany/sca/scope/ScopeTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-axiom/.ruleset create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-axiom/DISCLAIMER create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-axiom/LICENSE create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-axiom/NOTICE create mode 100755 tags/java/sca/1.0-RC1b/modules/databinding-axiom/pom.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/AxiomDataBinding.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/AxiomExceptionHandler.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/AxiomHelper.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/OMElement2Object.java create mode 100755 tags/java/sca/1.0-RC1b/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/OMElement2String.java create mode 100755 tags/java/sca/1.0-RC1b/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/OMElement2XMLStreamReader.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/OMElementWrapperHandler.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/Object2OMElement.java create mode 100755 tags/java/sca/1.0-RC1b/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/String2OMElement.java create mode 100755 tags/java/sca/1.0-RC1b/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/XMLStreamReader2OMElement.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-axiom/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.DataBinding create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-axiom/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-axiom/src/test/java/org/apache/tuscany/sca/databinding/axiom/AxiomExceptionHandlerTestCase.java create mode 100755 tags/java/sca/1.0-RC1b/modules/databinding-axiom/src/test/java/org/apache/tuscany/sca/databinding/axiom/OMElementTestCase.java create mode 100755 tags/java/sca/1.0-RC1b/modules/databinding-axiom/src/test/resources/ipo.xml create mode 100755 tags/java/sca/1.0-RC1b/modules/databinding-axiom/src/test/resources/ipo.xsd create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-axiom/src/test/resources/order.wsdl create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-jaxb/.ruleset create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-jaxb/DISCLAIMER create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-jaxb/LICENSE create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-jaxb/NOTICE create mode 100755 tags/java/sca/1.0-RC1b/modules/databinding-jaxb/pom.xml create mode 100755 tags/java/sca/1.0-RC1b/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXB2Node.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextHelper.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBDataBinding.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBExceptionHandler.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBWrapperHandler.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXWSJavaInterfaceProcessor.java create mode 100755 tags/java/sca/1.0-RC1b/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/Node2JAXB.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/Reader2JAXB.java create mode 100755 tags/java/sca/1.0-RC1b/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/XMLStreamReader2JAXB.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-jaxb/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.DataBinding create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-jaxb/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-jaxb/src/main/resources/META-INF/services/org.apache.tuscany.sca.interfacedef.java.introspect.JavaInterfaceVisitor create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBDataBindingTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBExceptionHandlerTestCase.java create mode 100755 tags/java/sca/1.0-RC1b/modules/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBWrapperHandlerTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXWSJavaInterfaceProcessorTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/fault/InvalidSymbolFault.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/fault/InvalidSymbolFault_Exception.java create mode 100755 tags/java/sca/1.0-RC1b/modules/databinding-jaxb/src/test/resources/ipo.xsd create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-json/.ruleset create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-json/LICENSE.txt create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-json/NOTICE.txt create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-json/pom.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/JSON2String.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/JSON2XMLStreamReader.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/JSONDataBinding.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/String2JSON.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/XMLStreamReader2JSON.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/XMLStreamSerializer.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/axiom/JSON2OMElement.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/axiom/JSONBadgerfishDataSource.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/axiom/JSONDataSource.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-json/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.DataBinding create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-json/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-json/src/test/java/org/apache/tuscany/sca/databinding/json/JSONTransformerTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-json/src/test/resources/ipo.xsd create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-saxon/LICENSE.txt create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-saxon/NOTICE.txt create mode 100755 tags/java/sca/1.0-RC1b/modules/databinding-saxon/mvn-install-saxon.sh create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-saxon/pom.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/DataObject2NodeInfoTransformer.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/Node2NodeInfoTransformer.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/NodeInfo2DataObjectTransformer.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/NodeInfo2NodeTransformer.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/Object2ValueTransformer.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/SaxonDataBindingHelper.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/SaxonNodeDataBinding.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/SaxonValueDataBinding.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/SimpleType2ValueTransformer.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/Value2ObjectTransformer.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/Value2SimpleTypeTransformer.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/module/SaxonDataBindingModuleActivator.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-saxon/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-sdo-axiom/.checkstyle create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-sdo-axiom/.ruleset create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-sdo-axiom/DISCLAIMER create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-sdo-axiom/LICENSE create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-sdo-axiom/NOTICE create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-sdo-axiom/pom.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-sdo-axiom/src/main/java/org/apache/tuscany/sca/databinding/sdo2om/AxiomHelper.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-sdo-axiom/src/main/java/org/apache/tuscany/sca/databinding/sdo2om/DataObject2OMElement.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-sdo-axiom/src/main/java/org/apache/tuscany/sca/databinding/sdo2om/DataObjectSerializer.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-sdo-axiom/src/main/java/org/apache/tuscany/sca/databinding/sdo2om/SDODataSource.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-sdo-axiom/src/main/java/org/apache/tuscany/sca/databinding/sdo2om/XMLDocument2OMElement.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-sdo-axiom/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-sdo-axiom/src/test/java/org/apache/tuscany/sca/databinding/sdo2om/DataObject2OMElementTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-sdo-axiom/src/test/java/org/apache/tuscany/sca/databinding/sdo2om/SDOTransformerTestCaseBase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-sdo-axiom/src/test/java/org/apache/tuscany/sca/databinding/sdo2om/XMLDocument2OMElementTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-sdo-axiom/src/test/resources/ipo.xsd create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-sdo-axiom/src/test/resources/stock.xsd create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-sdo/.checkstyle create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-sdo/.ruleset create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-sdo/DISCLAIMER create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-sdo/LICENSE create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-sdo/NOTICE create mode 100755 tags/java/sca/1.0-RC1b/modules/databinding-sdo/pom.xml create mode 100755 tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/DataObject2String.java create mode 100755 tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/DataObject2XMLStreamReader.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/ImportSDO.java create mode 100755 tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/ImportSDOProcessor.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOContextHelper.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDODataBinding.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOExceptionHandler.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOSimpleTypeMapper.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOWrapperHandler.java create mode 100755 tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/String2DataObject.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/XMLDocument2String.java create mode 100755 tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/XMLDocument2XMLStreamReader.java create mode 100755 tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/XMLStreamReader2DataObject.java create mode 100755 tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/XMLStreamReader2XMLDocument.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.DataBinding create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/test/java/com/example/stock/sdo/fault/InvalidSymbolFault_Exception.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/DataObject2StringTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/DataObject2XMLStreamReaderTestCase.java create mode 100755 tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/ImportSDOProcessorTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDODataBindingTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDOExceptionHandlerTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDOTransformerTestCaseBase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDOWrapperHandlerTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/TestModelResolver.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/XMLDocument2XMLStreamReaderTestCase.java create mode 100755 tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/test/resources/ipo.xsd create mode 100755 tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/test/resources/model/sca-core.xsd create mode 100755 tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/test/resources/model/sca-implementation-mock.xsd create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/test/resources/stock.xsd create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/test/resources/wrapper.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/test/resources/wrapper.xsd create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-xmlbeans/.ruleset create mode 100755 tags/java/sca/1.0-RC1b/modules/databinding-xmlbeans/LICENSE.txt create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-xmlbeans/NOTICE.txt create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-xmlbeans/pom.xml create mode 100755 tags/java/sca/1.0-RC1b/modules/databinding-xmlbeans/src/main/java/org/apache/tuscany/sca/databinding/xmlbeans/Node2XmlObject.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-xmlbeans/src/main/java/org/apache/tuscany/sca/databinding/xmlbeans/XMLBeansDataBinding.java create mode 100755 tags/java/sca/1.0-RC1b/modules/databinding-xmlbeans/src/main/java/org/apache/tuscany/sca/databinding/xmlbeans/XMLStreamReader2XmlObject.java create mode 100755 tags/java/sca/1.0-RC1b/modules/databinding-xmlbeans/src/main/java/org/apache/tuscany/sca/databinding/xmlbeans/XmlObject2Node.java create mode 100755 tags/java/sca/1.0-RC1b/modules/databinding-xmlbeans/src/main/java/org/apache/tuscany/sca/databinding/xmlbeans/XmlObject2XMLStreamReader.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-xmlbeans/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.DataBinding create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding-xmlbeans/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer create mode 100755 tags/java/sca/1.0-RC1b/modules/databinding-xmlbeans/src/test/java/org/apache/tuscany/sca/databinding/xmlbeans/XmlObjectTestCase.java create mode 100755 tags/java/sca/1.0-RC1b/modules/databinding-xmlbeans/src/test/resources/ipo.xsd create mode 100755 tags/java/sca/1.0-RC1b/modules/databinding-xmlbeans/src/test/resources/ipo.xsdconfig create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding/.checkstyle create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding/.pmd create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding/.ruleset create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding/DISCLAIMER create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding/LICENSE create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding/NOTICE create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding/pom.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DataBinding.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DataBindingExtensionPoint.java create mode 100755 tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DataPipe.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DataPipeTransformer.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DefaultDataBindingExtensionPoint.java create mode 100755 tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DefaultTransformerExtensionPoint.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/ExceptionHandler.java create mode 100755 tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/Mediator.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/PullTransformer.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/PushTransformer.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/SimpleTypeMapper.java create mode 100755 tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/TransformationContext.java create mode 100755 tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/TransformationException.java create mode 100755 tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/Transformer.java create mode 100755 tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/TransformerExtensionPoint.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/WrapperHandler.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/annotation/DataBinding.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/annotation/DataType.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/BaseDataBinding.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/BaseTransformer.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/DOMHelper.java create mode 100755 tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/DirectedGraph.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/Group2GroupTransformer.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/GroupDataBinding.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/Java2SimpleTypeTransformer.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/MediatorImpl.java create mode 100755 tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/PipedTransformer.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/ServiceConfigurationUtil.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/SimpleType2JavaTransformer.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/SimpleTypeMapperImpl.java create mode 100755 tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/TransformationContextImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/XSDDataTypeConverter.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/DOMNode2JavaBeanTransformer.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/Java2XMLMapperException.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/JavaBean2DOMNodeTransformer.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/JavaBean2XMLStreamReader.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/JavaBean2XMLTransformer.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/JavaBeansDataBinding.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/JavaBeansExceptionHandler.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/SimpleJavaDataBinding.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/XML2JavaBeanTransformer.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/XML2JavaMapperException.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/BeanUtil.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/DOMDataBinding.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/DOMWrapperHandler.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/DOMXMLStreamReader.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/DelegatingNamespaceContext.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/InputSource2Node.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/InputSource2SAX.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/InputStream2Node.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/InputStream2SAX.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/NameValueArrayStreamReader.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/NameValuePairStreamReader.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/NamedProperty.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/NilElementStreamReader.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Node2OutputStream.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Node2SimpleJavaType.java create mode 100755 tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Node2String.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Node2Writer.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Node2XMLStreamReader.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Reader2Node.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Reader2SAX.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/SAX2DOM.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/SAX2DOMPipe.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/SimpleJavaType2Node.java create mode 100755 tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Source2ResultTransformer.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/StAX2SAXAdapter.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/StAXDataBinding.java create mode 100755 tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/StAXHelper.java create mode 100755 tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/StreamDataPipe.java create mode 100755 tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/String2Node.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/String2SAX.java create mode 100755 tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/String2XMLStreamReader.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/WrappingXMLStreamReader.java create mode 100755 tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Writer2ReaderDataPipe.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XMLDocumentStreamReader.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XMLFragmentStreamReader.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XMLFragmentStreamReaderImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XMLGroupDataBinding.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XMLStreamReader2Node.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XMLStreamReader2SAX.java create mode 100755 tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XMLStreamReader2String.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XMLStreamSerializer.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XMLStreamable.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XMLStringDataBinding.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.DataBinding create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.DataBindingExtensionPoint create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PushTransformer create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.TransformerExtensionPoint create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/extension/DOMHelperTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/extension/DataBindingExtensionTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/extension/SimpleTypeMapperExtensionTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/extension/TransformerExtensionTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/extension/XSDDataTypeConverterTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/impl/DataBindingRegistryImplTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/impl/DataBindingTestCase.java create mode 100755 tags/java/sca/1.0-RC1b/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/impl/DirectedGraphTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/impl/MediatorImplTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/impl/TransformerRegistryImplTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/DOM2StAXTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/DataPipeTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/JavaBean2XMLStreamReaderTestCase.java create mode 100755 tags/java/sca/1.0-RC1b/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/Node2StringTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/PushTransformationTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/StAXHelperTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/TraxTransformerTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding/src/test/resources/org/apache/tuscany/sca/databinding/impl/ipo.xsd create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding/src/test/resources/org/apache/tuscany/sca/databinding/impl/order.wsdl create mode 100644 tags/java/sca/1.0-RC1b/modules/databinding/src/test/resources/org/apache/tuscany/sca/databinding/xml/foo.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/definitions/DISCLAIMER create mode 100644 tags/java/sca/1.0-RC1b/modules/definitions/LICENSE create mode 100644 tags/java/sca/1.0-RC1b/modules/definitions/NOTICE create mode 100644 tags/java/sca/1.0-RC1b/modules/definitions/pom.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/definitions/src/main/java/org/apache/tuscany/sca/definitions/SCADefinitions.java create mode 100644 tags/java/sca/1.0-RC1b/modules/definitions/src/main/java/org/apache/tuscany/sca/definitions/SCADefinitionsBuilder.java create mode 100644 tags/java/sca/1.0-RC1b/modules/definitions/src/main/java/org/apache/tuscany/sca/definitions/SCADefinitionsBuilderException.java create mode 100644 tags/java/sca/1.0-RC1b/modules/definitions/src/main/java/org/apache/tuscany/sca/definitions/SCADefinitionsBuilderImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/definitions/src/main/java/org/apache/tuscany/sca/definitions/SCADefinitionsDocumentProcessor.java create mode 100644 tags/java/sca/1.0-RC1b/modules/definitions/src/main/java/org/apache/tuscany/sca/definitions/SCADefinitionsProcessor.java create mode 100644 tags/java/sca/1.0-RC1b/modules/definitions/src/main/java/org/apache/tuscany/sca/definitions/SCADefinitionsResolver.java create mode 100644 tags/java/sca/1.0-RC1b/modules/definitions/src/main/java/org/apache/tuscany/sca/definitions/impl/BindingTypeImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/definitions/src/main/java/org/apache/tuscany/sca/definitions/impl/ImplementationTypeImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/definitions/src/main/java/org/apache/tuscany/sca/definitions/impl/SCADefinitionsImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/definitions/src/test/java/org/apache/tuscany/sca/definitions/MockPolicyProcessor.java create mode 100644 tags/java/sca/1.0-RC1b/modules/definitions/src/test/java/org/apache/tuscany/sca/definitions/Policy.java create mode 100644 tags/java/sca/1.0-RC1b/modules/definitions/src/test/java/org/apache/tuscany/sca/definitions/ReadDocumentTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/definitions/src/test/resources/org/apache/tuscany/sca/definitions/test_definitions.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/domain-api/DISCLAIMER create mode 100644 tags/java/sca/1.0-RC1b/modules/domain-api/LICENSE create mode 100644 tags/java/sca/1.0-RC1b/modules/domain-api/NOTICE create mode 100644 tags/java/sca/1.0-RC1b/modules/domain-api/pom.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/domain-api/src/main/java/org/apache/tuscany/sca/domain/SCADomain.java create mode 100644 tags/java/sca/1.0-RC1b/modules/domain-impl/DISCLAIMER create mode 100644 tags/java/sca/1.0-RC1b/modules/domain-impl/LICENSE create mode 100644 tags/java/sca/1.0-RC1b/modules/domain-impl/NOTICE create mode 100644 tags/java/sca/1.0-RC1b/modules/domain-impl/pom.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/domain-impl/src/main/java/org/apache/tuscany/sca/domain/impl/DomainManagerServiceImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/domain-impl/src/main/java/org/apache/tuscany/sca/domain/impl/NodeInfoImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/domain-impl/src/main/java/org/apache/tuscany/sca/domain/impl/SCADomainServiceImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/domain-impl/src/main/java/org/apache/tuscany/sca/domain/impl/ServiceInfoImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/domain-impl/src/main/resources/META-INF/sca-contribution.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/domain-impl/src/main/resources/domain.composite create mode 100644 tags/java/sca/1.0-RC1b/modules/domain-impl/src/main/resources/webroot/domain.png create mode 100644 tags/java/sca/1.0-RC1b/modules/domain-impl/src/main/resources/webroot/index.html create mode 100644 tags/java/sca/1.0-RC1b/modules/domain-impl/src/main/resources/webroot/node.png create mode 100644 tags/java/sca/1.0-RC1b/modules/domain-impl/src/main/resources/webroot/style.css create mode 100644 tags/java/sca/1.0-RC1b/modules/domain/DISCLAIMER create mode 100644 tags/java/sca/1.0-RC1b/modules/domain/LICENSE create mode 100644 tags/java/sca/1.0-RC1b/modules/domain/NOTICE create mode 100644 tags/java/sca/1.0-RC1b/modules/domain/pom.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/domain/src/main/java/org/apache/tuscany/sca/domain/DomainManagerService.java create mode 100644 tags/java/sca/1.0-RC1b/modules/domain/src/main/java/org/apache/tuscany/sca/domain/NodeInfo.java create mode 100644 tags/java/sca/1.0-RC1b/modules/domain/src/main/java/org/apache/tuscany/sca/domain/SCADomainService.java create mode 100644 tags/java/sca/1.0-RC1b/modules/domain/src/main/java/org/apache/tuscany/sca/domain/ServiceInfo.java create mode 100644 tags/java/sca/1.0-RC1b/modules/extension-helper/DISCLAIMER create mode 100644 tags/java/sca/1.0-RC1b/modules/extension-helper/LICENSE create mode 100644 tags/java/sca/1.0-RC1b/modules/extension-helper/NOTICE create mode 100644 tags/java/sca/1.0-RC1b/modules/extension-helper/pom.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/extension-helper/src/main/java/org/apache/tuscany/sca/extension/helper/BindingActivator.java create mode 100644 tags/java/sca/1.0-RC1b/modules/extension-helper/src/main/java/org/apache/tuscany/sca/extension/helper/ComponentLifecycle.java create mode 100644 tags/java/sca/1.0-RC1b/modules/extension-helper/src/main/java/org/apache/tuscany/sca/extension/helper/ImplementationActivator.java create mode 100644 tags/java/sca/1.0-RC1b/modules/extension-helper/src/main/java/org/apache/tuscany/sca/extension/helper/InvokerFactory.java create mode 100644 tags/java/sca/1.0-RC1b/modules/extension-helper/src/main/java/org/apache/tuscany/sca/extension/helper/impl/BindingSCDLProcessor.java create mode 100644 tags/java/sca/1.0-RC1b/modules/extension-helper/src/main/java/org/apache/tuscany/sca/extension/helper/impl/BindingsActivator.java create mode 100644 tags/java/sca/1.0-RC1b/modules/extension-helper/src/main/java/org/apache/tuscany/sca/extension/helper/impl/DiscoveryUtils.java create mode 100644 tags/java/sca/1.0-RC1b/modules/extension-helper/src/main/java/org/apache/tuscany/sca/extension/helper/impl/ImplementationImplementationProvider.java create mode 100644 tags/java/sca/1.0-RC1b/modules/extension-helper/src/main/java/org/apache/tuscany/sca/extension/helper/impl/ImplementationsActivator.java create mode 100644 tags/java/sca/1.0-RC1b/modules/extension-helper/src/main/java/org/apache/tuscany/sca/extension/helper/impl/PojoBinding.java create mode 100644 tags/java/sca/1.0-RC1b/modules/extension-helper/src/main/java/org/apache/tuscany/sca/extension/helper/impl/PojoImplementation.java create mode 100644 tags/java/sca/1.0-RC1b/modules/extension-helper/src/main/java/org/apache/tuscany/sca/extension/helper/impl/SCDLProcessor.java create mode 100644 tags/java/sca/1.0-RC1b/modules/extension-helper/src/main/java/org/apache/tuscany/sca/extension/helper/utils/AbstractBinding.java create mode 100644 tags/java/sca/1.0-RC1b/modules/extension-helper/src/main/java/org/apache/tuscany/sca/extension/helper/utils/AbstractImplementation.java create mode 100644 tags/java/sca/1.0-RC1b/modules/extension-helper/src/main/java/org/apache/tuscany/sca/extension/helper/utils/AbstractStAXArtifactProcessor.java create mode 100644 tags/java/sca/1.0-RC1b/modules/extension-helper/src/main/java/org/apache/tuscany/sca/extension/helper/utils/DefaultPropertyValueObjectFactory.java create mode 100644 tags/java/sca/1.0-RC1b/modules/extension-helper/src/main/java/org/apache/tuscany/sca/extension/helper/utils/DynamicImplementation.java create mode 100644 tags/java/sca/1.0-RC1b/modules/extension-helper/src/main/java/org/apache/tuscany/sca/extension/helper/utils/PropertyValueObjectFactory.java create mode 100644 tags/java/sca/1.0-RC1b/modules/extension-helper/src/main/java/org/apache/tuscany/sca/extension/helper/utils/ResourceHelper.java create mode 100644 tags/java/sca/1.0-RC1b/modules/extension-helper/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator create mode 100644 tags/java/sca/1.0-RC1b/modules/host-embedded/.checkstyle create mode 100644 tags/java/sca/1.0-RC1b/modules/host-embedded/.pmd create mode 100644 tags/java/sca/1.0-RC1b/modules/host-embedded/.ruleset create mode 100644 tags/java/sca/1.0-RC1b/modules/host-embedded/DISCLAIMER create mode 100644 tags/java/sca/1.0-RC1b/modules/host-embedded/LICENSE create mode 100644 tags/java/sca/1.0-RC1b/modules/host-embedded/NOTICE create mode 100644 tags/java/sca/1.0-RC1b/modules/host-embedded/pom.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/SCADomain.java create mode 100644 tags/java/sca/1.0-RC1b/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/SCADomainBean.java create mode 100644 tags/java/sca/1.0-RC1b/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/SCATestCaseRunner.java create mode 100644 tags/java/sca/1.0-RC1b/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/ComponentManagerImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/DefaultSCADomain.java create mode 100644 tags/java/sca/1.0-RC1b/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/EmbeddedSCADomain.java create mode 100644 tags/java/sca/1.0-RC1b/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/HotUpdatableSCADomain.java create mode 100644 tags/java/sca/1.0-RC1b/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/ReallySmallRuntime.java create mode 100644 tags/java/sca/1.0-RC1b/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/ReallySmallRuntimeBuilder.java create mode 100644 tags/java/sca/1.0-RC1b/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/management/ComponentListener.java create mode 100644 tags/java/sca/1.0-RC1b/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/management/ComponentManager.java create mode 100644 tags/java/sca/1.0-RC1b/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/SCADomainBeanTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/SCADomainTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/impl/DefaultSCADomainTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/impl/EmbeddedSCADomainTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/impl/TestModelResolver.java create mode 100644 tags/java/sca/1.0-RC1b/modules/host-embedded/src/test/java/test/crud/CRUD.java create mode 100644 tags/java/sca/1.0-RC1b/modules/host-embedded/src/test/java/test/crud/CRUDImplementation.java create mode 100644 tags/java/sca/1.0-RC1b/modules/host-embedded/src/test/java/test/crud/CRUDImplementationFactory.java create mode 100644 tags/java/sca/1.0-RC1b/modules/host-embedded/src/test/java/test/crud/DefaultCRUDImplementationFactory.java create mode 100644 tags/java/sca/1.0-RC1b/modules/host-embedded/src/test/java/test/crud/backend/ResourceManager.java create mode 100644 tags/java/sca/1.0-RC1b/modules/host-embedded/src/test/java/test/crud/impl/CRUDImplementationImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/host-embedded/src/test/java/test/crud/impl/CRUDImplementationProcessor.java create mode 100644 tags/java/sca/1.0-RC1b/modules/host-embedded/src/test/java/test/crud/module/CRUDModuleActivator.java create mode 100644 tags/java/sca/1.0-RC1b/modules/host-embedded/src/test/java/test/crud/provider/CRUDImplementationProvider.java create mode 100644 tags/java/sca/1.0-RC1b/modules/host-embedded/src/test/java/test/crud/provider/CRUDImplementationProviderFactory.java create mode 100644 tags/java/sca/1.0-RC1b/modules/host-embedded/src/test/java/test/crud/provider/CRUDInvoker.java create mode 100644 tags/java/sca/1.0-RC1b/modules/host-embedded/src/test/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator create mode 100644 tags/java/sca/1.0-RC1b/modules/host-embedded/src/test/resources/crud.composite create mode 100644 tags/java/sca/1.0-RC1b/modules/host-embedded/src/test/resources/test.txt create mode 100644 tags/java/sca/1.0-RC1b/modules/host-http/DISCLAIMER create mode 100644 tags/java/sca/1.0-RC1b/modules/host-http/LICENSE create mode 100644 tags/java/sca/1.0-RC1b/modules/host-http/NOTICE create mode 100644 tags/java/sca/1.0-RC1b/modules/host-http/pom.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/DefaultResourceServlet.java create mode 100644 tags/java/sca/1.0-RC1b/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/DefaultServletHostExtensionPoint.java create mode 100644 tags/java/sca/1.0-RC1b/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/ExtensibleServletHost.java create mode 100644 tags/java/sca/1.0-RC1b/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/ServletHost.java create mode 100644 tags/java/sca/1.0-RC1b/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/ServletHostExtensionPoint.java create mode 100644 tags/java/sca/1.0-RC1b/modules/host-http/src/main/java/org/apache/tuscany/sca/host/http/ServletMappingException.java create mode 100644 tags/java/sca/1.0-RC1b/modules/host-http/src/main/resources/META-INF/services/org.apache.tuscany.sca.host.http.ServletHostExtensionPoint create mode 100644 tags/java/sca/1.0-RC1b/modules/host-jetty/.ruleset create mode 100644 tags/java/sca/1.0-RC1b/modules/host-jetty/DISCLAIMER create mode 100644 tags/java/sca/1.0-RC1b/modules/host-jetty/LICENSE create mode 100644 tags/java/sca/1.0-RC1b/modules/host-jetty/NOTICE create mode 100644 tags/java/sca/1.0-RC1b/modules/host-jetty/pom.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/host-jetty/src/main/java/org/apache/tuscany/sca/http/jetty/JettyDefaultServlet.java create mode 100644 tags/java/sca/1.0-RC1b/modules/host-jetty/src/main/java/org/apache/tuscany/sca/http/jetty/JettyLogger.java create mode 100644 tags/java/sca/1.0-RC1b/modules/host-jetty/src/main/java/org/apache/tuscany/sca/http/jetty/JettyServer.java create mode 100644 tags/java/sca/1.0-RC1b/modules/host-jetty/src/main/java/org/apache/tuscany/sca/http/jetty/module/JettyRuntimeModuleActivator.java create mode 100644 tags/java/sca/1.0-RC1b/modules/host-jetty/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator create mode 100644 tags/java/sca/1.0-RC1b/modules/host-jetty/src/test/java/org/apache/tuscany/sca/http/jetty/JettyServerTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/host-jetty/src/test/resources/content/test.html create mode 100644 tags/java/sca/1.0-RC1b/modules/host-rmi/DISCLAIMER create mode 100644 tags/java/sca/1.0-RC1b/modules/host-rmi/LICENSE create mode 100644 tags/java/sca/1.0-RC1b/modules/host-rmi/NOTICE create mode 100644 tags/java/sca/1.0-RC1b/modules/host-rmi/pom.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/host-rmi/src/main/java/org/apache/tuscany/sca/host/rmi/DefaultRMIHost.java create mode 100644 tags/java/sca/1.0-RC1b/modules/host-rmi/src/main/java/org/apache/tuscany/sca/host/rmi/DefaultRMIHostExtensionPoint.java create mode 100644 tags/java/sca/1.0-RC1b/modules/host-rmi/src/main/java/org/apache/tuscany/sca/host/rmi/ExtensibleRMIHost.java create mode 100644 tags/java/sca/1.0-RC1b/modules/host-rmi/src/main/java/org/apache/tuscany/sca/host/rmi/RMIHost.java create mode 100644 tags/java/sca/1.0-RC1b/modules/host-rmi/src/main/java/org/apache/tuscany/sca/host/rmi/RMIHostException.java create mode 100644 tags/java/sca/1.0-RC1b/modules/host-rmi/src/main/java/org/apache/tuscany/sca/host/rmi/RMIHostExtensionPoint.java create mode 100644 tags/java/sca/1.0-RC1b/modules/host-rmi/src/main/java/org/apache/tuscany/sca/host/rmi/RMIHostRuntimeException.java create mode 100644 tags/java/sca/1.0-RC1b/modules/host-rmi/src/main/resources/META-INF/services/org.apache.tuscany.sca.host.rmi.RMIHostExtensionPoint create mode 100644 tags/java/sca/1.0-RC1b/modules/host-rmi/src/test/java/org/apache/tuscany/sca/host/rmi/RMIHostImplTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/host-tomcat/.ruleset create mode 100644 tags/java/sca/1.0-RC1b/modules/host-tomcat/DISCLAIMER create mode 100644 tags/java/sca/1.0-RC1b/modules/host-tomcat/LICENSE create mode 100644 tags/java/sca/1.0-RC1b/modules/host-tomcat/NOTICE create mode 100644 tags/java/sca/1.0-RC1b/modules/host-tomcat/pom.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/host-tomcat/src/main/java/org/apache/tuscany/sca/http/tomcat/ServletWrapper.java create mode 100644 tags/java/sca/1.0-RC1b/modules/host-tomcat/src/main/java/org/apache/tuscany/sca/http/tomcat/TomcatDefaultServlet.java create mode 100644 tags/java/sca/1.0-RC1b/modules/host-tomcat/src/main/java/org/apache/tuscany/sca/http/tomcat/TomcatServer.java create mode 100644 tags/java/sca/1.0-RC1b/modules/host-tomcat/src/main/java/org/apache/tuscany/sca/http/tomcat/module/TomcatRuntimeModuleActivator.java create mode 100644 tags/java/sca/1.0-RC1b/modules/host-tomcat/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator create mode 100644 tags/java/sca/1.0-RC1b/modules/host-tomcat/src/test/java/org/apache/tuscany/sca/http/tomcat/TomcatServerTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/host-tomcat/src/test/resources/content/test.html create mode 100644 tags/java/sca/1.0-RC1b/modules/host-webapp/DISCLAIMER create mode 100644 tags/java/sca/1.0-RC1b/modules/host-webapp/LICENSE create mode 100644 tags/java/sca/1.0-RC1b/modules/host-webapp/NOTICE create mode 100644 tags/java/sca/1.0-RC1b/modules/host-webapp/pom.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/HotUpdateContextListener.java create mode 100644 tags/java/sca/1.0-RC1b/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/SCADomainHelper.java create mode 100644 tags/java/sca/1.0-RC1b/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/TuscanyContextListener.java create mode 100644 tags/java/sca/1.0-RC1b/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/TuscanyServlet.java create mode 100644 tags/java/sca/1.0-RC1b/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/TuscanyServletFilter.java create mode 100644 tags/java/sca/1.0-RC1b/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppModuleActivator.java create mode 100644 tags/java/sca/1.0-RC1b/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppRequestDispatcher.java create mode 100644 tags/java/sca/1.0-RC1b/modules/host-webapp/src/main/java/org/apache/tuscany/sca/host/webapp/WebAppServletHost.java create mode 100644 tags/java/sca/1.0-RC1b/modules/host-webapp/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-bpel/DISCLAIMER create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-bpel/LICENSE create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-bpel/NOTICE create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-bpel/pom.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/BPELFactory.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/BPELImplementation.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/BPELProcessDefinition.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/DefaultBPELFactory.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/impl/BPELDocumentProcessor.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/impl/BPELImplementationImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/impl/BPELImplementationProcessor.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/impl/BPELProcessDefinitionImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/impl/ODEProcessException.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/EmbeddedODEServer.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/GeronimoTxFactory.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/ODEBindingContext.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/ODEDeployment.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/ODEInitializationException.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/ODEMessageExchangeContext.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/ode/ODEShutdownException.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/provider/BPELImplementationProvider.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/provider/BPELImplementationProviderFactory.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-bpel/src/main/java/org/apache/tuscany/sca/implementation/bpel/provider/BPELInvoker.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-bpel/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-bpel/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-bpel/src/main/resources/META-INF/services/org.apache.tuscany.sca.implementation.bpel.BPELFactory create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-bpel/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.ImplementationProviderFactory create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-bpel/src/test/java/org/apache/tuscany/sca/implementation/bpel/BPELDocumentProcessorTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-bpel/src/test/java/org/apache/tuscany/sca/implementation/bpel/BPELHelloWorldTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-bpel/src/test/java/org/apache/tuscany/sca/implementation/bpel/BPELImplementationProcessorTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-bpel/src/test/java/org/apache/tuscany/sca/implementation/bpel/EmbeddedODEServerTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-bpel/src/test/resources/deploy.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-bpel/src/test/resources/helloworld.bpel create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-bpel/src/test/resources/helloworld.componentType create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-bpel/src/test/resources/helloworld.composite create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-bpel/src/test/resources/helloworld.wsdl create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-bpel/src/test/resources/log4j.properties create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java-runtime/.checkstyle create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java-runtime/.pmd create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java-runtime/.ruleset create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java-runtime/DISCLAIMER create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java-runtime/LICENSE create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java-runtime/NOTICE create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java-runtime/pom.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/context/InstanceFactory.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/context/InstanceFactoryProvider.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/context/ReflectiveInstanceFactory.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/context/ReflectiveInstanceWrapper.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/ArrayMultiplicityObjectFactory.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/ContextInjector.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/ConversationIDObjectFactory.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/FieldInjector.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/InjectionRuntimeException.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/Injector.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/InvalidAccessorException.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/JavaPropertyValueObjectFactory.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/ListMultiplicityObjectFactory.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/MethodInjector.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/RequestContextObjectFactory.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/ResourceHost.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/ResourceNotFoundException.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/ResourceObjectFactory.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/ResourceResolutionException.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/EventInvocationException.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/EventInvoker.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/InvalidConversationSequenceException.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaCallbackRuntimeWireProcessor.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaComponentContextFactory.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaComponentContextProvider.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaComponentNameFactory.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaImplementationInvoker.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaImplementationProvider.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaImplementationProviderFactory.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaInstanceFactoryProvider.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/MethodEventInvoker.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/NoConversationalContractException.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/module/JavaRuntimeModuleActivator.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/context/MultiplicityTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/context/ReflectiveInstanceWrapperTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/injection/CallbackWireObjectFactoryTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/injection/FieldInjectorTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/injection/MethodEventInvokerTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/injection/MethodInjectorTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/injection/RequestContextObjectFactoryTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/injection/ResourceObjectFactoryTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/injection/SingletonObjectFactory.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/injection/SingletonObjectFactoryTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/injection/TestObjectFactory.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/injection/TestObjectFactoryTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/util/Bean1.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/util/Bean2.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/util/Entry.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/util/JavaIntrospectionHelperTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/util/SuperBean.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java-xml/.checkstyle create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java-xml/.pmd create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java-xml/.ruleset create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java-xml/DISCLAIMER create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java-xml/LICENSE create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java-xml/NOTICE create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java-xml/pom.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java-xml/src/main/java/org/apache/tuscany/sca/implementation/java/xml/JavaImplementationConstants.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java-xml/src/main/java/org/apache/tuscany/sca/implementation/java/xml/JavaImplementationProcessor.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java-xml/src/test/java/calculator/AddService.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java-xml/src/test/java/calculator/AddServiceImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java-xml/src/test/java/calculator/CalculatorService.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java-xml/src/test/java/calculator/CalculatorServiceImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java-xml/src/test/java/calculator/DivideService.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java-xml/src/test/java/calculator/DivideServiceImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java-xml/src/test/java/calculator/MultiplyService.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java-xml/src/test/java/calculator/MultiplyServiceImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java-xml/src/test/java/calculator/SubtractService.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java-xml/src/test/java/calculator/SubtractServiceImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/xml/ReadTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/xml/TestModelResolver.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/xml/WriteTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java-xml/src/test/resources/org/apache/tuscany/sca/implementation/java/xml/Calculator.composite create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java/.checkstyle create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java/.pmd create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java/.ruleset create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java/DISCLAIMER create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java/LICENSE create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java/NOTICE create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java/pom.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/BaseJavaImplementation.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/DefaultJavaImplementationFactory.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/IntrospectionException.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/JavaImplementation.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/JavaImplementationFactory.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/impl/BaseJavaImplementationImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/impl/JavaClassIntrospectorImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/impl/JavaConstructorImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/impl/JavaElementImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/impl/JavaImplementationFactoryImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/impl/JavaImplementationImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/impl/JavaParameterImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/impl/JavaResourceImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/impl/JavaScopeImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/JavaClassVisitor.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/AbstractPropertyProcessor.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/AllowsPassByReferenceProcessor.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/AmbiguousConstructorException.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/BaseJavaClassVisitor.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ComponentNameProcessor.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConstructorProcessor.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ContextProcessor.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConversationIDProcessor.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConversationProcessor.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/DestroyProcessor.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/DuplicateConstructorException.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/DuplicateDestructorException.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/DuplicateInitException.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/DuplicatePropertyException.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/DuplicateReferenceException.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/DuplicateResourceException.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/EagerInitProcessor.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/HeuristicPojoProcessor.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/IllegalCallbackReferenceException.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/IllegalContextException.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/IllegalDestructorException.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/IllegalInitException.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/IllegalPropertyException.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/IllegalReferenceException.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/IllegalResourceException.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/IllegalServiceDefinitionException.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/InitProcessor.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/InvalidConstructorException.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/InvalidConversationalImplementation.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/InvalidPropertyException.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/InvalidReferenceException.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/InvalidResourceException.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/InvalidServiceType.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/JavaIntrospectionHelper.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/NoConstructorException.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/PolicyProcessor.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/PropertyProcessor.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ReferenceProcessor.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/Resource.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ResourceProcessor.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ScopeProcessor.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ServiceProcessor.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ServiceTypeNotFoundException.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/UnknownContextTypeException.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java/src/main/resources/META-INF/services/org.apache.tuscany.sca.implementation.java.JavaImplementationFactory create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/AbstractProcessorTest.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/AbstractPropertyProcessorTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/AllowsPassByReferenceProcessorTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConstructorProcessorTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConstructorPropertyTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConstructorReferenceTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConstructorResourceTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ContextProcessorTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConversationIDProcessorTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConversationProcessorTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConvertTimeMillisTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/DestroyProcessorTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/EagerInitProcessorTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/HeuristicAndPropertyTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/HeuristicConstructorTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/HeuristicPojoProcessorTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/HeutisticExtensibleConstructorTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/InitProcessorTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/JavaClassIntrospectorImplTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ModelHelper.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/PolicyProcessorTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/PropertyProcessorTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ReferenceProcessorTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ResourceProcessorTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ScopeProcessorTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ServiceCallbackTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ServiceProcessorTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-node-runtime/DISCLAIMER create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-node-runtime/LICENSE create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-node-runtime/NOTICE create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-node-runtime/pom.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-node-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/provider/NodeImplementationInvoker.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-node-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/provider/NodeImplementationProvider.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-node-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/provider/NodeImplementationProviderFactory.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-node-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.ImplementationProviderFactory create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-node-runtime/src/test/java/org/apache/tuscany/sca/implementation/node/NodeImplementationTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-node-runtime/src/test/resources/TestComposite.composite create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-node-runtime/src/test/resources/TestNode.composite create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-node-xml/DISCLAIMER create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-node-xml/LICENSE create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-node-xml/NOTICE create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-node-xml/pom.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-node-xml/src/main/java/org/apache/tuscany/sca/implementation/node/xml/NodeImplementationProcessor.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-node-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-node-xml/src/test/java/org/apache/tuscany/sca/implementation/node/xml/ReadTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-node-xml/src/test/java/org/apache/tuscany/sca/implementation/node/xml/WriteTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-node-xml/src/test/resources/org/apache/tuscany/sca/implementation/node/xml/TestComposite.composite create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-node-xml/src/test/resources/org/apache/tuscany/sca/implementation/node/xml/TestNode.composite create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-node/DISCLAIMER create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-node/LICENSE create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-node/NOTICE create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-node/pom.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-node/src/main/java/org/apache/tuscany/sca/implementation/node/NodeImplementation.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-node/src/main/java/org/apache/tuscany/sca/implementation/node/NodeImplementationFactory.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-node/src/main/java/org/apache/tuscany/sca/implementation/node/impl/NodeImplementationFactoryImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-node/src/main/java/org/apache/tuscany/sca/implementation/node/impl/NodeImplementationImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-node/src/main/resources/META-INF/services/org.apache.tuscany.sca.implementation.node.NodeImplementationFactory create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-notification/DISCLAIMER create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-notification/LICENSE create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-notification/NOTICE create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-notification/pom.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-notification/src/main/java/org/apache/tuscany/sca/implementation/notification/DefaultNotificationImplementationFactory.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-notification/src/main/java/org/apache/tuscany/sca/implementation/notification/ImmutableMessage.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-notification/src/main/java/org/apache/tuscany/sca/implementation/notification/NotificationComponentInvoker.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-notification/src/main/java/org/apache/tuscany/sca/implementation/notification/NotificationImplementationFactory.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-notification/src/main/java/org/apache/tuscany/sca/implementation/notification/NotificationImplementationImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-notification/src/main/java/org/apache/tuscany/sca/implementation/notification/NotificationImplementationProcessor.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-notification/src/main/java/org/apache/tuscany/sca/implementation/notification/NotificationImplementationProvider.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-notification/src/main/java/org/apache/tuscany/sca/implementation/notification/NotificationImplementationProviderFactory.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-notification/src/main/java/org/apache/tuscany/sca/implementation/notification/NotificationModuleActivator.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-notification/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-notification/src/test/java/org/apache/tuscany/sca/implementation/notification/NotificationComponentTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-notification/src/test/java/org/apache/tuscany/sca/implementation/notification/NotificationImplementationLoaderTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-notification/src/test/resources/TrafficAdvisoryNotificationTestCase.componentType create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-osgi/DISCLAIMER create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-osgi/LICENSE create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-osgi/NOTICE create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-osgi/pom.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/OSGiImplementationInterface.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/context/OSGiAnnotations.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/context/OSGiPropertyInjector.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/context/OSGiPropertyValueObjectFactory.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/invocation/OSGiImplementationProvider.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/invocation/OSGiImplementationProviderFactory.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/invocation/OSGiInstanceWrapper.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/invocation/OSGiRemotableInvoker.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/invocation/OSGiTargetInvoker.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/EquinoxRuntime.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/FelixRuntime.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/KnopflerfishRuntime.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiRuntime.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiImplementation.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-osgi/src/main/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiImplementationProcessor.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-osgi/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-osgi/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.ImplementationProviderFactory create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/invocation/OSGiPropertyTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/invocation/OSGiTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/runtime/OSGiRuntimeTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/test/OSGiTestBundles.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/test/OSGiTestImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/test/OSGiTestInterface.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/test/OSGiTestWithPropertyImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/OSGiReadImplTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-osgi/src/test/java/org/apache/tuscany/sca/implementation/osgi/xml/TestModelResolver.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-osgi/src/test/resources/OSGiTestService.componentType create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-osgi/src/test/resources/osgiproptest.composite create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-osgi/src/test/resources/osgitest.composite create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-resource/DISCLAIMER create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-resource/LICENSE create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-resource/NOTICE create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-resource/pom.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-resource/src/main/java/org/apache/tuscany/sca/implementation/resource/Resource.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-resource/src/main/java/org/apache/tuscany/sca/implementation/resource/ResourceImplementation.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-resource/src/main/java/org/apache/tuscany/sca/implementation/resource/ResourceImplementationFactory.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-resource/src/main/java/org/apache/tuscany/sca/implementation/resource/impl/ResourceImplementationFactoryImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-resource/src/main/java/org/apache/tuscany/sca/implementation/resource/impl/ResourceImplementationImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-resource/src/main/java/org/apache/tuscany/sca/implementation/resource/impl/ResourceImplementationProcessor.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-resource/src/main/java/org/apache/tuscany/sca/implementation/resource/provider/ResourceImplementationInvoker.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-resource/src/main/java/org/apache/tuscany/sca/implementation/resource/provider/ResourceImplementationProvider.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-resource/src/main/java/org/apache/tuscany/sca/implementation/resource/provider/ResourceImplementationProviderFactory.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-resource/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-resource/src/main/resources/META-INF/services/org.apache.tuscany.sca.implementation.resource.ResourceImplementationFactory create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-resource/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.ImplementationProviderFactory create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-resource/src/test/java/org/apache/tuscany/sca/implementation/resource/ResourceImplementationTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-resource/src/test/resources/content/test.html create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-resource/src/test/resources/resource.composite create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-script/DISCLAIMER create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-script/LICENSE create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-script/NOTICE create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-script/pom.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-script/src/main/java/org/apache/tuscany/sca/implementation/script/ScriptImplementation.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-script/src/main/java/org/apache/tuscany/sca/implementation/script/ScriptImplementationActivator.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-script/src/main/java/org/apache/tuscany/sca/implementation/script/ScriptInvoker.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-script/src/main/java/org/apache/tuscany/sca/implementation/script/ScriptInvokerFactory.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-script/src/main/java/org/apache/tuscany/sca/implementation/script/engines/TuscanyJRubyScriptEngine.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-script/src/main/resources/META-INF/services/org.apache.tuscany.sca.extension.helper.ImplementationActivator create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-script/src/test/java/org/apache/tuscany/sca/implementation/script/itests/AbstractSCATestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-script/src/test/java/org/apache/tuscany/sca/implementation/script/itests/dynamic/AbstractHelloWorldTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-script/src/test/java/org/apache/tuscany/sca/implementation/script/itests/dynamic/HelloWorld.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-script/src/test/java/org/apache/tuscany/sca/implementation/script/itests/dynamic/JavaScriptDynamicRefTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-script/src/test/java/org/apache/tuscany/sca/implementation/script/itests/dynamic/JavaScriptHelloWorldTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-script/src/test/java/org/apache/tuscany/sca/implementation/script/itests/helloworld/AbstractHelloWorldTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-script/src/test/java/org/apache/tuscany/sca/implementation/script/itests/helloworld/GroovyHelloWorldTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-script/src/test/java/org/apache/tuscany/sca/implementation/script/itests/helloworld/HelloWorld.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-script/src/test/java/org/apache/tuscany/sca/implementation/script/itests/helloworld/HelloWorldProxy.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-script/src/test/java/org/apache/tuscany/sca/implementation/script/itests/helloworld/JRubyHelloWorldTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-script/src/test/java/org/apache/tuscany/sca/implementation/script/itests/helloworld/JavaScripInlineHelloWorldTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-script/src/test/java/org/apache/tuscany/sca/implementation/script/itests/helloworld/JavaScriptHelloWorldTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-script/src/test/java/org/apache/tuscany/sca/implementation/script/itests/helloworld/JythonHelloWorldTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-script/src/test/java/org/apache/tuscany/sca/implementation/script/itests/properties/AbstractHelloWorldTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-script/src/test/java/org/apache/tuscany/sca/implementation/script/itests/properties/GroovyHelloWorldTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-script/src/test/java/org/apache/tuscany/sca/implementation/script/itests/properties/HelloWorld.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-script/src/test/java/org/apache/tuscany/sca/implementation/script/itests/properties/HelloWorldProxy.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-script/src/test/java/org/apache/tuscany/sca/implementation/script/itests/properties/JRubyHelloWorldTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-script/src/test/java/org/apache/tuscany/sca/implementation/script/itests/properties/JavaScriptHelloWorldTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-script/src/test/java/org/apache/tuscany/sca/implementation/script/itests/properties/JythonHelloWorldTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-script/src/test/java/org/apache/tuscany/sca/implementation/script/itests/references/GroovyReferenceTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-script/src/test/java/org/apache/tuscany/sca/implementation/script/itests/references/HelloWorldTarget.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-script/src/test/java/org/apache/tuscany/sca/implementation/script/itests/references/JRubyReferenceTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-script/src/test/java/org/apache/tuscany/sca/implementation/script/itests/references/JavaScriptReferenceTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-script/src/test/java/org/apache/tuscany/sca/implementation/script/itests/references/JythonReferenceTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/dynamic/JavaScriptDynamicRef.composite create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/dynamic/JavaScriptHelloWorld.composite create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/dynamic/helloworld.js create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/dynamic/helloworldProxy.js create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/helloworld/GroovyHelloWorld.composite create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/helloworld/JRubyHelloWorld.composite create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/helloworld/JavaScripInlineHelloWorld.composite create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/helloworld/JavaScriptHelloWorld.composite create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/helloworld/JythonHelloWorld.composite create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/helloworld/helloworld.componentType create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/helloworld/helloworld.groovy create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/helloworld/helloworld.js create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/helloworld/helloworld.py create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/helloworld/helloworld.rb create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/properties/GroovyHelloWorld.composite create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/properties/JRubyHelloWorld.composite create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/properties/JavaScriptHelloWorld.composite create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/properties/JythonHelloWorld.composite create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/properties/helloworld.componentType create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/properties/helloworld.groovy create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/properties/helloworld.js create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/properties/helloworld.py create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/properties/helloworld.rb create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/references/GroovyReference.composite create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/references/JRubyReference.composite create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/references/JavaScriptReference.composite create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/references/JythonReference.composite create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/references/reference.componentType create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/references/reference.groovy create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/references/reference.js create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/references/reference.py create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/references/reference.rb create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-spring/.ruleset create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-spring/DISCLAIMER create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-spring/LICENSE create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-spring/NOTICE create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-spring/pom.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/SCAApplicationContext.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/SCANamespaceHandlerResolver.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/SCAParentApplicationContext.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/ScaNamespaceHandler.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/ScaPropertyBeanDefinitionParser.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/ScaReferenceBeanDefinitionParser.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/ScaServiceBeanDefinitionParser.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/SpringBeanNotFoundException.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/SpringImplementation.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/SpringImplementationProcessor.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/SpringImplementationProvider.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/SpringImplementationProviderFactory.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/SpringInvocationException.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/SpringInvoker.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/SpringOperationNotFoundException.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/SpringPropertyValueObjectFactory.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringBeanElement.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringBeanIntrospector.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringPropertyElement.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringSCAPropertyElement.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringSCAReferenceElement.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringSCAServiceElement.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/xml/SpringXMLComponentTypeLoader.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-spring/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-spring/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.ImplementationProviderFactory create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-spring/src/main/resources/META-INF/spring.handlers create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-spring/src/main/resources/META-INF/spring.schemas create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-spring/src/main/resources/org/springframework/sca/xml/spring-sca.xsd create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-spring/src/test/java/org/apache/tuscany/sca/implementation/spring/itests/AbstractSCATestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-spring/src/test/java/org/apache/tuscany/sca/implementation/spring/itests/helloworld/AbstractHelloWorldTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-spring/src/test/java/org/apache/tuscany/sca/implementation/spring/itests/helloworld/HelloWorld.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-spring/src/test/java/org/apache/tuscany/sca/implementation/spring/itests/helloworld/HelloWorldImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-spring/src/test/java/org/apache/tuscany/sca/implementation/spring/itests/helloworld/HelloWorldProxy.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-spring/src/test/java/org/apache/tuscany/sca/implementation/spring/itests/helloworld/SpringExplicitHelloWorldTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-spring/src/test/java/org/apache/tuscany/sca/implementation/spring/itests/helloworld/SpringExplicitReferenceTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-spring/src/test/java/org/apache/tuscany/sca/implementation/spring/itests/helloworld/SpringHelloWorldTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-spring/src/test/java/org/apache/tuscany/sca/implementation/spring/itests/helloworld/SpringImplicitReferenceTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-spring/src/test/java/org/apache/tuscany/sca/implementation/spring/itests/helloworld/SpringSCAPropertyTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-spring/src/test/java/org/apache/tuscany/sca/implementation/spring/itests/mock/TestBean.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-spring/src/test/java/org/apache/tuscany/sca/implementation/spring/itests/mock/TestBeanImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-spring/src/test/java/org/apache/tuscany/sca/implementation/spring/itests/mock/TestHelloWorldBean.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-spring/src/test/java/org/apache/tuscany/sca/implementation/spring/itests/mock/TestReference.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-spring/src/test/java/org/apache/tuscany/sca/implementation/spring/itests/mock/TestReferenceBean.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-spring/src/test/java/org/apache/tuscany/sca/implementation/spring/itests/mock/TestSCAPropertyBean.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-spring/src/test/resources/META-INF/sca/SpringExplicitHelloWorld-context.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-spring/src/test/resources/META-INF/sca/SpringExplicitReference-context.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-spring/src/test/resources/META-INF/sca/SpringHelloWorld-context.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-spring/src/test/resources/META-INF/sca/SpringImplicitReference-context.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-spring/src/test/resources/META-INF/sca/SpringSCAProperty-context.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-spring/src/test/resources/META-INF/sca/testReferenceContext.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-spring/src/test/resources/META-INF/sca/testServiceContext.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-spring/src/test/resources/org/apache/tuscany/sca/implementation/spring/itests/helloworld/SpringExplicitHelloWorld.composite create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-spring/src/test/resources/org/apache/tuscany/sca/implementation/spring/itests/helloworld/SpringExplicitReference.composite create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-spring/src/test/resources/org/apache/tuscany/sca/implementation/spring/itests/helloworld/SpringHelloWorld.composite create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-spring/src/test/resources/org/apache/tuscany/sca/implementation/spring/itests/helloworld/SpringImplicitReference.composite create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-spring/src/test/resources/org/apache/tuscany/sca/implementation/spring/itests/helloworld/SpringSCAProperty.composite create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-spring/src/test/resources/test.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-xquery/LICENSE.txt create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-xquery/NOTICE.txt create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-xquery/pom.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-xquery/src/main/java/org/apache/tuscany/sca/implementation/xquery/XQueryImplementation.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-xquery/src/main/java/org/apache/tuscany/sca/implementation/xquery/XQueryImplementationFactory.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-xquery/src/main/java/org/apache/tuscany/sca/implementation/xquery/XQueryImplementationProvider.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-xquery/src/main/java/org/apache/tuscany/sca/implementation/xquery/XQueryImplementationProviderFactory.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-xquery/src/main/java/org/apache/tuscany/sca/implementation/xquery/XQueryInvokationException.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-xquery/src/main/java/org/apache/tuscany/sca/implementation/xquery/XQueryInvoker.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-xquery/src/main/java/org/apache/tuscany/sca/implementation/xquery/XQueryModuleActivator.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-xquery/src/main/java/org/apache/tuscany/sca/implementation/xquery/impl/XQueryImplementationFactoryImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-xquery/src/main/java/org/apache/tuscany/sca/implementation/xquery/impl/XQueryImplementationImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-xquery/src/main/java/org/apache/tuscany/sca/implementation/xquery/xml/XQueryImplementationProcessor.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-xquery/src/main/java/org/apache/tuscany/sca/implementation/xquery/xml/XQueryIntrospector.java create mode 100644 tags/java/sca/1.0-RC1b/modules/implementation-xquery/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator create mode 100644 tags/java/sca/1.0-RC1b/modules/interface-java-xml/.checkstyle create mode 100644 tags/java/sca/1.0-RC1b/modules/interface-java-xml/.pmd create mode 100644 tags/java/sca/1.0-RC1b/modules/interface-java-xml/.ruleset create mode 100644 tags/java/sca/1.0-RC1b/modules/interface-java-xml/DISCLAIMER create mode 100644 tags/java/sca/1.0-RC1b/modules/interface-java-xml/LICENSE create mode 100644 tags/java/sca/1.0-RC1b/modules/interface-java-xml/NOTICE create mode 100644 tags/java/sca/1.0-RC1b/modules/interface-java-xml/pom.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/interface-java-xml/src/main/java/org/apache/tuscany/sca/interfacedef/java/xml/JavaConstants.java create mode 100644 tags/java/sca/1.0-RC1b/modules/interface-java-xml/src/main/java/org/apache/tuscany/sca/interfacedef/java/xml/JavaInterfaceProcessor.java create mode 100644 tags/java/sca/1.0-RC1b/modules/interface-java-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor create mode 100644 tags/java/sca/1.0-RC1b/modules/interface-java-xml/src/test/java/org/apache/tuscany/sca/interfacedef/java/xml/ReadTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/interface-java-xml/src/test/java/org/apache/tuscany/sca/interfacedef/java/xml/WriteTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/interface-java-xml/src/test/resources/org/apache/tuscany/sca/interfacedef/java/xml/Calculator.composite create mode 100644 tags/java/sca/1.0-RC1b/modules/interface-java-xml/src/test/resources/org/apache/tuscany/sca/interfacedef/java/xml/CalculatorComponent.constrainingType create mode 100644 tags/java/sca/1.0-RC1b/modules/interface-java-xml/src/test/resources/org/apache/tuscany/sca/interfacedef/java/xml/CalculatorImpl.componentType create mode 100644 tags/java/sca/1.0-RC1b/modules/interface-java/.checkstyle create mode 100644 tags/java/sca/1.0-RC1b/modules/interface-java/.pmd create mode 100644 tags/java/sca/1.0-RC1b/modules/interface-java/.ruleset create mode 100644 tags/java/sca/1.0-RC1b/modules/interface-java/DISCLAIMER create mode 100644 tags/java/sca/1.0-RC1b/modules/interface-java/LICENSE create mode 100644 tags/java/sca/1.0-RC1b/modules/interface-java/NOTICE create mode 100644 tags/java/sca/1.0-RC1b/modules/interface-java/pom.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/DefaultJavaInterfaceFactory.java create mode 100644 tags/java/sca/1.0-RC1b/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/JavaInterface.java create mode 100644 tags/java/sca/1.0-RC1b/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/JavaInterfaceContract.java create mode 100644 tags/java/sca/1.0-RC1b/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/JavaInterfaceFactory.java create mode 100644 tags/java/sca/1.0-RC1b/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceContractImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceFactoryImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceIntrospectorImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceUtil.java create mode 100644 tags/java/sca/1.0-RC1b/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/introspect/JavaInterfaceVisitor.java create mode 100644 tags/java/sca/1.0-RC1b/modules/interface-java/src/main/resources/META-INF/services/org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory create mode 100644 tags/java/sca/1.0-RC1b/modules/interface-java/src/test/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceUtilTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/interface-java/src/test/java/org/apache/tuscany/sca/interfacedef/java/introspection/impl/ConversationalIntrospectionTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/interface-java/src/test/java/org/apache/tuscany/sca/interfacedef/java/introspection/impl/JavaInterfaceProcessorRegistryImplTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/interface-wsdl-xml/.checkstyle create mode 100644 tags/java/sca/1.0-RC1b/modules/interface-wsdl-xml/.pmd create mode 100644 tags/java/sca/1.0-RC1b/modules/interface-wsdl-xml/.ruleset create mode 100644 tags/java/sca/1.0-RC1b/modules/interface-wsdl-xml/DISCLAIMER create mode 100644 tags/java/sca/1.0-RC1b/modules/interface-wsdl-xml/LICENSE create mode 100644 tags/java/sca/1.0-RC1b/modules/interface-wsdl-xml/NOTICE create mode 100644 tags/java/sca/1.0-RC1b/modules/interface-wsdl-xml/pom.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/interface-wsdl-xml/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLConstants.java create mode 100644 tags/java/sca/1.0-RC1b/modules/interface-wsdl-xml/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLDocumentProcessor.java create mode 100644 tags/java/sca/1.0-RC1b/modules/interface-wsdl-xml/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLInterfaceProcessor.java create mode 100644 tags/java/sca/1.0-RC1b/modules/interface-wsdl-xml/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLModelResolver.java create mode 100644 tags/java/sca/1.0-RC1b/modules/interface-wsdl-xml/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/XMLDocumentHelper.java create mode 100644 tags/java/sca/1.0-RC1b/modules/interface-wsdl-xml/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/XSDDocumentProcessor.java create mode 100644 tags/java/sca/1.0-RC1b/modules/interface-wsdl-xml/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/XSDModelResolver.java create mode 100644 tags/java/sca/1.0-RC1b/modules/interface-wsdl-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor create mode 100644 tags/java/sca/1.0-RC1b/modules/interface-wsdl-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor create mode 100644 tags/java/sca/1.0-RC1b/modules/interface-wsdl-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver create mode 100644 tags/java/sca/1.0-RC1b/modules/interface-wsdl-xml/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/introspect/TestModelResolver.java create mode 100644 tags/java/sca/1.0-RC1b/modules/interface-wsdl-xml/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/introspect/WSDLInterfaceIntrospectorTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/interface-wsdl-xml/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/introspect/WSDLOperationIntrospectorTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/interface-wsdl-xml/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/introspect/WrapperStyleOperationTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/interface-wsdl-xml/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/ReadTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/interface-wsdl-xml/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLDocumentProcessorTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/interface-wsdl-xml/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/interface-wsdl-xml/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WriteTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/interface-wsdl-xml/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/XMLDocumentHelperTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/interface-wsdl-xml/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/XSDDocumentProcessorTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/interface-wsdl-xml/src/test/resources/org/apache/tuscany/sca/interfacedef/wsdl/xml/Calculator.composite create mode 100644 tags/java/sca/1.0-RC1b/modules/interface-wsdl-xml/src/test/resources/org/apache/tuscany/sca/interfacedef/wsdl/xml/CalculatorComponent.constrainingType create mode 100644 tags/java/sca/1.0-RC1b/modules/interface-wsdl-xml/src/test/resources/org/apache/tuscany/sca/interfacedef/wsdl/xml/CalculatorImpl.componentType create mode 100644 tags/java/sca/1.0-RC1b/modules/interface-wsdl-xml/src/test/resources/org/apache/tuscany/sca/interfacedef/wsdl/xml/example.wsdl create mode 100644 tags/java/sca/1.0-RC1b/modules/interface-wsdl-xml/src/test/resources/org/apache/tuscany/sca/interfacedef/wsdl/xml/invalid-stockquote.wsdl create mode 100644 tags/java/sca/1.0-RC1b/modules/interface-wsdl-xml/src/test/resources/org/apache/tuscany/sca/interfacedef/wsdl/xml/ipo.xsd create mode 100644 tags/java/sca/1.0-RC1b/modules/interface-wsdl-xml/src/test/resources/org/apache/tuscany/sca/interfacedef/wsdl/xml/stockquote.wsdl create mode 100644 tags/java/sca/1.0-RC1b/modules/interface-wsdl-xml/src/test/resources/org/apache/tuscany/sca/interfacedef/wsdl/xml/test1.wsdl create mode 100644 tags/java/sca/1.0-RC1b/modules/interface-wsdl-xml/src/test/resources/org/apache/tuscany/sca/interfacedef/wsdl/xml/test1.xsd create mode 100644 tags/java/sca/1.0-RC1b/modules/interface-wsdl-xml/src/test/resources/org/apache/tuscany/sca/interfacedef/wsdl/xml/test2.wsdl create mode 100644 tags/java/sca/1.0-RC1b/modules/interface-wsdl-xml/src/test/resources/org/apache/tuscany/sca/interfacedef/wsdl/xml/unwrapped-stockquote.wsdl create mode 100644 tags/java/sca/1.0-RC1b/modules/interface-wsdl-xml/src/test/resources/wsdl/helloworld-interface.wsdl create mode 100644 tags/java/sca/1.0-RC1b/modules/interface-wsdl-xml/src/test/resources/wsdl/helloworld-service.wsdl create mode 100644 tags/java/sca/1.0-RC1b/modules/interface-wsdl-xml/src/test/resources/xsd/greeting.xsd create mode 100644 tags/java/sca/1.0-RC1b/modules/interface-wsdl-xml/src/test/resources/xsd/name.xsd create mode 100644 tags/java/sca/1.0-RC1b/modules/interface-wsdl/.checkstyle create mode 100644 tags/java/sca/1.0-RC1b/modules/interface-wsdl/.pmd create mode 100644 tags/java/sca/1.0-RC1b/modules/interface-wsdl/.ruleset create mode 100644 tags/java/sca/1.0-RC1b/modules/interface-wsdl/DISCLAIMER create mode 100644 tags/java/sca/1.0-RC1b/modules/interface-wsdl/LICENSE create mode 100644 tags/java/sca/1.0-RC1b/modules/interface-wsdl/NOTICE create mode 100644 tags/java/sca/1.0-RC1b/modules/interface-wsdl/pom.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/DefaultWSDLFactory.java create mode 100644 tags/java/sca/1.0-RC1b/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/WSDLDefinition.java create mode 100644 tags/java/sca/1.0-RC1b/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/WSDLFactory.java create mode 100644 tags/java/sca/1.0-RC1b/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/WSDLInterface.java create mode 100644 tags/java/sca/1.0-RC1b/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/WSDLInterfaceContract.java create mode 100644 tags/java/sca/1.0-RC1b/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/XSDefinition.java create mode 100644 tags/java/sca/1.0-RC1b/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/impl/InvalidWSDLException.java create mode 100644 tags/java/sca/1.0-RC1b/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/impl/WSDLDefinitionImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/impl/WSDLFactoryImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/impl/WSDLInterfaceContractImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/impl/WSDLInterfaceImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/impl/WSDLInterfaceIntrospectorImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/impl/WSDLOperationIntrospectorImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/impl/XSDefinitionImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/interface-wsdl/src/main/resources/META-INF/services/org.apache.tuscany.sca.interfacedef.wsdl.WSDLFactory create mode 100644 tags/java/sca/1.0-RC1b/modules/interface/.checkstyle create mode 100644 tags/java/sca/1.0-RC1b/modules/interface/.pmd create mode 100644 tags/java/sca/1.0-RC1b/modules/interface/.ruleset create mode 100644 tags/java/sca/1.0-RC1b/modules/interface/DISCLAIMER create mode 100644 tags/java/sca/1.0-RC1b/modules/interface/LICENSE create mode 100644 tags/java/sca/1.0-RC1b/modules/interface/NOTICE create mode 100644 tags/java/sca/1.0-RC1b/modules/interface/pom.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/ConversationSequence.java create mode 100644 tags/java/sca/1.0-RC1b/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/DataType.java create mode 100644 tags/java/sca/1.0-RC1b/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/IncompatibleInterfaceContractException.java create mode 100644 tags/java/sca/1.0-RC1b/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/Interface.java create mode 100644 tags/java/sca/1.0-RC1b/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/InterfaceContract.java create mode 100644 tags/java/sca/1.0-RC1b/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/InterfaceContractMapper.java create mode 100644 tags/java/sca/1.0-RC1b/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/InvalidCallbackException.java create mode 100644 tags/java/sca/1.0-RC1b/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/InvalidInterfaceException.java create mode 100644 tags/java/sca/1.0-RC1b/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/InvalidOperationException.java create mode 100644 tags/java/sca/1.0-RC1b/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/Operation.java create mode 100644 tags/java/sca/1.0-RC1b/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/OverloadedOperationException.java create mode 100644 tags/java/sca/1.0-RC1b/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/impl/DataTypeImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/impl/InterfaceContractImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/impl/InterfaceContractMapperImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/impl/InterfaceImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/impl/OperationImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/util/ElementInfo.java create mode 100644 tags/java/sca/1.0-RC1b/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/util/FaultException.java create mode 100644 tags/java/sca/1.0-RC1b/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/util/JavaXMLMapper.java create mode 100644 tags/java/sca/1.0-RC1b/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/util/TypeInfo.java create mode 100644 tags/java/sca/1.0-RC1b/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/util/WrapperInfo.java create mode 100644 tags/java/sca/1.0-RC1b/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/util/XMLType.java create mode 100644 tags/java/sca/1.0-RC1b/modules/interface/src/test/java/org/apache/tuscany/sca/interfacedef/impl/ContractCompatibilityTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/interface/src/test/java/org/apache/tuscany/sca/interfacedef/impl/InterfaceContractTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/java2wsdl/DISCLAIMER create mode 100644 tags/java/sca/1.0-RC1b/modules/java2wsdl/LICENSE create mode 100644 tags/java/sca/1.0-RC1b/modules/java2wsdl/NOTICE create mode 100644 tags/java/sca/1.0-RC1b/modules/java2wsdl/pom.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/java2wsdl/src/main/java/org/apache/tuscany/tools/java2wsdl/generate/GenerationParameters.java create mode 100644 tags/java/sca/1.0-RC1b/modules/java2wsdl/src/main/java/org/apache/tuscany/tools/java2wsdl/generate/Java2WSDL.java create mode 100644 tags/java/sca/1.0-RC1b/modules/java2wsdl/src/main/java/org/apache/tuscany/tools/java2wsdl/generate/Java2WSDLGenerator.java create mode 100644 tags/java/sca/1.0-RC1b/modules/java2wsdl/src/main/java/org/apache/tuscany/tools/java2wsdl/generate/Java2WSDLGeneratorFactory.java create mode 100644 tags/java/sca/1.0-RC1b/modules/java2wsdl/src/main/java/org/apache/tuscany/tools/java2wsdl/generate/Java2WSDLGeneratorImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/java2wsdl/src/main/java/org/apache/tuscany/tools/java2wsdl/generate/SchemaBuilder.java create mode 100644 tags/java/sca/1.0-RC1b/modules/java2wsdl/src/main/java/org/apache/tuscany/tools/java2wsdl/generate/TuscanyJava2OMBuilder.java create mode 100644 tags/java/sca/1.0-RC1b/modules/java2wsdl/src/main/java/org/apache/tuscany/tools/java2wsdl/generate/TuscanyJava2WSDLBuilder.java create mode 100644 tags/java/sca/1.0-RC1b/modules/java2wsdl/src/main/java/org/apache/tuscany/tools/java2wsdl/generate/TuscanyJava2WSDLConstants.java create mode 100644 tags/java/sca/1.0-RC1b/modules/java2wsdl/src/main/java/org/apache/tuscany/tools/java2wsdl/generate/TuscanyJava2WSDLOptionsValidator.java create mode 100644 tags/java/sca/1.0-RC1b/modules/java2wsdl/src/main/java/org/apache/tuscany/tools/java2wsdl/generate/TuscanySchemaGenerator.java create mode 100644 tags/java/sca/1.0-RC1b/modules/java2wsdl/src/main/java/org/apache/tuscany/tools/java2wsdl/generate/TuscanyTypeTable.java create mode 100644 tags/java/sca/1.0-RC1b/modules/java2wsdl/src/main/java/org/apache/tuscany/tools/java2wsdl/generate/TuscanyWSDLTypesGenerator.java create mode 100644 tags/java/sca/1.0-RC1b/modules/java2wsdl/src/main/java/org/apache/tuscany/tools/java2wsdl/generate/WSDLGenEvent.java create mode 100644 tags/java/sca/1.0-RC1b/modules/java2wsdl/src/main/java/org/apache/tuscany/tools/java2wsdl/generate/WSDLGenListener.java create mode 100644 tags/java/sca/1.0-RC1b/modules/java2wsdl/src/main/java/org/apache/tuscany/tools/java2wsdl/util/XMLNameUtil.java create mode 100644 tags/java/sca/1.0-RC1b/modules/java2wsdl/src/main/resources/META-INF/LICENSE.txt create mode 100644 tags/java/sca/1.0-RC1b/modules/java2wsdl/src/test/java/org/apache/tuscany/tools/java2wsdl/generate/CustomerValue.java create mode 100644 tags/java/sca/1.0-RC1b/modules/java2wsdl/src/test/java/org/apache/tuscany/tools/java2wsdl/generate/CustomerWithAccount.java create mode 100644 tags/java/sca/1.0-RC1b/modules/java2wsdl/src/test/java/org/apache/tuscany/tools/java2wsdl/generate/TuscanyJava2WSDLTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/java2wsdl/src/test/java/org/apache/tuscany/tools/java2wsdl/generate/account/Account.java create mode 100644 tags/java/sca/1.0-RC1b/modules/java2wsdl/src/test/java/org/apache/tuscany/tools/java2wsdl/generate/customer/Customer.java create mode 100644 tags/java/sca/1.0-RC1b/modules/java2wsdl/src/test/java/org/apache/tuscany/tools/java2wsdl/generate/extra/GoldCustomer.java create mode 100644 tags/java/sca/1.0-RC1b/modules/java2wsdl/src/test/java/org/soapinterop/CreditScoreDocLit.java create mode 100644 tags/java/sca/1.0-RC1b/modules/java2wsdl/src/test/resources/AccountService.wsdl create mode 100644 tags/java/sca/1.0-RC1b/modules/java2wsdl/src/test/resources/CreditScoreDocLit.wsdl create mode 100644 tags/java/sca/1.0-RC1b/modules/java2wsdl/src/test/resources/helloworld.wsdl create mode 100644 tags/java/sca/1.0-RC1b/modules/java2wsdl/src/test/resources/interopdoc.wsdl create mode 100644 tags/java/sca/1.0-RC1b/modules/java2wsdl/src/test/resources/sequences.xsd create mode 100644 tags/java/sca/1.0-RC1b/modules/maven-java2wsdl/DISCLAIMER create mode 100644 tags/java/sca/1.0-RC1b/modules/maven-java2wsdl/LICENSE create mode 100644 tags/java/sca/1.0-RC1b/modules/maven-java2wsdl/NOTICE create mode 100644 tags/java/sca/1.0-RC1b/modules/maven-java2wsdl/pom.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/maven-java2wsdl/src/main/java/org/apache/tuscany/tools/java2wsdl/plugin/Java2WSDLGeneratorMojo.java create mode 100644 tags/java/sca/1.0-RC1b/modules/maven-wsdl2java/DISCLAIMER create mode 100644 tags/java/sca/1.0-RC1b/modules/maven-wsdl2java/LICENSE create mode 100644 tags/java/sca/1.0-RC1b/modules/maven-wsdl2java/NOTICE create mode 100644 tags/java/sca/1.0-RC1b/modules/maven-wsdl2java/pom.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/maven-wsdl2java/src/main/java/org/apache/tuscany/tools/wsdl2java/plugin/WSDL2JavaGeneratorMojo.java create mode 100644 tags/java/sca/1.0-RC1b/modules/maven-wsdl2java/src/main/java/org/apache/tuscany/tools/wsdl2java/plugin/WSDLFileOption.java create mode 100644 tags/java/sca/1.0-RC1b/modules/node-api/DISCLAIMER create mode 100644 tags/java/sca/1.0-RC1b/modules/node-api/LICENSE create mode 100644 tags/java/sca/1.0-RC1b/modules/node-api/NOTICE create mode 100644 tags/java/sca/1.0-RC1b/modules/node-api/pom.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/node-api/src/main/java/org/apache/tuscany/sca/node/ComponentInfo.java create mode 100644 tags/java/sca/1.0-RC1b/modules/node-api/src/main/java/org/apache/tuscany/sca/node/ComponentListener.java create mode 100644 tags/java/sca/1.0-RC1b/modules/node-api/src/main/java/org/apache/tuscany/sca/node/ComponentManager.java create mode 100644 tags/java/sca/1.0-RC1b/modules/node-api/src/main/java/org/apache/tuscany/sca/node/ComponentManagerService.java create mode 100644 tags/java/sca/1.0-RC1b/modules/node-api/src/main/java/org/apache/tuscany/sca/node/CompositeManager.java create mode 100644 tags/java/sca/1.0-RC1b/modules/node-api/src/main/java/org/apache/tuscany/sca/node/ContributionManager.java create mode 100644 tags/java/sca/1.0-RC1b/modules/node-api/src/main/java/org/apache/tuscany/sca/node/SCADomain.java create mode 100644 tags/java/sca/1.0-RC1b/modules/node-api/src/main/java/org/apache/tuscany/sca/node/SCANode.java create mode 100644 tags/java/sca/1.0-RC1b/modules/node-impl/DISCLAIMER create mode 100644 tags/java/sca/1.0-RC1b/modules/node-impl/LICENSE create mode 100644 tags/java/sca/1.0-RC1b/modules/node-impl/NOTICE create mode 100644 tags/java/sca/1.0-RC1b/modules/node-impl/pom.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/ComponentInfoImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/ComponentManagerServiceImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/ContributionManagerImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/DomainManagerServiceImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeFactoryImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeManagerServiceImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/SCADomainServiceImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/SCANodeImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/SCANodeUtil.java create mode 100644 tags/java/sca/1.0-RC1b/modules/node-impl/src/test/java/calculator/AddService.java create mode 100644 tags/java/sca/1.0-RC1b/modules/node-impl/src/test/java/calculator/AddServiceImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/node-impl/src/test/java/calculator/CalculatorService.java create mode 100644 tags/java/sca/1.0-RC1b/modules/node-impl/src/test/java/calculator/CalculatorServiceImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/node-impl/src/test/java/calculator/DivideService.java create mode 100644 tags/java/sca/1.0-RC1b/modules/node-impl/src/test/java/calculator/DivideServiceImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/node-impl/src/test/java/calculator/MultiplyService.java create mode 100644 tags/java/sca/1.0-RC1b/modules/node-impl/src/test/java/calculator/MultiplyServiceImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/node-impl/src/test/java/calculator/SubtractService.java create mode 100644 tags/java/sca/1.0-RC1b/modules/node-impl/src/test/java/calculator/SubtractServiceImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/impl/InMemoryTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/node-impl/src/test/resources/nodeA/Calculator.composite create mode 100644 tags/java/sca/1.0-RC1b/modules/node-impl/src/test/resources/nodeA/META-INF/sca-contribution.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/node-impl/src/test/resources/nodeA/wsdl/add.wsdl create mode 100644 tags/java/sca/1.0-RC1b/modules/node-impl/src/test/resources/nodeA/wsdl/multiply.wsdl create mode 100644 tags/java/sca/1.0-RC1b/modules/node-impl/src/test/resources/nodeA/wsdl/subtract.wsdl create mode 100644 tags/java/sca/1.0-RC1b/modules/node-impl/src/test/resources/nodeB/Calculator.composite create mode 100644 tags/java/sca/1.0-RC1b/modules/node-impl/src/test/resources/nodeB/META-INF/sca-contribution.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/node-impl/src/test/resources/nodeC/Calculator.composite create mode 100644 tags/java/sca/1.0-RC1b/modules/node-impl/src/test/resources/nodeC/META-INF/sca-contribution.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/node/DISCLAIMER create mode 100644 tags/java/sca/1.0-RC1b/modules/node/LICENSE create mode 100644 tags/java/sca/1.0-RC1b/modules/node/NOTICE create mode 100644 tags/java/sca/1.0-RC1b/modules/node/pom.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/node/src/main/java/org/apache/tuscany/sca/node/ComponentInfo.java create mode 100644 tags/java/sca/1.0-RC1b/modules/node/src/main/java/org/apache/tuscany/sca/node/ComponentListener.java create mode 100644 tags/java/sca/1.0-RC1b/modules/node/src/main/java/org/apache/tuscany/sca/node/ComponentManager.java create mode 100644 tags/java/sca/1.0-RC1b/modules/node/src/main/java/org/apache/tuscany/sca/node/ComponentManagerService.java create mode 100644 tags/java/sca/1.0-RC1b/modules/node/src/main/java/org/apache/tuscany/sca/node/CompositeManager.java create mode 100644 tags/java/sca/1.0-RC1b/modules/node/src/main/java/org/apache/tuscany/sca/node/ContributionManager.java create mode 100644 tags/java/sca/1.0-RC1b/modules/node/src/main/java/org/apache/tuscany/sca/node/NodeFactory.java create mode 100644 tags/java/sca/1.0-RC1b/modules/node/src/main/java/org/apache/tuscany/sca/node/NodeManagerInitService.java create mode 100644 tags/java/sca/1.0-RC1b/modules/node/src/main/java/org/apache/tuscany/sca/node/NodeManagerService.java create mode 100644 tags/java/sca/1.0-RC1b/modules/node/src/main/java/org/apache/tuscany/sca/node/SCANode.java create mode 100644 tags/java/sca/1.0-RC1b/modules/node/src/main/resources/META-INF/sca-contribution.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/node/src/main/resources/node.composite create mode 100644 tags/java/sca/1.0-RC1b/modules/node/src/main/resources/webroot/index.html create mode 100644 tags/java/sca/1.0-RC1b/modules/node/src/main/resources/webroot/node.png create mode 100644 tags/java/sca/1.0-RC1b/modules/node/src/main/resources/webroot/style.css create mode 100644 tags/java/sca/1.0-RC1b/modules/osgi-runtime/DISCLAIMER create mode 100644 tags/java/sca/1.0-RC1b/modules/osgi-runtime/LICENSE create mode 100644 tags/java/sca/1.0-RC1b/modules/osgi-runtime/NOTICE create mode 100644 tags/java/sca/1.0-RC1b/modules/osgi-runtime/pom.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/osgi-runtime/src/main/java/org/apache/tuscany/sca/osgi/runtime/EquinoxRuntime.java create mode 100644 tags/java/sca/1.0-RC1b/modules/osgi-runtime/src/main/java/org/apache/tuscany/sca/osgi/runtime/FelixRuntime.java create mode 100644 tags/java/sca/1.0-RC1b/modules/osgi-runtime/src/main/java/org/apache/tuscany/sca/osgi/runtime/KnopflerfishRuntime.java create mode 100644 tags/java/sca/1.0-RC1b/modules/osgi-runtime/src/main/java/org/apache/tuscany/sca/osgi/runtime/OSGiRuntime.java create mode 100644 tags/java/sca/1.0-RC1b/modules/osgi-runtime/src/test/java/org/apache/tuscany/sca/osgi/runtime/OSGiRuntimeTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/policy-security/DISCLAIMER create mode 100644 tags/java/sca/1.0-RC1b/modules/policy-security/LICENSE create mode 100644 tags/java/sca/1.0-RC1b/modules/policy-security/NOTICE create mode 100644 tags/java/sca/1.0-RC1b/modules/policy-security/pom.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/security/ws/Axis2ConfigParamPolicy.java create mode 100644 tags/java/sca/1.0-RC1b/modules/policy-security/src/main/java/org/apache/tuscany/sca/policy/security/ws/Axis2ConfigParamPolicyProcessor.java create mode 100644 tags/java/sca/1.0-RC1b/modules/policy-security/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor create mode 100644 tags/java/sca/1.0-RC1b/modules/policy-security/src/main/resources/policy_definitions.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/policy-security/src/test/java/org/apache/tuscany/sca/policy/security/ws/PolicyReadTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/policy-security/src/test/resources/org/apache/tuscany/sca/policy/security/ws/mock_policies.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/policy-xml/DISCLAIMER create mode 100644 tags/java/sca/1.0-RC1b/modules/policy-xml/LICENSE create mode 100644 tags/java/sca/1.0-RC1b/modules/policy-xml/NOTICE create mode 100644 tags/java/sca/1.0-RC1b/modules/policy-xml/pom.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/BindingTypeProcessor.java create mode 100644 tags/java/sca/1.0-RC1b/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/ImplementationTypeProcessor.java create mode 100644 tags/java/sca/1.0-RC1b/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/IntentAttachPointTypeProcessor.java create mode 100644 tags/java/sca/1.0-RC1b/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicyConstants.java create mode 100644 tags/java/sca/1.0-RC1b/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicyIntentProcessor.java create mode 100644 tags/java/sca/1.0-RC1b/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicySetProcessor.java create mode 100644 tags/java/sca/1.0-RC1b/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/ProfileIntentProcessor.java create mode 100644 tags/java/sca/1.0-RC1b/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/QualifiedIntentProcessor.java create mode 100644 tags/java/sca/1.0-RC1b/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/SimpleIntentProcessor.java create mode 100644 tags/java/sca/1.0-RC1b/modules/policy-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor create mode 100644 tags/java/sca/1.0-RC1b/modules/policy-xml/src/test/java/org/apache/tuscany/sca/policy/xml/MockPolicyProcessor.java create mode 100644 tags/java/sca/1.0-RC1b/modules/policy-xml/src/test/java/org/apache/tuscany/sca/policy/xml/Policy.java create mode 100644 tags/java/sca/1.0-RC1b/modules/policy-xml/src/test/java/org/apache/tuscany/sca/policy/xml/ReadDocumentTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/policy-xml/src/test/java/org/apache/tuscany/sca/policy/xml/TestModelResolver.java create mode 100644 tags/java/sca/1.0-RC1b/modules/policy-xml/src/test/resources/org/apache/tuscany/sca/policy/xml/test_definitions.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/policy/DISCLAIMER create mode 100644 tags/java/sca/1.0-RC1b/modules/policy/LICENSE create mode 100644 tags/java/sca/1.0-RC1b/modules/policy/NOTICE create mode 100644 tags/java/sca/1.0-RC1b/modules/policy/pom.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/policy/src/main/java/org/apache/tuscany/sca/policy/DefaultIntentAttachPointTypeFactory.java create mode 100644 tags/java/sca/1.0-RC1b/modules/policy/src/main/java/org/apache/tuscany/sca/policy/DefaultPolicyFactory.java create mode 100644 tags/java/sca/1.0-RC1b/modules/policy/src/main/java/org/apache/tuscany/sca/policy/Intent.java create mode 100644 tags/java/sca/1.0-RC1b/modules/policy/src/main/java/org/apache/tuscany/sca/policy/IntentAttachPoint.java create mode 100644 tags/java/sca/1.0-RC1b/modules/policy/src/main/java/org/apache/tuscany/sca/policy/IntentAttachPointType.java create mode 100644 tags/java/sca/1.0-RC1b/modules/policy/src/main/java/org/apache/tuscany/sca/policy/IntentAttachPointTypeFactory.java create mode 100644 tags/java/sca/1.0-RC1b/modules/policy/src/main/java/org/apache/tuscany/sca/policy/IntentMap.java create mode 100644 tags/java/sca/1.0-RC1b/modules/policy/src/main/java/org/apache/tuscany/sca/policy/Policy.java create mode 100644 tags/java/sca/1.0-RC1b/modules/policy/src/main/java/org/apache/tuscany/sca/policy/PolicyFactory.java create mode 100644 tags/java/sca/1.0-RC1b/modules/policy/src/main/java/org/apache/tuscany/sca/policy/PolicySet.java create mode 100644 tags/java/sca/1.0-RC1b/modules/policy/src/main/java/org/apache/tuscany/sca/policy/PolicySetAttachPoint.java create mode 100644 tags/java/sca/1.0-RC1b/modules/policy/src/main/java/org/apache/tuscany/sca/policy/PolicySetReference.java create mode 100644 tags/java/sca/1.0-RC1b/modules/policy/src/main/java/org/apache/tuscany/sca/policy/ProfileIntent.java create mode 100644 tags/java/sca/1.0-RC1b/modules/policy/src/main/java/org/apache/tuscany/sca/policy/QualifiedIntent.java create mode 100644 tags/java/sca/1.0-RC1b/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/BindingTypeImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/ImplementationTypeImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/IntentAttachPointTypeFactoryImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/IntentImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/IntentMapImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/PolicyFactoryImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/PolicySetImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/PolicySetReferenceImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/ProfileIntentImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/QualifiedIntentImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/policy/src/main/resources/META-INF/services/org.apache.tuscany.sca.policy.IntentAttachPointTypeFactory create mode 100644 tags/java/sca/1.0-RC1b/modules/policy/src/main/resources/META-INF/services/org.apache.tuscany.sca.policy.PolicyFactory create mode 100644 tags/java/sca/1.0-RC1b/modules/policy/src/test/java/org/apache/tuscany/sca/policy/PolicyFactoryTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/pom.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/sca-api/DISCLAIMER create mode 100644 tags/java/sca/1.0-RC1b/modules/sca-api/LICENSE create mode 100644 tags/java/sca/1.0-RC1b/modules/sca-api/NOTICE create mode 100644 tags/java/sca/1.0-RC1b/modules/sca-api/pom.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/sca-api/src/main/java/org/osoa/sca/CallableReference.java create mode 100644 tags/java/sca/1.0-RC1b/modules/sca-api/src/main/java/org/osoa/sca/ComponentContext.java create mode 100644 tags/java/sca/1.0-RC1b/modules/sca-api/src/main/java/org/osoa/sca/Constants.java create mode 100644 tags/java/sca/1.0-RC1b/modules/sca-api/src/main/java/org/osoa/sca/Conversation.java create mode 100644 tags/java/sca/1.0-RC1b/modules/sca-api/src/main/java/org/osoa/sca/ConversationEndedException.java create mode 100644 tags/java/sca/1.0-RC1b/modules/sca-api/src/main/java/org/osoa/sca/NoRegisteredCallbackException.java create mode 100644 tags/java/sca/1.0-RC1b/modules/sca-api/src/main/java/org/osoa/sca/RequestContext.java create mode 100644 tags/java/sca/1.0-RC1b/modules/sca-api/src/main/java/org/osoa/sca/ServiceReference.java create mode 100644 tags/java/sca/1.0-RC1b/modules/sca-api/src/main/java/org/osoa/sca/ServiceRuntimeException.java create mode 100644 tags/java/sca/1.0-RC1b/modules/sca-api/src/main/java/org/osoa/sca/ServiceUnavailableException.java create mode 100644 tags/java/sca/1.0-RC1b/modules/sca-api/src/main/java/org/osoa/sca/annotations/AllowsPassByReference.java create mode 100644 tags/java/sca/1.0-RC1b/modules/sca-api/src/main/java/org/osoa/sca/annotations/Authentication.java create mode 100644 tags/java/sca/1.0-RC1b/modules/sca-api/src/main/java/org/osoa/sca/annotations/Callback.java create mode 100644 tags/java/sca/1.0-RC1b/modules/sca-api/src/main/java/org/osoa/sca/annotations/ComponentName.java create mode 100644 tags/java/sca/1.0-RC1b/modules/sca-api/src/main/java/org/osoa/sca/annotations/Confidentiality.java create mode 100644 tags/java/sca/1.0-RC1b/modules/sca-api/src/main/java/org/osoa/sca/annotations/Constructor.java create mode 100644 tags/java/sca/1.0-RC1b/modules/sca-api/src/main/java/org/osoa/sca/annotations/Context.java create mode 100644 tags/java/sca/1.0-RC1b/modules/sca-api/src/main/java/org/osoa/sca/annotations/ConversationAttributes.java create mode 100644 tags/java/sca/1.0-RC1b/modules/sca-api/src/main/java/org/osoa/sca/annotations/ConversationID.java create mode 100644 tags/java/sca/1.0-RC1b/modules/sca-api/src/main/java/org/osoa/sca/annotations/Conversational.java create mode 100644 tags/java/sca/1.0-RC1b/modules/sca-api/src/main/java/org/osoa/sca/annotations/Destroy.java create mode 100644 tags/java/sca/1.0-RC1b/modules/sca-api/src/main/java/org/osoa/sca/annotations/EagerInit.java create mode 100644 tags/java/sca/1.0-RC1b/modules/sca-api/src/main/java/org/osoa/sca/annotations/EndsConversation.java create mode 100644 tags/java/sca/1.0-RC1b/modules/sca-api/src/main/java/org/osoa/sca/annotations/Init.java create mode 100644 tags/java/sca/1.0-RC1b/modules/sca-api/src/main/java/org/osoa/sca/annotations/Integrity.java create mode 100644 tags/java/sca/1.0-RC1b/modules/sca-api/src/main/java/org/osoa/sca/annotations/Intent.java create mode 100644 tags/java/sca/1.0-RC1b/modules/sca-api/src/main/java/org/osoa/sca/annotations/OneWay.java create mode 100644 tags/java/sca/1.0-RC1b/modules/sca-api/src/main/java/org/osoa/sca/annotations/PolicySets.java create mode 100644 tags/java/sca/1.0-RC1b/modules/sca-api/src/main/java/org/osoa/sca/annotations/Property.java create mode 100644 tags/java/sca/1.0-RC1b/modules/sca-api/src/main/java/org/osoa/sca/annotations/Qualifier.java create mode 100644 tags/java/sca/1.0-RC1b/modules/sca-api/src/main/java/org/osoa/sca/annotations/Reference.java create mode 100644 tags/java/sca/1.0-RC1b/modules/sca-api/src/main/java/org/osoa/sca/annotations/Remotable.java create mode 100644 tags/java/sca/1.0-RC1b/modules/sca-api/src/main/java/org/osoa/sca/annotations/Requires.java create mode 100644 tags/java/sca/1.0-RC1b/modules/sca-api/src/main/java/org/osoa/sca/annotations/Scope.java create mode 100644 tags/java/sca/1.0-RC1b/modules/sca-api/src/main/java/org/osoa/sca/annotations/Service.java create mode 100644 tags/java/sca/1.0-RC1b/modules/topology-xml/DISCLAIMER create mode 100644 tags/java/sca/1.0-RC1b/modules/topology-xml/LICENSE create mode 100644 tags/java/sca/1.0-RC1b/modules/topology-xml/NOTICE create mode 100644 tags/java/sca/1.0-RC1b/modules/topology-xml/pom.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/topology-xml/src/main/java/org/apache/tuscany/sca/topology/xml/BaseTopologyArtifactProcessor.java create mode 100644 tags/java/sca/1.0-RC1b/modules/topology-xml/src/main/java/org/apache/tuscany/sca/topology/xml/Constants.java create mode 100644 tags/java/sca/1.0-RC1b/modules/topology-xml/src/main/java/org/apache/tuscany/sca/topology/xml/TopologyDocumentProcessor.java create mode 100644 tags/java/sca/1.0-RC1b/modules/topology-xml/src/main/java/org/apache/tuscany/sca/topology/xml/TopologyProcessor.java create mode 100644 tags/java/sca/1.0-RC1b/modules/topology-xml/src/test/java/org/apache/tuscany/sca/topology/xml/ReadDocumentTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/topology-xml/src/test/java/org/apache/tuscany/sca/topology/xml/TestModelResolver.java create mode 100644 tags/java/sca/1.0-RC1b/modules/topology-xml/src/test/resources/org/apache/tuscany/sca/topology/xml/runtime.topology create mode 100644 tags/java/sca/1.0-RC1b/modules/topology/DISCLAIMER create mode 100644 tags/java/sca/1.0-RC1b/modules/topology/LICENSE create mode 100644 tags/java/sca/1.0-RC1b/modules/topology/NOTICE create mode 100644 tags/java/sca/1.0-RC1b/modules/topology/pom.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/topology/src/main/java/org/apache/tuscany/sca/topology/Component.java create mode 100644 tags/java/sca/1.0-RC1b/modules/topology/src/main/java/org/apache/tuscany/sca/topology/DefaultTopologyFactory.java create mode 100644 tags/java/sca/1.0-RC1b/modules/topology/src/main/java/org/apache/tuscany/sca/topology/Node.java create mode 100644 tags/java/sca/1.0-RC1b/modules/topology/src/main/java/org/apache/tuscany/sca/topology/Runtime.java create mode 100644 tags/java/sca/1.0-RC1b/modules/topology/src/main/java/org/apache/tuscany/sca/topology/Scheme.java create mode 100644 tags/java/sca/1.0-RC1b/modules/topology/src/main/java/org/apache/tuscany/sca/topology/TopologyFactory.java create mode 100644 tags/java/sca/1.0-RC1b/modules/topology/src/main/java/org/apache/tuscany/sca/topology/impl/ComponentImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/topology/src/main/java/org/apache/tuscany/sca/topology/impl/NodeImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/topology/src/main/java/org/apache/tuscany/sca/topology/impl/RuntimeImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/topology/src/main/java/org/apache/tuscany/sca/topology/impl/SchemeImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/topology/src/main/java/org/apache/tuscany/sca/topology/impl/TopologyFactoryImpl.java create mode 100644 tags/java/sca/1.0-RC1b/modules/topology/src/test/java/org/apache/tuscany/sca/topology/TopologyFactoryTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/wsdl2java/DISCLAIMER create mode 100644 tags/java/sca/1.0-RC1b/modules/wsdl2java/LICENSE create mode 100644 tags/java/sca/1.0-RC1b/modules/wsdl2java/NOTICE create mode 100644 tags/java/sca/1.0-RC1b/modules/wsdl2java/pom.xml create mode 100644 tags/java/sca/1.0-RC1b/modules/wsdl2java/src/main/java/org/apache/tuscany/tools/wsdl2java/generate/JavaInterfaceEmitter.java create mode 100644 tags/java/sca/1.0-RC1b/modules/wsdl2java/src/main/java/org/apache/tuscany/tools/wsdl2java/generate/JavaInterfaceGenerator.java create mode 100644 tags/java/sca/1.0-RC1b/modules/wsdl2java/src/main/java/org/apache/tuscany/tools/wsdl2java/generate/RemotableInterfaceWritter.java create mode 100644 tags/java/sca/1.0-RC1b/modules/wsdl2java/src/main/java/org/apache/tuscany/tools/wsdl2java/generate/SDODataBindingCodegenExtension.java create mode 100644 tags/java/sca/1.0-RC1b/modules/wsdl2java/src/main/java/org/apache/tuscany/tools/wsdl2java/generate/SDODataBindingTypeMappingEntry.java create mode 100644 tags/java/sca/1.0-RC1b/modules/wsdl2java/src/main/java/org/apache/tuscany/tools/wsdl2java/generate/WSDL2JavaGenerator.java create mode 100644 tags/java/sca/1.0-RC1b/modules/wsdl2java/src/main/java/org/apache/tuscany/tools/wsdl2java/util/XMLNameUtil.java create mode 100644 tags/java/sca/1.0-RC1b/modules/wsdl2java/src/main/resources/META-INF/LICENSE.txt create mode 100644 tags/java/sca/1.0-RC1b/modules/wsdl2java/src/main/resources/RemotableInterfaceTemplate.xsl create mode 100644 tags/java/sca/1.0-RC1b/modules/wsdl2java/src/test/java/org/apache/tuscany/tools/wsdl2java/generate/WSDL2JavaGeneratorTestCase.java create mode 100644 tags/java/sca/1.0-RC1b/modules/wsdl2java/src/test/java/org/soapinterop/CreditScoreDocLit.java create mode 100644 tags/java/sca/1.0-RC1b/modules/wsdl2java/src/test/resources/AccountService.wsdl create mode 100644 tags/java/sca/1.0-RC1b/modules/wsdl2java/src/test/resources/AccountServiceWithFault.wsdl create mode 100644 tags/java/sca/1.0-RC1b/modules/wsdl2java/src/test/resources/CreditScoreDocLit.wsdl create mode 100644 tags/java/sca/1.0-RC1b/modules/wsdl2java/src/test/resources/helloworld.wsdl create mode 100644 tags/java/sca/1.0-RC1b/modules/wsdl2java/src/test/resources/interopdoc.wsdl create mode 100644 tags/java/sca/1.0-RC1b/modules/wsdl2java/src/test/resources/sequences.xsd (limited to 'tags/java/sca/1.0-RC1b/modules') diff --git a/tags/java/sca/1.0-RC1b/modules/assembly-java-dsl/DISCLAIMER b/tags/java/sca/1.0-RC1b/modules/assembly-java-dsl/DISCLAIMER new file mode 100644 index 0000000000..d68a410903 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly-java-dsl/DISCLAIMER @@ -0,0 +1,8 @@ +Apache Tuscany is an effort undergoing incubation at The Apache Software +Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is +required of all newly accepted projects until a further review indicates that +the infrastructure, communications, and decision making process have stabilized +in a manner consistent with other successful ASF projects. While incubation +status is not necessarily a reflection of the completeness or stability of the +code, it does indicate that the project has yet to be fully endorsed by the ASF. + diff --git a/tags/java/sca/1.0-RC1b/modules/assembly-java-dsl/LICENSE b/tags/java/sca/1.0-RC1b/modules/assembly-java-dsl/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly-java-dsl/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/tags/java/sca/1.0-RC1b/modules/assembly-java-dsl/NOTICE b/tags/java/sca/1.0-RC1b/modules/assembly-java-dsl/NOTICE new file mode 100644 index 0000000000..94481d6cfa --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly-java-dsl/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2007 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/tags/java/sca/1.0-RC1b/modules/assembly-java-dsl/pom.xml b/tags/java/sca/1.0-RC1b/modules/assembly-java-dsl/pom.xml new file mode 100644 index 0000000000..997b075d98 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly-java-dsl/pom.xml @@ -0,0 +1,38 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.0-incubating + ../pom.xml + + tuscany-assembly-java-dsl + Apache Tuscany SCA Assembly Model Java DSL + + + + org.apache.tuscany.sca + tuscany-assembly + 1.0-incubating + + + diff --git a/tags/java/sca/1.0-RC1b/modules/assembly-java-dsl/src/main/java/org/apache/tuscany/sca/assembly/dsl/AssemblyBuilder.java b/tags/java/sca/1.0-RC1b/modules/assembly-java-dsl/src/main/java/org/apache/tuscany/sca/assembly/dsl/AssemblyBuilder.java new file mode 100644 index 0000000000..28a5ecdc24 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly-java-dsl/src/main/java/org/apache/tuscany/sca/assembly/dsl/AssemblyBuilder.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.dsl; + + +public interface AssemblyBuilder { + + CompositeBuilder composite(String name); + + ComponentBuilder component(String name); + + ComponentReferenceBuilder reference(String name); + + ComponentServiceBuilder service(String name); + + ComponentPropertyBuilder property(String name); + + CompositeBuilder domain(String uri); + +} diff --git a/tags/java/sca/1.0-RC1b/modules/assembly-java-dsl/src/main/java/org/apache/tuscany/sca/assembly/dsl/ComponentBuilder.java b/tags/java/sca/1.0-RC1b/modules/assembly-java-dsl/src/main/java/org/apache/tuscany/sca/assembly/dsl/ComponentBuilder.java new file mode 100644 index 0000000000..98f247e5cc --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly-java-dsl/src/main/java/org/apache/tuscany/sca/assembly/dsl/ComponentBuilder.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.assembly.dsl; + +public interface ComponentBuilder { + + ComponentBuilder implementedBy(Class clazz); + + ComponentBuilder implementedBy(CompositeBuilder composite); + + public ComponentBuilder uses(ComponentReferenceBuilder... componentReferences); + + public ComponentBuilder provides(ComponentServiceBuilder... componentServices); + + public ComponentBuilder declares(ComponentPropertyBuilder...componentProperties); + +} diff --git a/tags/java/sca/1.0-RC1b/modules/assembly-java-dsl/src/main/java/org/apache/tuscany/sca/assembly/dsl/ComponentPropertyBuilder.java b/tags/java/sca/1.0-RC1b/modules/assembly-java-dsl/src/main/java/org/apache/tuscany/sca/assembly/dsl/ComponentPropertyBuilder.java new file mode 100644 index 0000000000..7f3c89fd2f --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly-java-dsl/src/main/java/org/apache/tuscany/sca/assembly/dsl/ComponentPropertyBuilder.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.dsl; + +public interface ComponentPropertyBuilder { + + ComponentPropertyBuilder ofType(String type); + + ComponentPropertyBuilder configuredTo(Object value); + +} diff --git a/tags/java/sca/1.0-RC1b/modules/assembly-java-dsl/src/main/java/org/apache/tuscany/sca/assembly/dsl/ComponentReferenceBuilder.java b/tags/java/sca/1.0-RC1b/modules/assembly-java-dsl/src/main/java/org/apache/tuscany/sca/assembly/dsl/ComponentReferenceBuilder.java new file mode 100644 index 0000000000..8966a4be9d --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly-java-dsl/src/main/java/org/apache/tuscany/sca/assembly/dsl/ComponentReferenceBuilder.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.dsl; + +public interface ComponentReferenceBuilder { + + ComponentReferenceBuilder wiredTo(String target); + + ComponentReferenceBuilder wiredTo(ComponentServiceBuilder target); + + ComponentReferenceBuilder typedBy(Class interfaceClass); + + ComponentReferenceBuilder promotedAs(String promoted); + + ComponentReferenceBuilder promoted(); + + ComponentReferenceBuilder boundTo(String uri); + +} diff --git a/tags/java/sca/1.0-RC1b/modules/assembly-java-dsl/src/main/java/org/apache/tuscany/sca/assembly/dsl/ComponentServiceBuilder.java b/tags/java/sca/1.0-RC1b/modules/assembly-java-dsl/src/main/java/org/apache/tuscany/sca/assembly/dsl/ComponentServiceBuilder.java new file mode 100644 index 0000000000..f3e36e8c38 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly-java-dsl/src/main/java/org/apache/tuscany/sca/assembly/dsl/ComponentServiceBuilder.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.dsl; + +public interface ComponentServiceBuilder { + + ComponentServiceBuilder typedBy(Class interfaceClass); + + ComponentServiceBuilder promotedAs(String promoted); + + ComponentServiceBuilder promoted(); + + ComponentServiceBuilder boundTo(String uri); + +} diff --git a/tags/java/sca/1.0-RC1b/modules/assembly-java-dsl/src/main/java/org/apache/tuscany/sca/assembly/dsl/CompositeBuilder.java b/tags/java/sca/1.0-RC1b/modules/assembly-java-dsl/src/main/java/org/apache/tuscany/sca/assembly/dsl/CompositeBuilder.java new file mode 100644 index 0000000000..e2108b5ef8 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly-java-dsl/src/main/java/org/apache/tuscany/sca/assembly/dsl/CompositeBuilder.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.dsl; + + +public interface CompositeBuilder { + + CompositeBuilder contains(ComponentBuilder... components); + + CompositeBuilder includes(CompositeBuilder... includes); + +} diff --git a/tags/java/sca/1.0-RC1b/modules/assembly-java-dsl/src/main/java/org/apache/tuscany/sca/assembly/dsl/impl/AssemblyBuilderImpl.java b/tags/java/sca/1.0-RC1b/modules/assembly-java-dsl/src/main/java/org/apache/tuscany/sca/assembly/dsl/impl/AssemblyBuilderImpl.java new file mode 100644 index 0000000000..0968310548 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly-java-dsl/src/main/java/org/apache/tuscany/sca/assembly/dsl/impl/AssemblyBuilderImpl.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.assembly.dsl.impl; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory; +import org.apache.tuscany.sca.assembly.dsl.AssemblyBuilder; +import org.apache.tuscany.sca.assembly.dsl.ComponentBuilder; +import org.apache.tuscany.sca.assembly.dsl.ComponentPropertyBuilder; +import org.apache.tuscany.sca.assembly.dsl.ComponentReferenceBuilder; +import org.apache.tuscany.sca.assembly.dsl.ComponentServiceBuilder; +import org.apache.tuscany.sca.assembly.dsl.CompositeBuilder; + +public class AssemblyBuilderImpl extends DefaultAssemblyFactory implements AssemblyBuilder { + + public ComponentBuilder component(String name) { + ComponentBuilderImpl component = new ComponentBuilderImpl(); + component.setName(name); + return component; + } + + public CompositeBuilder composite(String name) { + CompositeBuilderImpl composite = new CompositeBuilderImpl(); + //TODO handle namespace + composite.setName(new QName("", name)); + return composite; + } + + public CompositeBuilder domain(String uri) { + CompositeBuilderImpl composite = new CompositeBuilderImpl(); + composite.setName(new QName(uri, "")); + return composite; + } + + public ComponentPropertyBuilder property(String name) { + ComponentPropertyBuilderImpl property = new ComponentPropertyBuilderImpl(); + property.setName(name); + return property; + } + + public ComponentReferenceBuilder reference(String name) { + ComponentReferenceBuilderImpl reference = new ComponentReferenceBuilderImpl(this); + reference.setName(name); + return reference; + } + + public ComponentServiceBuilder service(String name) { + ComponentServiceBuilderImpl service = new ComponentServiceBuilderImpl(this); + service.setName(name); + return service; + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/assembly-java-dsl/src/main/java/org/apache/tuscany/sca/assembly/dsl/impl/ComponentBuilderImpl.java b/tags/java/sca/1.0-RC1b/modules/assembly-java-dsl/src/main/java/org/apache/tuscany/sca/assembly/dsl/impl/ComponentBuilderImpl.java new file mode 100644 index 0000000000..9022b9d9e6 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly-java-dsl/src/main/java/org/apache/tuscany/sca/assembly/dsl/impl/ComponentBuilderImpl.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.dsl.impl; + +import java.util.List; + +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.dsl.ComponentBuilder; +import org.apache.tuscany.sca.assembly.dsl.ComponentPropertyBuilder; +import org.apache.tuscany.sca.assembly.dsl.ComponentReferenceBuilder; +import org.apache.tuscany.sca.assembly.dsl.ComponentServiceBuilder; +import org.apache.tuscany.sca.assembly.dsl.CompositeBuilder; +import org.apache.tuscany.sca.assembly.impl.ComponentImpl; + +public class ComponentBuilderImpl extends ComponentImpl implements ComponentBuilder { + + public ComponentBuilderImpl() { + } + + public ComponentBuilder implementedBy(Class clazz) { + //FIXME support Java implementations + return this; + } + + public ComponentBuilder implementedBy(CompositeBuilder composite) { + setImplementation((Composite)composite); + return this; + } + + public ComponentBuilder uses(ComponentReferenceBuilder... componentReferences) { + List references = getReferences(); + for (ComponentReferenceBuilder componentReference: componentReferences) { + references.add((ComponentReference)componentReference); + } + return this; + } + + public ComponentBuilder provides(ComponentServiceBuilder... componentServices) { + List services = getServices(); + for (ComponentServiceBuilder componentService: componentServices) { + services.add((ComponentService)componentService); + } + return this; + } + + public ComponentBuilder declares(ComponentPropertyBuilder...componentProperties) { + List properties = getProperties(); + for (ComponentPropertyBuilder componentProperty: componentProperties) { + properties.add((ComponentProperty)componentProperty); + } + return this; + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/assembly-java-dsl/src/main/java/org/apache/tuscany/sca/assembly/dsl/impl/ComponentPropertyBuilderImpl.java b/tags/java/sca/1.0-RC1b/modules/assembly-java-dsl/src/main/java/org/apache/tuscany/sca/assembly/dsl/impl/ComponentPropertyBuilderImpl.java new file mode 100644 index 0000000000..49f7cd46b2 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly-java-dsl/src/main/java/org/apache/tuscany/sca/assembly/dsl/impl/ComponentPropertyBuilderImpl.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.dsl.impl; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.dsl.ComponentPropertyBuilder; +import org.apache.tuscany.sca.assembly.impl.ComponentPropertyImpl; + +public class ComponentPropertyBuilderImpl extends ComponentPropertyImpl implements ComponentPropertyBuilder { + + public ComponentPropertyBuilderImpl ofType(String type) { + //TODO handle namespace + this.setXSDType(new QName("", type)); + return this; + } + + public ComponentPropertyBuilderImpl configuredTo(Object value) { + this.setValue(value); + return this; + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/assembly-java-dsl/src/main/java/org/apache/tuscany/sca/assembly/dsl/impl/ComponentReferenceBuilderImpl.java b/tags/java/sca/1.0-RC1b/modules/assembly-java-dsl/src/main/java/org/apache/tuscany/sca/assembly/dsl/impl/ComponentReferenceBuilderImpl.java new file mode 100644 index 0000000000..d9aab9de22 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly-java-dsl/src/main/java/org/apache/tuscany/sca/assembly/dsl/impl/ComponentReferenceBuilderImpl.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.dsl.impl; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.ComponentService; +import org.apache.tuscany.sca.assembly.CompositeReference; +import org.apache.tuscany.sca.assembly.dsl.ComponentReferenceBuilder; +import org.apache.tuscany.sca.assembly.dsl.ComponentServiceBuilder; +import org.apache.tuscany.sca.assembly.impl.ComponentReferenceImpl; +import org.apache.tuscany.sca.assembly.impl.ComponentServiceImpl; + +public class ComponentReferenceBuilderImpl extends ComponentReferenceImpl implements ComponentReferenceBuilder { + + private CompositeReference compositeReference; + private AssemblyFactory assemblyFactory; + + protected ComponentReferenceBuilderImpl(AssemblyFactory assemblyFactory) { + this.assemblyFactory = assemblyFactory; + } + + public ComponentReferenceBuilder wiredTo(String target) { + ComponentService componentService = assemblyFactory.createComponentService(); + componentService.setUnresolved(true); + componentService.setName(target); + getTargets().add(componentService); + return this; + } + + public ComponentReferenceBuilder wiredTo(ComponentServiceBuilder target) { + getTargets().add((ComponentServiceImpl)target); + return this; + } + + public ComponentReferenceBuilderImpl typedBy(Class interfaceClass) { + //FIXME support for Java interfaces + return this; + } + + public ComponentReferenceBuilderImpl promotedAs(String promoted) { + compositeReference = assemblyFactory.createCompositeReference(); + compositeReference.setName(promoted); + return this; + } + + public ComponentReferenceBuilderImpl promoted() { + compositeReference = assemblyFactory.createCompositeReference(); + compositeReference.setName(getName()); + return this; + } + + public ComponentReferenceBuilder boundTo(String uri) { + //TODO support bindings + return this; + } + + CompositeReference getCompositeReference() { + return compositeReference; + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/assembly-java-dsl/src/main/java/org/apache/tuscany/sca/assembly/dsl/impl/ComponentServiceBuilderImpl.java b/tags/java/sca/1.0-RC1b/modules/assembly-java-dsl/src/main/java/org/apache/tuscany/sca/assembly/dsl/impl/ComponentServiceBuilderImpl.java new file mode 100644 index 0000000000..379429d17e --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly-java-dsl/src/main/java/org/apache/tuscany/sca/assembly/dsl/impl/ComponentServiceBuilderImpl.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.dsl.impl; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.CompositeService; +import org.apache.tuscany.sca.assembly.dsl.ComponentServiceBuilder; +import org.apache.tuscany.sca.assembly.impl.ComponentServiceImpl; + +public class ComponentServiceBuilderImpl extends ComponentServiceImpl implements ComponentServiceBuilder { + + private CompositeService compositeService; + private AssemblyFactory assemblyFactory; + + protected ComponentServiceBuilderImpl(AssemblyFactory assemblyFactory) { + this.assemblyFactory = assemblyFactory; + } + + public ComponentServiceBuilderImpl typedBy(Class interfaceClass) { + //FIXME support for Java interfaces + return this; + } + + public ComponentServiceBuilderImpl promotedAs(String promoted) { + compositeService = assemblyFactory.createCompositeService(); + compositeService.setName(promoted); + return this; + } + + public ComponentServiceBuilderImpl promoted() { + compositeService = assemblyFactory.createCompositeService(); + compositeService.setName(getName()); + return this; + } + + public ComponentServiceBuilder boundTo(String uri) { + // TODO support bindings + return this; + } + + CompositeService getCompositeService() { + return compositeService; + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/assembly-java-dsl/src/main/java/org/apache/tuscany/sca/assembly/dsl/impl/CompositeBuilderImpl.java b/tags/java/sca/1.0-RC1b/modules/assembly-java-dsl/src/main/java/org/apache/tuscany/sca/assembly/dsl/impl/CompositeBuilderImpl.java new file mode 100644 index 0000000000..709562cd72 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly-java-dsl/src/main/java/org/apache/tuscany/sca/assembly/dsl/impl/CompositeBuilderImpl.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.dsl.impl; + +import java.util.List; + +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.dsl.ComponentBuilder; +import org.apache.tuscany.sca.assembly.dsl.CompositeBuilder; +import org.apache.tuscany.sca.assembly.impl.CompositeImpl; + +public class CompositeBuilderImpl extends CompositeImpl implements CompositeBuilder { + + public CompositeBuilder contains(ComponentBuilder... componentBuilders) { + List components = getComponents(); + for (ComponentBuilder componentBuilder: componentBuilders) { + Component component = (Component)componentBuilder; + components.add(component); + + for (ComponentService componentService: component.getServices()) { + ComponentServiceBuilderImpl builder = (ComponentServiceBuilderImpl)componentService; + if (builder.getCompositeService() != null) + getServices().add(builder.getCompositeService()); + } + for (ComponentReference componentReference: component.getReferences()) { + ComponentReferenceBuilderImpl builder = (ComponentReferenceBuilderImpl)componentReference; + if (builder.getCompositeReference() != null) + getReferences().add(builder.getCompositeReference()); + } + } + return this; + } + + public CompositeBuilder includes(CompositeBuilder... compositeBuilders) { + List list = getIncludes(); + for (CompositeBuilder composite: compositeBuilders) { + list.add((Composite)composite); + } + return this; + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/assembly-java-dsl/src/test/java/org/apache/tuscany/sca/assembly/dsl/AccountDataService.java b/tags/java/sca/1.0-RC1b/modules/assembly-java-dsl/src/test/java/org/apache/tuscany/sca/assembly/dsl/AccountDataService.java new file mode 100644 index 0000000000..ba91fd2168 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly-java-dsl/src/test/java/org/apache/tuscany/sca/assembly/dsl/AccountDataService.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.assembly.dsl; + +public interface AccountDataService { + +} diff --git a/tags/java/sca/1.0-RC1b/modules/assembly-java-dsl/src/test/java/org/apache/tuscany/sca/assembly/dsl/AccountDataServiceImpl.java b/tags/java/sca/1.0-RC1b/modules/assembly-java-dsl/src/test/java/org/apache/tuscany/sca/assembly/dsl/AccountDataServiceImpl.java new file mode 100644 index 0000000000..4e239d03d3 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly-java-dsl/src/test/java/org/apache/tuscany/sca/assembly/dsl/AccountDataServiceImpl.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.assembly.dsl; + +public class AccountDataServiceImpl { + +} diff --git a/tags/java/sca/1.0-RC1b/modules/assembly-java-dsl/src/test/java/org/apache/tuscany/sca/assembly/dsl/AccountService.java b/tags/java/sca/1.0-RC1b/modules/assembly-java-dsl/src/test/java/org/apache/tuscany/sca/assembly/dsl/AccountService.java new file mode 100644 index 0000000000..030c820ed2 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly-java-dsl/src/test/java/org/apache/tuscany/sca/assembly/dsl/AccountService.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.assembly.dsl; + +public interface AccountService { + +} diff --git a/tags/java/sca/1.0-RC1b/modules/assembly-java-dsl/src/test/java/org/apache/tuscany/sca/assembly/dsl/AccountServiceImpl.java b/tags/java/sca/1.0-RC1b/modules/assembly-java-dsl/src/test/java/org/apache/tuscany/sca/assembly/dsl/AccountServiceImpl.java new file mode 100644 index 0000000000..92f448ec87 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly-java-dsl/src/test/java/org/apache/tuscany/sca/assembly/dsl/AccountServiceImpl.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.assembly.dsl; + +public class AccountServiceImpl { + +} diff --git a/tags/java/sca/1.0-RC1b/modules/assembly-java-dsl/src/test/java/org/apache/tuscany/sca/assembly/dsl/BigBankBuilder.java b/tags/java/sca/1.0-RC1b/modules/assembly-java-dsl/src/test/java/org/apache/tuscany/sca/assembly/dsl/BigBankBuilder.java new file mode 100644 index 0000000000..b856201551 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly-java-dsl/src/test/java/org/apache/tuscany/sca/assembly/dsl/BigBankBuilder.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.dsl; + +import org.apache.tuscany.sca.assembly.dsl.impl.AssemblyBuilderImpl; + +public class BigBankBuilder extends AssemblyBuilderImpl { + + public CompositeBuilder build() { + + CompositeBuilder bigbankAccount = composite("bigbank.account").contains( + + component("AccountServiceComponent"). + implementedBy(AccountServiceImpl.class). + uses( + reference("accountDataService").typedBy(AccountDataService.class).wiredTo("AccountDataServiceComponent/AccountDataService"), + reference("stockQuoteService").promotedAs("StockQuoteService") + ). + provides( + service("AccountDataService").typedBy(AccountService.class).promoted() + ). + declares( + property("currency").ofType("string").configuredTo("USD") + ), + + component("AccountDataServiceComponent"). + implementedBy(AccountDataServiceImpl.class). + provides( + service("AccountDataService").typedBy(AccountDataService.class) + ) + ); + + CompositeBuilder bigbankApp = composite("bigbank.app"). + contains( + component("BigBankAccount").implementedBy(bigbankAccount) + ); + + CompositeBuilder domain = domain("http://bigbank.org").includes(bigbankApp); + + return domain; + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/assembly-java-dsl/src/test/java/org/apache/tuscany/sca/assembly/dsl/BigBankBuilderTestCase.java b/tags/java/sca/1.0-RC1b/modules/assembly-java-dsl/src/test/java/org/apache/tuscany/sca/assembly/dsl/BigBankBuilderTestCase.java new file mode 100644 index 0000000000..90a4292546 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly-java-dsl/src/test/java/org/apache/tuscany/sca/assembly/dsl/BigBankBuilderTestCase.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.dsl; + +import junit.framework.TestCase; + +public class BigBankBuilderTestCase extends TestCase { + + public void testBuild() throws Exception { + + BigBankBuilder builder = new BigBankBuilder(); + CompositeBuilder domain = builder.build(); + assertNotNull(domain); + + //System.out.println(); + //new PrintUtil(System.out).print(domain); + //System.out.println(); + + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/assembly-java-dsl/src/test/java/org/apache/tuscany/sca/assembly/dsl/StockQuoteService.java b/tags/java/sca/1.0-RC1b/modules/assembly-java-dsl/src/test/java/org/apache/tuscany/sca/assembly/dsl/StockQuoteService.java new file mode 100644 index 0000000000..a0580095a0 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly-java-dsl/src/test/java/org/apache/tuscany/sca/assembly/dsl/StockQuoteService.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.assembly.dsl; + +public interface StockQuoteService { + +} diff --git a/tags/java/sca/1.0-RC1b/modules/assembly-xml/.checkstyle b/tags/java/sca/1.0-RC1b/modules/assembly-xml/.checkstyle new file mode 100644 index 0000000000..3e57539570 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly-xml/.checkstyle @@ -0,0 +1,24 @@ + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/assembly-xml/.pmd b/tags/java/sca/1.0-RC1b/modules/assembly-xml/.pmd new file mode 100644 index 0000000000..2db10d6a6a --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly-xml/.pmd @@ -0,0 +1,20 @@ + + +truefalse \ No newline at end of file diff --git a/tags/java/sca/1.0-RC1b/modules/assembly-xml/.ruleset b/tags/java/sca/1.0-RC1b/modules/assembly-xml/.ruleset new file mode 100644 index 0000000000..830b4cfee4 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly-xml/.ruleset @@ -0,0 +1,190 @@ + + + + PMD Plugin preferences rule set + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/assembly-xml/DISCLAIMER b/tags/java/sca/1.0-RC1b/modules/assembly-xml/DISCLAIMER new file mode 100644 index 0000000000..d68a410903 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly-xml/DISCLAIMER @@ -0,0 +1,8 @@ +Apache Tuscany is an effort undergoing incubation at The Apache Software +Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is +required of all newly accepted projects until a further review indicates that +the infrastructure, communications, and decision making process have stabilized +in a manner consistent with other successful ASF projects. While incubation +status is not necessarily a reflection of the completeness or stability of the +code, it does indicate that the project has yet to be fully endorsed by the ASF. + diff --git a/tags/java/sca/1.0-RC1b/modules/assembly-xml/LICENSE b/tags/java/sca/1.0-RC1b/modules/assembly-xml/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/assembly-xml/NOTICE b/tags/java/sca/1.0-RC1b/modules/assembly-xml/NOTICE new file mode 100644 index 0000000000..94481d6cfa --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly-xml/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2007 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/tags/java/sca/1.0-RC1b/modules/assembly-xml/pom.xml b/tags/java/sca/1.0-RC1b/modules/assembly-xml/pom.xml new file mode 100644 index 0000000000..8807632143 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly-xml/pom.xml @@ -0,0 +1,104 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.0-incubating + ../pom.xml + + tuscany-assembly-xml + Apache Tuscany SCA XML Assembly Model + + + + org.apache.tuscany.sca + tuscany-assembly + 1.0-incubating + + + + org.apache.tuscany.sca + tuscany-definitions + 1.0-incubating + test + + + + org.apache.tuscany.sca + tuscany-contribution + 1.0-incubating + + + + org.apache.tuscany.sca + tuscany-contribution-namespace + 1.0-incubating + + + + org.apache.tuscany.sca + tuscany-contribution-impl + 1.0-incubating + test + + + + org.apache.tuscany.sca + tuscany-policy + 1.0-incubating + + + + org.apache.tuscany.sca + tuscany-policy-xml + 1.0-incubating + test + + + + stax + stax-api + 1.0.1 + + + + org.codehaus.woodstox + wstx-asl + 3.2.1 + runtime + + + + xalan + xalan + 2.7.0 + + + + org.apache.tuscany.sca + tuscany-assembly-xsd + 1.0-incubating + test + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/BaseAssemblyProcessor.java b/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/BaseAssemblyProcessor.java new file mode 100644 index 0000000000..c3a55b9323 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/BaseAssemblyProcessor.java @@ -0,0 +1,597 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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.Binding; +import org.apache.tuscany.sca.assembly.ComponentService; +import org.apache.tuscany.sca.assembly.ComponentType; +import org.apache.tuscany.sca.assembly.ConstrainingType; +import org.apache.tuscany.sca.assembly.Contract; +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.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.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.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; +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 PolicyFactory policyFactory; + protected StAXArtifactProcessor extensionProcessor; + protected PolicyAttachPointProcessor policyProcessor; + private DocumentBuilderFactory documentBuilderFactory; + + /** + * Construcst a new BaseArtifactProcessor. + * @param contribFactory + * @param factory + * @param policyFactory + */ + @SuppressWarnings("unchecked") + public BaseAssemblyProcessor(ContributionFactory contribFactory, + AssemblyFactory factory, + PolicyFactory policyFactory, + StAXArtifactProcessor extensionProcessor) { + this.assemblyFactory = factory; + this.policyFactory = policyFactory; + this.extensionProcessor = (StAXArtifactProcessor)extensionProcessor; + this.contributionFactory = contribFactory; + this.policyProcessor = new PolicyAttachPointProcessor(policyFactory); + } + + /** + * Construcst a new BaseArtifactProcessor. + * @param factory + * @param policyFactory + */ + @SuppressWarnings("unchecked") + public BaseAssemblyProcessor(AssemblyFactory factory, + PolicyFactory policyFactory, + StAXArtifactProcessor extensionProcessor) { + this.assemblyFactory = factory; + this.policyFactory = policyFactory; + this.extensionProcessor = (StAXArtifactProcessor)extensionProcessor; + this.policyProcessor = new PolicyAttachPointProcessor(policyFactory); + } + + /** + * 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); + } + } + + /** + * 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 { + 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()) { + resolver.addModel(implementation); + } + } + + if (implementation instanceof PolicySetAttachPoint) { + resolveIntents(((PolicySetAttachPoint)implementation).getRequiredIntents(), resolver); + resolvePolicySets(((PolicySetAttachPoint)implementation).getPolicySets(), resolver); + } + } + } + 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 { + for (Contract contract : contracts) { + // 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; + resolveIntents(policiedBinding.getRequiredIntents(), resolver); + } + if (binding instanceof PolicySetAttachPoint) { + PolicySetAttachPoint policiedBinding = (PolicySetAttachPoint)binding; + resolvePolicySets(policiedBinding.getPolicySets(), resolver); + } + } + + // Resolve callback bindings + if (contract.getCallback() != null) { + resolveIntents(contract.getCallback().getRequiredIntents(), resolver); + resolvePolicySets(contract.getCallback().getPolicySets(), resolver); + 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; + resolveIntents(policiedBinding.getRequiredIntents(), resolver); + } + if (binding instanceof PolicySetAttachPoint) { + PolicySetAttachPoint policiedBinding = (PolicySetAttachPoint)binding; + resolvePolicySets(policiedBinding.getPolicySets(), resolver); + } + } + } + + resolveIntents(contract.getRequiredIntents(), resolver); + resolvePolicySets(contract.getPolicySets(), resolver); + } + } + + /** + * 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) { + throw new ContributionReadException(e); + } + + // 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) { + resolvedPolicySet = resolver.resolveModel(PolicySet.class, policySet); + resolvedPolicySets.add(resolvedPolicySet); + } + 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) { + if (nodeList.item(item).getNodeType() == Node.ELEMENT_NODE) { + XMLStreamReader reader = + XMLInputFactory.newInstance().createXMLStreamReader(new DOMSource(nodeList.item(item))); + + 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/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ComponentTypeDocumentProcessor.java b/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ComponentTypeDocumentProcessor.java new file mode 100644 index 0000000000..2ccc5880aa --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ComponentTypeDocumentProcessor.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.xml; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.net.URL; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.validation.Schema; + +import org.apache.tuscany.sca.assembly.ComponentType; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.ValidatingXMLStreamReader; +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; + private Schema schema; + + /** + * Constructs a new componentType processor. + * @param factory + * @param policyFactory + * @param registry + */ + public ComponentTypeDocumentProcessor(StAXArtifactProcessor staxProcessor, XMLInputFactory inputFactory, Schema schema) { + super(null, null, staxProcessor); + this.inputFactory = inputFactory; + this.schema = schema; + } + + public ComponentType read(URL contributionURL, URI uri, URL url) throws ContributionReadException { + InputStream urlStream = null; + try { + + // Create a stream reader + urlStream = url.openStream(); + XMLStreamReader reader = inputFactory.createXMLStreamReader(url.toString(), urlStream); + reader = new ValidatingXMLStreamReader(reader, schema); + 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) { + throw new ContributionReadException(e); + } catch (IOException e) { + throw new ContributionReadException(e); + } 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/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ComponentTypeModelResolver.java b/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ComponentTypeModelResolver.java new file mode 100644 index 0000000000..24e41a3177 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ComponentTypeModelResolver.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.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.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; + +/** + * A Model Resolver for ComponentType models. + * + * @version $Rev$ $Date$ + */ +public class ComponentTypeModelResolver implements ModelResolver { + + private Map map = new HashMap(); + + public ComponentTypeModelResolver(Contribution contribution, ModelFactoryExtensionPoint modelFactories) { + } + + 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) { + + // Lookup a definition for the given namespace + String uri = ((ComponentType)unresolved).getURI(); + ComponentType resolved = (ComponentType) map.get(uri); + if (resolved != null) { + return modelClass.cast(resolved); + } else { + return (T)unresolved; + } + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ComponentTypeProcessor.java b/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ComponentTypeProcessor.java new file mode 100644 index 0000000000..4915ae2906 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ComponentTypeProcessor.java @@ -0,0 +1,354 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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.Property; +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.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.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 factory + * @param policyFactory + * @param registry + */ + public ComponentTypeProcessor(AssemblyFactory factory, PolicyFactory policyFactory, StAXArtifactProcessor extensionProcessor) { + super(factory, policyFactory, extensionProcessor); + } + + public ComponentType read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + ComponentType componentType = null; + Service service = null; + Reference reference = null; + Contract contract = null; + Property property = null; + Callback callback = null; + QName name = null; + + // 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.equals(name)) { + + // Read an + Operation operation = assemblyFactory.createOperation(); + 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(); + } + } + 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()), + 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/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeDocumentProcessor.java b/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeDocumentProcessor.java new file mode 100644 index 0000000000..d45c257714 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeDocumentProcessor.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.xml; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.net.URL; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.validation.Schema; + +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.ValidatingXMLStreamReader; +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 composite processor. + * + * @version $Rev$ $Date$ + */ +public class CompositeDocumentProcessor extends BaseAssemblyProcessor implements URLArtifactProcessor { + private XMLInputFactory inputFactory; + private Schema schema; + + /** + * Construct a new composite processor + * @param assemblyFactory + * @param policyFactory + * @param staxProcessor + */ + public CompositeDocumentProcessor(StAXArtifactProcessor staxProcessor, XMLInputFactory inputFactory, Schema schema) { + super(null, null, staxProcessor); + this.inputFactory = inputFactory; + this.schema = schema; + } + + public Composite read(URL contributionURL, URI uri, URL url) throws ContributionReadException { + InputStream urlStream = null; + try { + + // Create a stream reader + urlStream = url.openStream(); + XMLStreamReader reader = inputFactory.createXMLStreamReader(url.toString(), urlStream); + reader = new ValidatingXMLStreamReader(reader, schema); + reader.nextTag(); + + // Read the composite model + Composite 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) { + throw new ContributionReadException(e); + } catch (IOException e) { + throw new ContributionReadException(e); + } finally { + try { + if (urlStream != null) { + urlStream.close(); + urlStream = null; + } + } catch (IOException ioe) { + //ignore + } + } + } + + public void resolve(Composite composite, ModelResolver resolver) throws ContributionResolveException { + extensionProcessor.resolve(composite, resolver); + } + + public String getArtifactType() { + return ".composite"; + } + + public Class getModelType() { + return Composite.class; + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeModelResolver.java b/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeModelResolver.java new file mode 100644 index 0000000000..72744259f6 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeProcessor.java b/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeProcessor.java new file mode 100644 index 0000000000..c7ae5683fd --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeProcessor.java @@ -0,0 +1,766 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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.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 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.ConstrainingType; +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.Service; +import org.apache.tuscany.sca.assembly.Wire; +import org.apache.tuscany.sca.contribution.ContributionFactory; +import org.apache.tuscany.sca.contribution.DeployedArtifact; +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.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.policy.PolicyFactory; +import org.apache.tuscany.sca.policy.PolicySetAttachPoint; +import org.w3c.dom.Document; + +/** + * A composite processor. + * + * @version $Rev$ $Date$ + */ +public class CompositeProcessor extends BaseAssemblyProcessor implements StAXArtifactProcessor { + + /** + * Construct a new composite processor + * + * @param contributionFactory + * @param assemblyFactory + * @param policyFactory + * @param extensionProcessor + */ + public CompositeProcessor(ContributionFactory contributionFactory, + AssemblyFactory factory, + PolicyFactory policyFactory, + InterfaceContractMapper interfaceContractMapper, + StAXArtifactProcessor extensionProcessor) { + super(contributionFactory, factory, policyFactory, extensionProcessor); + } + + /** + * Construct a new composite processor + * + * @param assemblyFactory + * @param policyFactory + * @param extensionProcessor public CompositeProcessor(AssemblyFactory + * factory, PolicyFactory policyFactory, InterfaceContractMapper + * interfaceContractMapper, StAXArtifactProcessor + * extensionProcessor) { super(factory, policyFactory, + * extensionProcessor); } + */ + + public Composite read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + 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; + + // 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, AUTOWIRE)) { + composite.setAutowire(getBoolean(reader, AUTOWIRE)); + } + 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.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)); + 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); + 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); + + 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)); + 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)); + composite.getReferences().add(compositeReference); + policyProcessor.readPolicies(contract, reader); + } + + } else if (PROPERTY_QNAME.equals(name)) { + if (component != null) { + + // Read a + componentProperty = assemblyFactory.createComponentProperty(); + property = componentProperty; + componentProperty.setSource(getString(reader, SOURCE)); + componentProperty.setFile(getString(reader, FILE)); + 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); + } + + } 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)); + } + 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); + + composite.getWires().add(wire); + policyProcessor.readPolicies(wire, reader); + + } else if (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 = assemblyFactory.createOperation(); + operation.setName(getString(reader, NAME)); + operation.setUnresolved(true); + if (callback != null) { + policyProcessor.readPolicies(callback, operation, reader); + } else { + policyProcessor.readPolicies(contract, operation, reader); + } + } else if (IMPLEMENTATION_COMPOSITE_QNAME.equals(name)) { + + // Read an implementation.composite + Composite implementation = assemblyFactory.createComposite(); + implementation.setName(getQName(reader, NAME)); + implementation.setUnresolved(true); + 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)) { + throw new ContributionReadException( + "Unexpected element found. It should appear inside a or element"); + } else { + composite.getExtensions().add(extension); + } + } + + } else if (extension instanceof Binding) { + // 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)) { + throw new ContributionReadException( + "Unexpected element found. It should appear inside a or element"); + } else { + composite.getExtensions().add(extension); + } + } + } + + } else if (extension instanceof Implementation) { + + // + if (component != null) { + component.setImplementation((Implementation)extension); + } else { + if (name.getNamespaceURI().equals(SCA10_NS)) { + 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(); + } + } + 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(AUTOWIRE, composite.getAutowire()), + policyProcessor.writePolicies(composite)); + + // 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.getService(); + } else { + promote = promotedComponent.getName(); + } + } else { + promote = null; + } + writeStart(writer, SERVICE, new XAttr(NAME, service.getName()), new XAttr(PROMOTE, promote), + policyProcessor.writePolicies(service)); + + // 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 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 elements + for (ComponentService service : component.getServices()) { + writeStart(writer, SERVICE, new XAttr(NAME, service.getName()), + policyProcessor.writePolicies(service)); + + // 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 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()) { + writeStart(writer, REFERENCE, new XAttr(NAME, reference.getName()), + new XAttr(AUTOWIRE, reference.getAutowire()), + writeTargets(reference), + policyProcessor.writePolicies(reference)); + + // 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 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 property value + writePropertyValue(property.getValue(), property.getXSDElement(), property.getXSDType(), writer); + + // Write extensions + for (Object extension : property.getExtensions()) { + extensionProcessor.write(extension, writer); + } + + writeEnd(writer); + } + + // Write the component implementation + Implementation implementation = component.getImplementation(); + if (implementation instanceof Composite) { + writeStart(writer, IMPLEMENTATION_COMPOSITE, new XAttr(NAME, composite.getName())); + writeEnd(writer); + } else { + extensionProcessor.write(component.getImplementation(), 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), + policyProcessor.writePolicies(reference)); + + // 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 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 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 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 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); + } + + Implementation implementation = component.getImplementation(); + if (implementation != null) { + implementation = resolveImplementation(implementation, resolver); + component.setImplementation(implementation); + } + + for (ComponentProperty componentProperty : component.getProperties()) { + if (componentProperty.getFile() != null) { + DeployedArtifact deployedArtifact = contributionFactory.createDeployedArtifact(); + deployedArtifact.setURI(componentProperty.getFile()); + deployedArtifact = resolver.resolveModel(DeployedArtifact.class, deployedArtifact); + if (deployedArtifact.getLocation() != null) { + componentProperty.setFile(deployedArtifact.getLocation()); + } + } + } + resolveIntents(component.getRequiredIntents(), resolver); + resolvePolicySets(component.getPolicySets(), resolver); + resolveContracts(component.getServices(), resolver); + resolveContracts(component.getReferences(), resolver); + } + + // Resolve composite services and references + resolveContracts(composite.getServices(), resolver); + resolveContracts(composite.getReferences(), resolver); + if (composite instanceof PolicySetAttachPoint) { + resolveIntents(((PolicySetAttachPoint)composite).getRequiredIntents(), resolver); + resolvePolicySets(((PolicySetAttachPoint)composite).getPolicySets(), resolver); + } + } + + public QName getArtifactType() { + return COMPOSITE_QNAME; + } + + public Class getModelType() { + return Composite.class; + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/Constants.java b/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/Constants.java new file mode 100644 index 0000000000..80ab8d1b70 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/Constants.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 javax.xml.namespace.QName; + +/** + * Constants used in SCA assembly XML files. + */ +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 NAME = "name"; + String TARGET_NAMESPACE = "targetNamespace"; + String LOCAL = "local"; + String AUTOWIRE = "autowire"; + String REQUIRES = "requires"; + String POLICY_SETS = "policySets"; + 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/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConstrainingTypeDocumentProcessor.java b/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConstrainingTypeDocumentProcessor.java new file mode 100644 index 0000000000..49f1c7c51b --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConstrainingTypeDocumentProcessor.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.xml; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.net.URL; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.validation.Schema; + +import org.apache.tuscany.sca.assembly.ConstrainingType; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.ValidatingXMLStreamReader; +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 contrainingType content handler. + * + * @version $Rev$ $Date$ + */ +public class ConstrainingTypeDocumentProcessor extends BaseAssemblyProcessor implements URLArtifactProcessor { + private XMLInputFactory inputFactory; + private Schema schema; + + /** + * Construct a new constrainingType processor. + * @param factory + * @param policyFactory + * @param staxProcessor + */ + public ConstrainingTypeDocumentProcessor(StAXArtifactProcessor staxProcessor, XMLInputFactory inputFactory, Schema schema) { + super(null, null, staxProcessor); + this.inputFactory = inputFactory; + this.schema = schema; + } + + public ConstrainingType read(URL contributionURL, URI uri, URL url) throws ContributionReadException { + InputStream urlStream = null; + try { + + // Create a stream reader + urlStream = url.openStream(); + XMLStreamReader reader = inputFactory.createXMLStreamReader(url.toString(), urlStream); + reader = new ValidatingXMLStreamReader(reader, schema); + 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) { + throw new ContributionReadException(e); + } catch (IOException e) { + throw new ContributionReadException(e); + } 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/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConstrainingTypeModelResolver.java b/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConstrainingTypeModelResolver.java new file mode 100644 index 0000000000..7dd95e3944 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConstrainingTypeProcessor.java b/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConstrainingTypeProcessor.java new file mode 100644 index 0000000000..d82327b9dd --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConstrainingTypeProcessor.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.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.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.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.Operation; +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 factory + * @param policyFactory + * @param extensionProcessor + */ + public ConstrainingTypeProcessor(AssemblyFactory factory, PolicyFactory policyFactory, StAXArtifactProcessor extensionProcessor) { + super(factory, policyFactory, extensionProcessor); + } + + public ConstrainingType read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + ConstrainingType constrainingType = null; + AbstractService abstractService = null; + AbstractReference abstractReference = null; + AbstractProperty abstractProperty = null; + AbstractContract abstractContract = null; + QName name = null; + + // 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.equals(name)) { + + // Read an + Operation operation = assemblyFactory.createOperation(); + 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(); + } + } + 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()), + 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/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/DefaultBeanModelProcessor.java b/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/DefaultBeanModelProcessor.java new file mode 100644 index 0000000000..6bc190aaf5 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/DefaultBeanModelProcessor.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.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.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.policy.PolicyFactory; +import org.apache.tuscany.sca.policy.PolicySetAttachPoint; + +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, + PolicyFactory policyFactory, + QName artifactType, + Class modelClass, + Object modelFactory) { + super(assemblyFactory, policyFactory, null); + 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 Object 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 model; + + } catch (Exception e) { + throw new ContributionReadException(e); + } + } + + public void write(Object 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) { + throw new ContributionWriteException(e); + } + } + + public void resolve(Object 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/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/PolicyAttachPointProcessor.java b/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/PolicyAttachPointProcessor.java new file mode 100644 index 0000000000..711283088e --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/PolicyAttachPointProcessor.java @@ -0,0 +1,255 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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.assembly.Binding; +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.IntentAttachPointType; +import org.apache.tuscany.sca.policy.PolicyFactory; +import org.apache.tuscany.sca.policy.PolicySet; +import org.apache.tuscany.sca.policy.PolicySetAttachPoint; + +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); + } + } + } + + /** + * 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 + * @param attachPoint + * @return + */ + public void writePolicyPrefixes(Object attachPoint, XMLStreamWriter writer) throws XMLStreamException { + writePolicyPrefixes(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 instanceof Binding ) { + if ( policySetAttachPoint.getType().isUnresolved() ) { + IntentAttachPointType resolved = + resolver.resolveModel(IntentAttachPointType.class, policySetAttachPoint.getType()); + policySetAttachPoint.setType(resolved); + } + } + + 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/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/BuildPolicyTestCase.java b/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/BuildPolicyTestCase.java new file mode 100644 index 0000000000..17069783b2 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/BuildPolicyTestCase.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.xml; + +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.Composite; +import org.apache.tuscany.sca.assembly.ConstrainingType; +import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory; +import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; +import org.apache.tuscany.sca.assembly.builder.impl.CompositeBuilderImpl; +import org.apache.tuscany.sca.contribution.DefaultModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.impl.ContributionFactoryImpl; +import org.apache.tuscany.sca.contribution.processor.DefaultStAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.DefaultURLArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.ExtensibleURLArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.definitions.SCADefinitions; +import org.apache.tuscany.sca.definitions.SCADefinitionsDocumentProcessor; +import org.apache.tuscany.sca.definitions.SCADefinitionsProcessor; +import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; +import org.apache.tuscany.sca.interfacedef.impl.InterfaceContractMapperImpl; +import org.apache.tuscany.sca.policy.DefaultPolicyFactory; +import org.apache.tuscany.sca.policy.IntentAttachPoint; +import org.apache.tuscany.sca.policy.PolicyFactory; +import org.apache.tuscany.sca.policy.xml.PolicySetProcessor; +import org.apache.tuscany.sca.policy.xml.ProfileIntentProcessor; +import org.apache.tuscany.sca.policy.xml.QualifiedIntentProcessor; +import org.apache.tuscany.sca.policy.xml.SimpleIntentProcessor; + +/** + * 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 ExtensibleURLArtifactProcessor documentProcessor; + private TestModelResolver resolver; + SCADefinitionsDocumentProcessor scaDefnDocProcessor; + CompositeBuilder compositeBuilder; + Composite composite = null; + + @Override + public void setUp() throws Exception { + AssemblyFactory factory = new DefaultAssemblyFactory(); + PolicyFactory policyFactory = new DefaultPolicyFactory(); + InterfaceContractMapper mapper = new InterfaceContractMapperImpl(); + resolver = new TestModelResolver(); + compositeBuilder = new CompositeBuilderImpl(factory, new TestSCABindingFactoryImpl(), new InterfaceContractMapperImpl(), null, null); + URLArtifactProcessorExtensionPoint documentProcessors = new DefaultURLArtifactProcessorExtensionPoint(new DefaultModelFactoryExtensionPoint()); + documentProcessor = new ExtensibleURLArtifactProcessor(documentProcessors); + + // Create Stax processors + DefaultStAXArtifactProcessorExtensionPoint staxProcessors = new DefaultStAXArtifactProcessorExtensionPoint(new DefaultModelFactoryExtensionPoint()); + ExtensibleStAXArtifactProcessor staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, XMLInputFactory.newInstance(), XMLOutputFactory.newInstance()); + staxProcessors.addArtifactProcessor(new CompositeProcessor(new ContributionFactoryImpl(), factory, policyFactory, mapper, staxProcessor)); + staxProcessors.addArtifactProcessor(new ComponentTypeProcessor(factory, policyFactory, staxProcessor)); + staxProcessors.addArtifactProcessor(new ConstrainingTypeProcessor(factory, policyFactory, staxProcessor)); + staxProcessors.addArtifactProcessor(new SCADefinitionsProcessor(policyFactory, staxProcessor, resolver)); + staxProcessors.addArtifactProcessor(new SimpleIntentProcessor(policyFactory, staxProcessor)); + staxProcessors.addArtifactProcessor(new ProfileIntentProcessor(policyFactory, staxProcessor)); + staxProcessors.addArtifactProcessor(new QualifiedIntentProcessor(policyFactory, staxProcessor)); + staxProcessors.addArtifactProcessor(new PolicySetProcessor(policyFactory, staxProcessor)); + staxProcessors.addArtifactProcessor(new MockPolicyProcessor()); + + XMLInputFactory inputFactory = XMLInputFactory.newInstance(); + + // Create document processors + documentProcessors.addArtifactProcessor(new CompositeDocumentProcessor(staxProcessor, inputFactory, null)); + documentProcessors.addArtifactProcessor(new ComponentTypeDocumentProcessor(staxProcessor, inputFactory, null)); + documentProcessors.addArtifactProcessor(new ConstrainingTypeDocumentProcessor(staxProcessor, inputFactory, null)); + scaDefnDocProcessor = new SCADefinitionsDocumentProcessor(staxProcessors, staxProcessor, inputFactory, policyFactory, null); + documentProcessors.addArtifactProcessor(scaDefnDocProcessor); + + 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("AnotherDefinitions.xml"); + uri = URI.create("AnotherDefinitions.xml"); + SCADefinitions scaDefns = (SCADefinitions)scaDefnDocProcessor.read(null, uri, url); + assertNotNull(scaDefns); + + //preResolvePolicyTests(composite); + documentProcessor.resolve(scaDefns, resolver); + documentProcessor.resolve(composite, resolver); + //postResolvePolicyTests(composite); + + compositeBuilder.build(composite); + } + + @Override + public void tearDown() throws Exception { + documentProcessor = null; + resolver = null; + } + + 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 for the promoted service (4) + assertEquals(composite.getServices().get(0).getRequiredIntents().size(), 4); + 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(composite.getReferences().get(0).getRequiredIntents().size(), 2); + 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(), 2); + + 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).getReferences().get(0).getRequiredIntents().size(), 5); + + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/MockPolicyProcessor.java b/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/MockPolicyProcessor.java new file mode 100644 index 0000000000..e435f7ce0a --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/MockPolicyProcessor.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.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; + +/** + * @author administrator + * + */ +public class MockPolicyProcessor 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/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadAllTestCase.java b/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadAllTestCase.java new file mode 100644 index 0000000000..8b42bd03db --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadAllTestCase.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.xml; + +import java.io.InputStream; + +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.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.DefaultAssemblyFactory; +import org.apache.tuscany.sca.assembly.Property; +import org.apache.tuscany.sca.contribution.ContributionFactory; +import org.apache.tuscany.sca.contribution.DefaultModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.impl.ContributionFactoryImpl; +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.interfacedef.InterfaceContractMapper; +import org.apache.tuscany.sca.interfacedef.impl.InterfaceContractMapperImpl; +import org.apache.tuscany.sca.policy.DefaultPolicyFactory; +import org.apache.tuscany.sca.policy.PolicyFactory; +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 ExtensibleStAXArtifactProcessor staxProcessor; + + @Override + public void setUp() throws Exception { + AssemblyFactory factory = new DefaultAssemblyFactory(); + PolicyFactory policyFactory = new DefaultPolicyFactory(); + InterfaceContractMapper mapper = new InterfaceContractMapperImpl(); + ContributionFactory contributionFactory = new ContributionFactoryImpl(); + + StAXArtifactProcessorExtensionPoint staxProcessors = new DefaultStAXArtifactProcessorExtensionPoint(new DefaultModelFactoryExtensionPoint()); + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, XMLInputFactory.newInstance(), XMLOutputFactory.newInstance()); + + staxProcessors.addArtifactProcessor(new CompositeProcessor(contributionFactory, factory, policyFactory, mapper, staxProcessor)); + staxProcessors.addArtifactProcessor(new ComponentTypeProcessor(factory, policyFactory, staxProcessor)); + staxProcessors.addArtifactProcessor(new ConstrainingTypeProcessor(factory, policyFactory, staxProcessor)); + } + + @Override + public void tearDown() throws Exception { + } + + public void testReadComposite() throws Exception { + InputStream is = getClass().getResourceAsStream("TestAllCalculator.composite"); + Composite composite = (Composite)staxProcessor.read(is, Composite.class); + 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 + + //new PrintUtil(System.out).print(composite); + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadDocumentTestCase.java b/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadDocumentTestCase.java new file mode 100644 index 0000000000..de2452fde8 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadDocumentTestCase.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.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.stream.XMLOutputFactory; +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.AssemblyFactory; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.ConstrainingType; +import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory; +import org.apache.tuscany.sca.contribution.DefaultModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.impl.ContributionFactoryImpl; +import org.apache.tuscany.sca.contribution.processor.DefaultStAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.DefaultURLArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.ExtensibleURLArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; +import org.apache.tuscany.sca.interfacedef.impl.InterfaceContractMapperImpl; +import org.apache.tuscany.sca.policy.DefaultPolicyFactory; +import org.apache.tuscany.sca.policy.PolicyFactory; +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 ExtensibleURLArtifactProcessor documentProcessor; + private TestModelResolver resolver; + private XMLInputFactory inputFactory; + private ExtensibleStAXArtifactProcessor staxProcessor; + + @Override + public void setUp() throws Exception { + AssemblyFactory factory = new DefaultAssemblyFactory(); + PolicyFactory policyFactory = new DefaultPolicyFactory(); + InterfaceContractMapper mapper = new InterfaceContractMapperImpl(); + + URLArtifactProcessorExtensionPoint documentProcessors = new DefaultURLArtifactProcessorExtensionPoint(new DefaultModelFactoryExtensionPoint()); + documentProcessor = new ExtensibleURLArtifactProcessor(documentProcessors); + + // Create Stax processors + DefaultStAXArtifactProcessorExtensionPoint staxProcessors = new DefaultStAXArtifactProcessorExtensionPoint(new DefaultModelFactoryExtensionPoint()); + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, XMLInputFactory.newInstance(), XMLOutputFactory.newInstance()); + staxProcessors.addArtifactProcessor(new CompositeProcessor(new ContributionFactoryImpl(), factory, policyFactory, mapper, staxProcessor)); + staxProcessors.addArtifactProcessor(new ComponentTypeProcessor(factory, policyFactory, staxProcessor)); + staxProcessors.addArtifactProcessor(new ConstrainingTypeProcessor(factory, policyFactory, staxProcessor)); + + inputFactory = XMLInputFactory.newInstance(); + documentProcessors.addArtifactProcessor(new CompositeDocumentProcessor(staxProcessor, inputFactory, null)); + documentProcessors.addArtifactProcessor(new ComponentTypeDocumentProcessor(staxProcessor, inputFactory, null)); + documentProcessors.addArtifactProcessor(new ConstrainingTypeDocumentProcessor(staxProcessor, inputFactory, null)); + + resolver = new TestModelResolver(); + } + + @Override + public void tearDown() throws Exception { + } + + 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 { + + 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")); + + CompositeDocumentProcessor compositeDocumentProcessor = new CompositeDocumentProcessor(staxProcessor, inputFactory, schema); + + 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 { + + 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")); + + CompositeDocumentProcessor compositeDocumentProcessor = new CompositeDocumentProcessor(staxProcessor, inputFactory, schema); + + 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/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadTestCase.java b/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadTestCase.java new file mode 100644 index 0000000000..81c244a6d5 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadTestCase.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.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.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory; +import org.apache.tuscany.sca.contribution.DefaultModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.impl.ContributionFactoryImpl; +import org.apache.tuscany.sca.contribution.processor.DefaultStAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; +import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; +import org.apache.tuscany.sca.interfacedef.impl.InterfaceContractMapperImpl; +import org.apache.tuscany.sca.policy.DefaultPolicyFactory; +import org.apache.tuscany.sca.policy.PolicyFactory; + +/** + * Test reading SCA XML assemblies. + * + * @version $Rev$ $Date$ + */ +public class ReadTestCase extends TestCase { + + private XMLInputFactory inputFactory; + private DefaultStAXArtifactProcessorExtensionPoint staxProcessors; + private ExtensibleStAXArtifactProcessor staxProcessor; + private AssemblyFactory factory; + private PolicyFactory policyFactory; + private InterfaceContractMapper mapper; + + @Override + public void setUp() throws Exception { + factory = new DefaultAssemblyFactory(); + policyFactory = new DefaultPolicyFactory(); + mapper = new InterfaceContractMapperImpl(); + inputFactory = XMLInputFactory.newInstance(); + staxProcessors = new DefaultStAXArtifactProcessorExtensionPoint(new DefaultModelFactoryExtensionPoint()); + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, XMLInputFactory.newInstance(), XMLOutputFactory.newInstance()); + } + + @Override + public void tearDown() throws Exception { + } + + public void testReadComponentType() throws Exception { + ComponentTypeProcessor componentTypeReader = new ComponentTypeProcessor(factory, policyFactory, staxProcessor); + InputStream is = getClass().getResourceAsStream("CalculatorImpl.componentType"); + XMLStreamReader reader = inputFactory.createXMLStreamReader(is); + assertNotNull(componentTypeReader.read(reader)); + is.close(); + } + + public void testReadConstrainingType() throws Exception { + InputStream is = getClass().getResourceAsStream("CalculatorComponent.constrainingType"); + ConstrainingTypeProcessor constrainingTypeReader = new ConstrainingTypeProcessor(factory, policyFactory, staxProcessor); + XMLStreamReader reader = inputFactory.createXMLStreamReader(is); + assertNotNull(constrainingTypeReader.read(reader)); + is.close(); + + } + + public void testReadComposite() throws Exception { + InputStream is = getClass().getResourceAsStream("Calculator.composite"); + CompositeProcessor compositeReader = new CompositeProcessor(new ContributionFactoryImpl(), factory, policyFactory, mapper, staxProcessor); + XMLStreamReader reader = inputFactory.createXMLStreamReader(is); + assertNotNull(compositeReader.read(reader)); + is.close(); + + } + + public void testReadCompositeAndWireIt() throws Exception { + InputStream is = getClass().getResourceAsStream("Calculator.composite"); + CompositeProcessor compositeReader = new CompositeProcessor(new ContributionFactoryImpl(), factory, policyFactory, mapper, staxProcessor); + XMLStreamReader reader = inputFactory.createXMLStreamReader(is); + assertNotNull(compositeReader.read(reader)); + is.close(); + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ResolvePolicyTestCase.java b/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ResolvePolicyTestCase.java new file mode 100644 index 0000000000..0c2b686016 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ResolvePolicyTestCase.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.assembly.xml; + +import java.net.URI; +import java.net.URL; + +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.Composite; +import org.apache.tuscany.sca.assembly.ConstrainingType; +import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory; +import org.apache.tuscany.sca.contribution.DefaultModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.impl.ContributionFactoryImpl; +import org.apache.tuscany.sca.contribution.processor.DefaultStAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.DefaultURLArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.ExtensibleURLArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.definitions.SCADefinitions; +import org.apache.tuscany.sca.definitions.SCADefinitionsDocumentProcessor; +import org.apache.tuscany.sca.definitions.SCADefinitionsProcessor; +import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; +import org.apache.tuscany.sca.interfacedef.impl.InterfaceContractMapperImpl; +import org.apache.tuscany.sca.policy.DefaultPolicyFactory; +import org.apache.tuscany.sca.policy.PolicyFactory; +import org.apache.tuscany.sca.policy.PolicySetAttachPoint; +import org.apache.tuscany.sca.policy.xml.PolicySetProcessor; +import org.apache.tuscany.sca.policy.xml.ProfileIntentProcessor; +import org.apache.tuscany.sca.policy.xml.QualifiedIntentProcessor; +import org.apache.tuscany.sca.policy.xml.SimpleIntentProcessor; + +/** + * 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 ExtensibleURLArtifactProcessor documentProcessor; + private TestModelResolver resolver; + SCADefinitionsDocumentProcessor scaDefnDocProcessor; + + @Override + public void setUp() throws Exception { + AssemblyFactory factory = new DefaultAssemblyFactory(); + PolicyFactory policyFactory = new DefaultPolicyFactory(); + InterfaceContractMapper mapper = new InterfaceContractMapperImpl(); + resolver = new TestModelResolver(); + + URLArtifactProcessorExtensionPoint documentProcessors = new DefaultURLArtifactProcessorExtensionPoint(new DefaultModelFactoryExtensionPoint()); + documentProcessor = new ExtensibleURLArtifactProcessor(documentProcessors); + + // Create Stax processors + DefaultStAXArtifactProcessorExtensionPoint staxProcessors = new DefaultStAXArtifactProcessorExtensionPoint(new DefaultModelFactoryExtensionPoint()); + ExtensibleStAXArtifactProcessor staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, XMLInputFactory.newInstance(), XMLOutputFactory.newInstance()); + staxProcessors.addArtifactProcessor(new CompositeProcessor(new ContributionFactoryImpl(), factory, policyFactory, mapper, staxProcessor)); + staxProcessors.addArtifactProcessor(new ComponentTypeProcessor(factory, policyFactory, staxProcessor)); + staxProcessors.addArtifactProcessor(new ConstrainingTypeProcessor(factory, policyFactory, staxProcessor)); + staxProcessors.addArtifactProcessor(new SCADefinitionsProcessor(policyFactory, staxProcessor, resolver)); + staxProcessors.addArtifactProcessor(new SimpleIntentProcessor(policyFactory, staxProcessor)); + staxProcessors.addArtifactProcessor(new ProfileIntentProcessor(policyFactory, staxProcessor)); + staxProcessors.addArtifactProcessor(new QualifiedIntentProcessor(policyFactory, staxProcessor)); + staxProcessors.addArtifactProcessor(new PolicySetProcessor(policyFactory, staxProcessor)); + staxProcessors.addArtifactProcessor(new MockPolicyProcessor()); + + // Create document processors + XMLInputFactory inputFactory = XMLInputFactory.newInstance(); + documentProcessors.addArtifactProcessor(new CompositeDocumentProcessor(staxProcessor, inputFactory, null)); + documentProcessors.addArtifactProcessor(new ComponentTypeDocumentProcessor(staxProcessor, inputFactory, null)); + documentProcessors.addArtifactProcessor(new ConstrainingTypeDocumentProcessor(staxProcessor, inputFactory, null)); + scaDefnDocProcessor = new SCADefinitionsDocumentProcessor(staxProcessors, staxProcessor, inputFactory, policyFactory, null); + documentProcessors.addArtifactProcessor(scaDefnDocProcessor); + } + + @Override + public void tearDown() throws Exception { + } + + 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("definitions.xml"); + uri = URI.create("definitions.xml"); + SCADefinitions scaDefns = (SCADefinitions)scaDefnDocProcessor.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/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ResolveTestCase.java b/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ResolveTestCase.java new file mode 100644 index 0000000000..ddd26169e8 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ResolveTestCase.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.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.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.ConstrainingType; +import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory; +import org.apache.tuscany.sca.contribution.DefaultModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.impl.ContributionFactoryImpl; +import org.apache.tuscany.sca.contribution.processor.DefaultStAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; +import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; +import org.apache.tuscany.sca.interfacedef.impl.InterfaceContractMapperImpl; +import org.apache.tuscany.sca.policy.DefaultPolicyFactory; +import org.apache.tuscany.sca.policy.PolicyFactory; + +/** + * Test resolving SCA XML assemblies. + * + * @version $Rev$ $Date$ + */ +public class ResolveTestCase extends TestCase { + + private XMLInputFactory inputFactory; + private DefaultStAXArtifactProcessorExtensionPoint staxProcessors; + private ExtensibleStAXArtifactProcessor staxProcessor; + private TestModelResolver resolver; + private AssemblyFactory factory; + private PolicyFactory policyFactory; + private InterfaceContractMapper mapper; + + @Override + public void setUp() throws Exception { + factory = new DefaultAssemblyFactory(); + policyFactory = new DefaultPolicyFactory(); + mapper = new InterfaceContractMapperImpl(); + inputFactory = XMLInputFactory.newInstance(); + staxProcessors = new DefaultStAXArtifactProcessorExtensionPoint(new DefaultModelFactoryExtensionPoint()); + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, XMLInputFactory.newInstance(), XMLOutputFactory.newInstance()); + resolver = new TestModelResolver(); + } + + @Override + public void tearDown() throws Exception { + } + + public void testResolveConstrainingType() throws Exception { + InputStream is = getClass().getResourceAsStream("CalculatorComponent.constrainingType"); + ConstrainingTypeProcessor constrainingTypeReader = new ConstrainingTypeProcessor(factory, policyFactory, staxProcessor); + XMLStreamReader reader = inputFactory.createXMLStreamReader(is); + ConstrainingType constrainingType = constrainingTypeReader.read(reader); + is.close(); + assertNotNull(constrainingType); + resolver.addModel(constrainingType); + + is = getClass().getResourceAsStream("TestAllCalculator.composite"); + CompositeProcessor compositeReader = new CompositeProcessor(new ContributionFactoryImpl(), factory, policyFactory, mapper, staxProcessor); + 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"); + CompositeProcessor compositeReader = new CompositeProcessor(new ContributionFactoryImpl(), factory, policyFactory, mapper, staxProcessor); + XMLStreamReader reader = inputFactory.createXMLStreamReader(is); + Composite nestedComposite = compositeReader.read(reader); + is.close(); + assertNotNull(nestedComposite); + resolver.addModel(nestedComposite); + + is = getClass().getResourceAsStream("TestAllCalculator.composite"); + compositeReader = new CompositeProcessor(new ContributionFactoryImpl(), factory, policyFactory, mapper, staxProcessor); + 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/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestModelResolver.java b/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestModelResolver.java new file mode 100644 index 0000000000..3224176d6e --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/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.assembly.xml; + +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/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestSCABindingFactoryImpl.java b/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestSCABindingFactoryImpl.java new file mode 100644 index 0000000000..c423df6f7d --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestSCABindingImpl.java b/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestSCABindingImpl.java new file mode 100644 index 0000000000..6ecf387da9 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestSCABindingImpl.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.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.SCABinding; +import org.apache.tuscany.sca.assembly.OptimizableBinding; +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 implements SCABinding, OptimizableBinding, PolicySetAttachPoint { + private String name; + private String uri; + private List extensions = new ArrayList(); + + private Component targetComponent; + private ComponentService targetComponentService; + private Binding targetBinding; + + List requiredIntents = new ArrayList(); + List policySets = new ArrayList(); + IntentAttachPointType bindingType = new TestSCABindingType(); + + /** + * 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 + + } + + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/WireTestCase.java b/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/WireTestCase.java new file mode 100644 index 0000000000..7bf412e4b6 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/WireTestCase.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.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.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.ConstrainingType; +import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory; +import org.apache.tuscany.sca.assembly.SCABindingFactory; +import org.apache.tuscany.sca.assembly.builder.impl.CompositeBuilderImpl; +import org.apache.tuscany.sca.contribution.DefaultModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.impl.ContributionFactoryImpl; +import org.apache.tuscany.sca.contribution.processor.DefaultStAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; +import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; +import org.apache.tuscany.sca.interfacedef.impl.InterfaceContractMapperImpl; +import org.apache.tuscany.sca.policy.DefaultPolicyFactory; +import org.apache.tuscany.sca.policy.PolicyFactory; + +/** + * Test the wiring of SCA XML assemblies. + * + * @version $Rev$ $Date$ + */ +public class WireTestCase extends TestCase { + + private XMLInputFactory inputFactory; + private DefaultStAXArtifactProcessorExtensionPoint staxProcessors; + private ExtensibleStAXArtifactProcessor staxProcessor; + private TestModelResolver resolver; + private AssemblyFactory assemblyFactory; + private SCABindingFactory scaBindingFactory; + private PolicyFactory policyFactory; + private InterfaceContractMapper mapper; + + @Override + public void setUp() throws Exception { + inputFactory = XMLInputFactory.newInstance(); + staxProcessors = new DefaultStAXArtifactProcessorExtensionPoint(new DefaultModelFactoryExtensionPoint()); + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, XMLInputFactory.newInstance(), XMLOutputFactory.newInstance()); + resolver = new TestModelResolver(); + assemblyFactory = new DefaultAssemblyFactory(); + scaBindingFactory = new TestSCABindingFactoryImpl(); + policyFactory = new DefaultPolicyFactory(); + mapper = new InterfaceContractMapperImpl(); + } + + @Override + public void tearDown() throws Exception { + } + + public void testResolveConstrainingType() throws Exception { + InputStream is = getClass().getResourceAsStream("CalculatorComponent.constrainingType"); + ConstrainingTypeProcessor constrainingTypeReader = new ConstrainingTypeProcessor(assemblyFactory, policyFactory, staxProcessor); + XMLStreamReader reader = inputFactory.createXMLStreamReader(is); + ConstrainingType constrainingType = constrainingTypeReader.read(reader); + is.close(); + assertNotNull(constrainingType); + resolver.addModel(constrainingType); + + is = getClass().getResourceAsStream("TestAllCalculator.composite"); + CompositeProcessor compositeReader = new CompositeProcessor(new ContributionFactoryImpl(), assemblyFactory, policyFactory, mapper, staxProcessor); + reader = inputFactory.createXMLStreamReader(is); + Composite composite = compositeReader.read(reader); + is.close(); + assertNotNull(composite); + + compositeReader.resolve(composite, resolver); + CompositeBuilderImpl compositeUtil = new CompositeBuilderImpl(assemblyFactory, scaBindingFactory, mapper, null, null); + compositeUtil.build(composite); + + assertEquals(composite.getConstrainingType(), constrainingType); + assertEquals(composite.getComponents().get(0).getConstrainingType(), constrainingType); + } + + public void testResolveComposite() throws Exception { + InputStream is = getClass().getResourceAsStream("Calculator.composite"); + CompositeProcessor compositeReader = new CompositeProcessor(new ContributionFactoryImpl(), assemblyFactory, policyFactory, mapper, staxProcessor); + XMLStreamReader reader = inputFactory.createXMLStreamReader(is); + Composite nestedComposite = compositeReader.read(reader); + is.close(); + assertNotNull(nestedComposite); + resolver.addModel(nestedComposite); + + is = getClass().getResourceAsStream("TestAllCalculator.composite"); + compositeReader = new CompositeProcessor(new ContributionFactoryImpl(), assemblyFactory, policyFactory, mapper, staxProcessor); + reader = inputFactory.createXMLStreamReader(is); + Composite composite = compositeReader.read(reader); + is.close(); + + compositeReader.resolve(composite, resolver); + CompositeBuilderImpl compositeUtil = new CompositeBuilderImpl(assemblyFactory, scaBindingFactory, mapper, null, null); + compositeUtil.build(composite); + + assertEquals(composite.getComponents().get(2).getImplementation(), nestedComposite); + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/WriteAllTestCase.java b/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/WriteAllTestCase.java new file mode 100644 index 0000000000..202d3d7f13 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/WriteAllTestCase.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.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 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.DefaultAssemblyFactory; +import org.apache.tuscany.sca.assembly.SCABindingFactory; +import org.apache.tuscany.sca.assembly.builder.impl.CompositeBuilderImpl; +import org.apache.tuscany.sca.contribution.DefaultModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.impl.ContributionFactoryImpl; +import org.apache.tuscany.sca.contribution.processor.DefaultStAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; +import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; +import org.apache.tuscany.sca.interfacedef.impl.InterfaceContractMapperImpl; +import org.apache.tuscany.sca.policy.DefaultPolicyFactory; +import org.apache.tuscany.sca.policy.PolicyFactory; + +/** + * Test writing SCA XML assemblies. + * + * @version $Rev$ $Date$ + */ +public class WriteAllTestCase extends TestCase { + private DefaultStAXArtifactProcessorExtensionPoint staxProcessors; + private ExtensibleStAXArtifactProcessor staxProcessor; + private TestModelResolver resolver; + private AssemblyFactory assemblyFactory; + private SCABindingFactory scaBindingFactory; + private PolicyFactory policyFactory; + private InterfaceContractMapper mapper; + private CompositeBuilderImpl compositeUtil; + + + @Override + public void setUp() throws Exception { + assemblyFactory = new DefaultAssemblyFactory(); + scaBindingFactory = new TestSCABindingFactoryImpl(); + policyFactory = new DefaultPolicyFactory(); + mapper = new InterfaceContractMapperImpl(); + compositeUtil = new CompositeBuilderImpl(assemblyFactory, scaBindingFactory, mapper, null, null); + staxProcessors = new DefaultStAXArtifactProcessorExtensionPoint(new DefaultModelFactoryExtensionPoint()); + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, XMLInputFactory.newInstance(), XMLOutputFactory.newInstance()); + staxProcessors.addArtifactProcessor(new CompositeProcessor(new ContributionFactoryImpl(), assemblyFactory, policyFactory, mapper, staxProcessor)); + staxProcessors.addArtifactProcessor(new ComponentTypeProcessor(assemblyFactory, policyFactory, staxProcessor)); + staxProcessors.addArtifactProcessor(new ConstrainingTypeProcessor(assemblyFactory, policyFactory, staxProcessor)); + resolver = new TestModelResolver(); + } + + @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); + staxProcessor.resolve(composite, resolver); + compositeUtil.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/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/AnotherDefinitions.xml b/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/AnotherDefinitions.xml new file mode 100644 index 0000000000..b99287d57e --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/AnotherDefinitions.xml @@ -0,0 +1,84 @@ + + + + + + + + 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/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/Calculator.composite b/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/Calculator.composite new file mode 100644 index 0000000000..4546fddb2d --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/Calculator.composite @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/CalculatorComponent.constrainingType b/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/CalculatorComponent.constrainingType new file mode 100644 index 0000000000..072fe8fde1 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/CalculatorComponent.constrainingType @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/CalculatorImpl.componentType b/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/CalculatorImpl.componentType new file mode 100644 index 0000000000..d67ba3ec2b --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/CalculatorImpl.componentType @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/JavaScriptReference.composite b/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/JavaScriptReference.composite new file mode 100644 index 0000000000..a313dd1e6d --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/JavaScriptReference.composite @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/RMIBindingTest.composite b/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/RMIBindingTest.composite new file mode 100644 index 0000000000..d29fe85586 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/RMIBindingTest.composite @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/TestAllCalculator.composite b/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/TestAllCalculator.composite new file mode 100644 index 0000000000..5091ff700b --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/TestAllDivide.composite b/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/TestAllDivide.composite new file mode 100644 index 0000000000..d59e69209d --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/TestAllDivide.composite @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/TestAllPolicyCalculator.composite b/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/TestAllPolicyCalculator.composite new file mode 100644 index 0000000000..59f832d6df --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/TestAllPolicyCalculator.composite @@ -0,0 +1,131 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + AValue + InterestingURI + + + BValue + BoringURI + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/definitions.xml b/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/definitions.xml new file mode 100644 index 0000000000..3c268f18e0 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/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/tags/java/sca/1.0-RC1b/modules/assembly-xsd/DISCLAIMER b/tags/java/sca/1.0-RC1b/modules/assembly-xsd/DISCLAIMER new file mode 100644 index 0000000000..d68a410903 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly-xsd/DISCLAIMER @@ -0,0 +1,8 @@ +Apache Tuscany is an effort undergoing incubation at The Apache Software +Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is +required of all newly accepted projects until a further review indicates that +the infrastructure, communications, and decision making process have stabilized +in a manner consistent with other successful ASF projects. While incubation +status is not necessarily a reflection of the completeness or stability of the +code, it does indicate that the project has yet to be fully endorsed by the ASF. + diff --git a/tags/java/sca/1.0-RC1b/modules/assembly-xsd/LICENSE b/tags/java/sca/1.0-RC1b/modules/assembly-xsd/LICENSE new file mode 100644 index 0000000000..bfded7c6a9 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly-xsd/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. + + + +=============================================================================== + +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. + +=============================================================================== diff --git a/tags/java/sca/1.0-RC1b/modules/assembly-xsd/NOTICE b/tags/java/sca/1.0-RC1b/modules/assembly-xsd/NOTICE new file mode 100644 index 0000000000..9fd1d9f6d8 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly-xsd/NOTICE @@ -0,0 +1,12 @@ +${pom.name} +Copyright (c) 2005 - 2007 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 + diff --git a/tags/java/sca/1.0-RC1b/modules/assembly-xsd/pom.xml b/tags/java/sca/1.0-RC1b/modules/assembly-xsd/pom.xml new file mode 100644 index 0000000000..d109160a27 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly-xsd/pom.xml @@ -0,0 +1,31 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.0-incubating + ../pom.xml + + tuscany-assembly-xsd + Apache Tuscany SCA Assembly Model XML Schemas + + diff --git a/tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/sca-binding-ejb.xsd b/tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/sca-binding-ejb.xsd new file mode 100644 index 0000000000..26bedfcce5 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/sca-binding-ejb.xsd @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/sca-binding-jms.xsd b/tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/sca-binding-jms.xsd new file mode 100644 index 0000000000..850f32b56a --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/sca-binding-jms.xsd @@ -0,0 +1,135 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/sca-binding-sca.xsd b/tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/sca-binding-sca.xsd new file mode 100644 index 0000000000..02703402ef --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/sca-binding-sca.xsd @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/sca-binding-webservice.xsd b/tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/sca-binding-webservice.xsd new file mode 100644 index 0000000000..3e92de193b --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/sca-binding-webservice.xsd @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/sca-core.xsd b/tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/sca-core.xsd new file mode 100644 index 0000000000..1c6291792b --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/sca-core.xsd @@ -0,0 +1,350 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/sca-definitions.xsd b/tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/sca-definitions.xsd new file mode 100644 index 0000000000..0249882a92 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/sca-definitions.xsd @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/sca-implementation-bpel.xsd b/tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/sca-implementation-bpel.xsd new file mode 100644 index 0000000000..87b443fb36 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/sca-implementation-bpel.xsd @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/sca-implementation-composite.xsd b/tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/sca-implementation-composite.xsd new file mode 100644 index 0000000000..99669bc672 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/sca-implementation-composite.xsd @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/sca-implementation-cpp.xsd b/tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/sca-implementation-cpp.xsd new file mode 100644 index 0000000000..6f1cf14a4b --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/sca-implementation-cpp.xsd @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/sca-implementation-java.xsd b/tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/sca-implementation-java.xsd new file mode 100644 index 0000000000..f9d8171b8e --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/sca-implementation-java.xsd @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/sca-implementation-spring.xsd b/tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/sca-implementation-spring.xsd new file mode 100644 index 0000000000..1cf9fb3ea9 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/sca-implementation-spring.xsd @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/sca-interface-cpp.xsd b/tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/sca-interface-cpp.xsd new file mode 100644 index 0000000000..44f14e5ed5 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/sca-interface-cpp.xsd @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/sca-interface-java.xsd b/tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/sca-interface-java.xsd new file mode 100644 index 0000000000..81f939bdb4 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/sca-interface-java.xsd @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/sca-interface-wsdl.xsd b/tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/sca-interface-wsdl.xsd new file mode 100644 index 0000000000..c1fdfd8f3c --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/sca-interface-wsdl.xsd @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/sca-policy.xsd b/tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/sca-policy.xsd new file mode 100644 index 0000000000..c22ffd6618 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/sca-policy.xsd @@ -0,0 +1,76 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/sca.xsd b/tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/sca.xsd new file mode 100644 index 0000000000..10f54275d0 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/sca.xsd @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-atom.xsd b/tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-atom.xsd new file mode 100644 index 0000000000..1d25e9faf9 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-atom.xsd @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-dwr.xsd b/tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-dwr.xsd new file mode 100644 index 0000000000..d0da5421ec --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-dwr.xsd @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-http.xsd b/tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-http.xsd new file mode 100644 index 0000000000..ff48b97d7a --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-http.xsd @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-jsonrpc.xsd b/tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-jsonrpc.xsd new file mode 100644 index 0000000000..7c79738898 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-jsonrpc.xsd @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-notification.xsd b/tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-notification.xsd new file mode 100644 index 0000000000..6d5468b2f9 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-notification.xsd @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-rmi.xsd b/tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-rmi.xsd new file mode 100644 index 0000000000..2697a1ea98 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-rmi.xsd @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-rss.xsd b/tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-rss.xsd new file mode 100644 index 0000000000..79215617eb --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-rss.xsd @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/tuscany-sca-implementation-node.xsd b/tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/tuscany-sca-implementation-node.xsd new file mode 100644 index 0000000000..f972e498b2 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/tuscany-sca-implementation-node.xsd @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/tuscany-sca-implementation-notification.xsd b/tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/tuscany-sca-implementation-notification.xsd new file mode 100644 index 0000000000..f8d437310e --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/tuscany-sca-implementation-notification.xsd @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/tuscany-sca-implementation-osgi.xsd b/tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/tuscany-sca-implementation-osgi.xsd new file mode 100644 index 0000000000..f8ece54a07 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/tuscany-sca-implementation-osgi.xsd @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/tuscany-sca-implementation-resource.xsd b/tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/tuscany-sca-implementation-resource.xsd new file mode 100644 index 0000000000..dd596821ea --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/tuscany-sca-implementation-resource.xsd @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/tuscany-sca-implementation-script.xsd b/tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/tuscany-sca-implementation-script.xsd new file mode 100644 index 0000000000..e1723d65f0 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/tuscany-sca-implementation-script.xsd @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/tuscany-sca-implementation-xquery.xsd b/tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/tuscany-sca-implementation-xquery.xsd new file mode 100644 index 0000000000..cdabb697aa --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/tuscany-sca-implementation-xquery.xsd @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/tuscany-sca-include.xsd b/tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/tuscany-sca-include.xsd new file mode 100644 index 0000000000..169ca1b11c --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/tuscany-sca-include.xsd @@ -0,0 +1,31 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/tuscany-sca.xsd b/tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/tuscany-sca.xsd new file mode 100644 index 0000000000..8560425d45 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly-xsd/src/main/resources/tuscany-sca.xsd @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tags/java/sca/1.0-RC1b/modules/assembly/.checkstyle b/tags/java/sca/1.0-RC1b/modules/assembly/.checkstyle new file mode 100644 index 0000000000..e3c216986d --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly/.checkstyle @@ -0,0 +1,24 @@ + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/assembly/.pmd b/tags/java/sca/1.0-RC1b/modules/assembly/.pmd new file mode 100644 index 0000000000..aa1ce3e754 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly/.pmd @@ -0,0 +1,21 @@ + + + +truefalse \ No newline at end of file diff --git a/tags/java/sca/1.0-RC1b/modules/assembly/.ruleset b/tags/java/sca/1.0-RC1b/modules/assembly/.ruleset new file mode 100644 index 0000000000..ba9b5ce886 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly/.ruleset @@ -0,0 +1,190 @@ + + + + PMD Plugin preferences rule set + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/assembly/DISCLAIMER b/tags/java/sca/1.0-RC1b/modules/assembly/DISCLAIMER new file mode 100644 index 0000000000..d68a410903 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly/DISCLAIMER @@ -0,0 +1,8 @@ +Apache Tuscany is an effort undergoing incubation at The Apache Software +Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is +required of all newly accepted projects until a further review indicates that +the infrastructure, communications, and decision making process have stabilized +in a manner consistent with other successful ASF projects. While incubation +status is not necessarily a reflection of the completeness or stability of the +code, it does indicate that the project has yet to be fully endorsed by the ASF. + diff --git a/tags/java/sca/1.0-RC1b/modules/assembly/LICENSE b/tags/java/sca/1.0-RC1b/modules/assembly/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/assembly/NOTICE b/tags/java/sca/1.0-RC1b/modules/assembly/NOTICE new file mode 100644 index 0000000000..94481d6cfa --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2007 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/tags/java/sca/1.0-RC1b/modules/assembly/pom.xml b/tags/java/sca/1.0-RC1b/modules/assembly/pom.xml new file mode 100644 index 0000000000..c15c4d8f4f --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly/pom.xml @@ -0,0 +1,44 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.0-incubating + ../pom.xml + + tuscany-assembly + Apache Tuscany SCA Assembly Model + + + + org.apache.tuscany.sca + tuscany-policy + 1.0-incubating + + + + org.apache.tuscany.sca + tuscany-interface + 1.0-incubating + + + diff --git a/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/AbstractContract.java b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/AbstractContract.java new file mode 100644 index 0000000000..6af7f40169 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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 { + + /** + * 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/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/AbstractProperty.java b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/AbstractProperty.java new file mode 100644 index 0000000000..c5e78cb471 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/AbstractProperty.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.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. + */ +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 ths property + */ + Object getValue(); + + /** + * Sets the default value of the property. + * + * @param defaultValue the default value of ths 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 type the element defining the type of this property + */ + void setXSDElement(QName element); + +} diff --git a/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/AbstractReference.java b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/AbstractReference.java new file mode 100644 index 0000000000..a9ef26bbb9 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/AbstractService.java b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/AbstractService.java new file mode 100644 index 0000000000..9ae511c07b --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/AssemblyFactory.java b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/AssemblyFactory.java new file mode 100644 index 0000000000..3937d34f92 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/AssemblyFactory.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.assembly; + +import org.apache.tuscany.sca.interfacedef.Operation; + +/** + * 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 operation. + * + * @return a new operation + */ + Operation createOperation(); + +} diff --git a/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Base.java b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Base.java new file mode 100644 index 0000000000..76511d351d --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Binding.java b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Binding.java new file mode 100644 index 0000000000..11914778f7 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Binding.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 binding. + * + * @version $Rev$ $Date$ + */ +public interface Binding extends Base { + + /** + * 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); +} diff --git a/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Callback.java b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Callback.java new file mode 100644 index 0000000000..e21547d6a6 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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 Extensible, IntentAttachPoint, PolicySetAttachPoint { + + /** + * Returns the bindings supported for callbacks. + * + * @return the bindings supported for callbacks + */ + List getBindings(); + +} diff --git a/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Component.java b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Component.java new file mode 100644 index 0000000000..7fa906dca6 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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.IntentAttachPoint; +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, IntentAttachPoint, 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/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ComponentProperty.java b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ComponentProperty.java new file mode 100644 index 0000000000..f944d52794 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ComponentProperty.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; + +/** + * 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 type that defines this property. + * + * @param type the property that defines this property + */ + 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); + + /** + * 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/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ComponentReference.java b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ComponentReference.java new file mode 100644 index 0000000000..7f121ac124 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ComponentReference.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; + + +/** + * 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 + */ + public ComponentService getCallbackService(); + + /** + * Sets the callback service created internally as a target endpoint + * for callbacks to this reference. + * + * @param callbackService the callback service + */ + public void setCallbackService(ComponentService callbackService); + +} diff --git a/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ComponentService.java b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ComponentService.java new file mode 100644 index 0000000000..65945692f1 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ComponentType.java b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ComponentType.java new file mode 100644 index 0000000000..e1ea65ea39 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Composite.java b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Composite.java new file mode 100644 index 0000000000..a1a16dea91 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Composite.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; + +import java.util.List; + +import javax.xml.namespace.QName; + + +/** + * Represents a composite. + * + * @version $Rev$ $Date$ + */ +public interface Composite extends Implementation, Extensible, Cloneable { + + /** + * 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/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/CompositeReference.java b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/CompositeReference.java new file mode 100644 index 0000000000..d3fa80ba74 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/CompositeService.java b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/CompositeService.java new file mode 100644 index 0000000000..7143f571f9 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ConstrainingType.java b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ConstrainingType.java new file mode 100644 index 0000000000..9890bfed68 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Contract.java b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Contract.java new file mode 100644 index 0000000000..25d35d38f5 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Contract.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.assembly; + +import java.util.List; + +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; + +} diff --git a/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/DefaultAssemblyFactory.java b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/DefaultAssemblyFactory.java new file mode 100644 index 0000000000..5dd256e3c4 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Extensible.java b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Extensible.java new file mode 100644 index 0000000000..3577a94d1e --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Extensible.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; + +/** + * 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(); + +} diff --git a/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Implementation.java b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Implementation.java new file mode 100644 index 0000000000..9b62bb4506 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Implementation.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 component implementation. + * + * @version $Rev$ $Date$ + */ +public interface Implementation extends ComponentType { +} diff --git a/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Multiplicity.java b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Multiplicity.java new file mode 100644 index 0000000000..5d15ce9938 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/OptimizableBinding.java b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/OptimizableBinding.java new file mode 100644 index 0000000000..98ff92f15b --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Property.java b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Property.java new file mode 100644 index 0000000000..683920da58 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Reference.java b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Reference.java new file mode 100644 index 0000000000..f38346663a --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Reference.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; + +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 the targets of this reference. + * + * @return the targets of this reference. + */ + List getTargets(); + +} diff --git a/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/SCABinding.java b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/SCABinding.java new file mode 100644 index 0000000000..2cf04277cd --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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 { +} diff --git a/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/SCABindingFactory.java b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/SCABindingFactory.java new file mode 100644 index 0000000000..0abfd13d10 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Service.java b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Service.java new file mode 100644 index 0000000000..020870cd34 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Wire.java b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Wire.java new file mode 100644 index 0000000000..ee65e5746e --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/ComponentPreProcessor.java b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/ComponentPreProcessor.java new file mode 100644 index 0000000000..5f5856d051 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/ComponentPreProcessor.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.builder; + +import org.apache.tuscany.sca.assembly.Component; + +public interface ComponentPreProcessor { + + void preProcess(Component component); + +} diff --git a/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/CompositeBuilder.java b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/CompositeBuilder.java new file mode 100644 index 0000000000..26bdc3cffa --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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, configure and wire a composite. + * + * @param composite + * @throws CompositeBuilderException + */ + void build(Composite composite) throws CompositeBuilderException; + +} diff --git a/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/CompositeBuilderException.java b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/CompositeBuilderException.java new file mode 100644 index 0000000000..5a2015f55e --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/CompositeBuilderMonitor.java b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/CompositeBuilderMonitor.java new file mode 100644 index 0000000000..aecdf417f2 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/CompositeBuilderMonitor.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; + +/** + * A monitor for the composite builder. + * + * @version $Rev$ $Date$ + */ +public interface CompositeBuilderMonitor { + + /** + * Reports a build problem. + * + * @param problem + */ + void problem(Problem problem); + +} diff --git a/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/Problem.java b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/Problem.java new file mode 100644 index 0000000000..8965410438 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/Problem.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 assembly problem. + * + * @version $Rev$ $Date$ + */ +public interface Problem { + + public enum Severity { + INFO, + WARNING, + ERROR + } + + Severity getSeverity(); + + String getMessage(); + + Object getModel(); + + Object getResource(); + + Exception getCause(); +} diff --git a/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BindingUtil.java b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BindingUtil.java new file mode 100644 index 0000000000..023702f022 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BindingUtil.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.assembly.builder.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.SCABinding; +import org.apache.tuscany.sca.assembly.OptimizableBinding; +import org.apache.tuscany.sca.policy.PolicySet; +import org.apache.tuscany.sca.policy.PolicySetAttachPoint; + +/** + * This class encapsulates utility methods to deal with binding definitions + */ +class BindingUtil { + private static boolean hasCompatiblePolicySets(Binding refBinding, Binding svcBinding) { + 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() ) { + for ( PolicySet refPolicySet : ((PolicySetAttachPoint)refBinding).getPolicySets() ) { + if ( !svcPolicySet.equals(refPolicySet) ) { + return false; + } + } + } + } + return true; + } + + + private static Binding matchBinding(Component component, ComponentService service, List source, List target) { + 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)) { + + Binding cloned = binding; + if (binding instanceof OptimizableBinding) { + // TODO: We need to clone the reference binding + try { + cloned = (Binding)((OptimizableBinding)binding).clone(); + OptimizableBinding endpoint = ((OptimizableBinding)cloned); + endpoint.setTargetComponent(component); + endpoint.setTargetComponentService(service); + endpoint.setTargetBinding(serviceBinding); + cloned.setURI(serviceBinding.getURI()); + } catch (Exception e) { + // warning("The binding doesn't support clone: " + binding.getClass().getSimpleName(), binding); + } + } else { + if (binding.getURI() == null) { + binding.setURI(serviceBinding.getURI()); + } + } + matched.add(cloned); + break; + } + } + } + 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) { + List source = reference.getBindings(); + List target = service.getBindings(); + + return matchBinding(component, service, source, target); + + } + + /** + * @param reference + * @param service + * @return + */ + static Binding resolveCallbackBindings(ComponentReference reference, Component component, ComponentService service) { + List source = reference.getCallback().getBindings(); + List target = service.getCallback().getBindings(); + + return matchBinding(component, service, source, target); + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBuilderImpl.java b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBuilderImpl.java new file mode 100644 index 0000000000..6eb3a931df --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBuilderImpl.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 java.util.List; +import java.util.logging.Logger; + +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.assembly.builder.CompositeBuilderMonitor; +import org.apache.tuscany.sca.assembly.builder.Problem; +import org.apache.tuscany.sca.assembly.builder.Problem.Severity; +import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; +import org.apache.tuscany.sca.policy.PolicySet; + +/** + * 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 final static Logger logger = Logger.getLogger(CompositeBuilderImpl.class.getName()); + private CompositeIncludeBuilderImpl includeBuilder; + private CompositeWireBuilderImpl wireBuilder; + private CompositeCloneBuilderImpl cloneBuilder; + private CompositeConfigurationBuilderImpl configurationBuilder; + + /** + * Constructs a new composite util. + * + * @param assemblyFactory + * @param interfaceContractMapper + */ + public CompositeBuilderImpl(AssemblyFactory assemblyFactory, + SCABindingFactory scaBindingFactory, + InterfaceContractMapper interfaceContractMapper, + List domainPolicySets, + CompositeBuilderMonitor monitor) { + + if (monitor == null) { + // Create a default monitor that does nothing. + monitor = new CompositeBuilderMonitor() { + public void problem(Problem problem) { + if (problem.getSeverity() == Severity.INFO) { + logger.info(problem.toString()); + } else if (problem.getSeverity() == Severity.WARNING) { + logger.warning(problem.toString()); + } else if (problem.getSeverity() == Severity.ERROR) { + logger.severe(problem.toString()); + } + } + }; + } + + includeBuilder = new CompositeIncludeBuilderImpl(monitor); + wireBuilder = new CompositeWireBuilderImpl(assemblyFactory, interfaceContractMapper, domainPolicySets, monitor); + cloneBuilder = new CompositeCloneBuilderImpl(monitor); + configurationBuilder = new CompositeConfigurationBuilderImpl(assemblyFactory, scaBindingFactory, interfaceContractMapper, monitor); + } + + public void build(Composite composite) throws CompositeBuilderException { + + // Collect and fuse includes + includeBuilder.fuseIncludes(composite); + + // Expand nested composites + cloneBuilder.expandCompositeImplementations(composite); + + // Configure all components + configurationBuilder.configureComponents(composite); + + // Wire the composite + wireBuilder.wireComposite(composite); + + // Activate composite services + configurationBuilder.activateCompositeServices(composite); + + // Wire composite references + wireBuilder.wireCompositeReferences(composite); + + // Fuse nested composites + //cloneBuilder.fuseCompositeImplementations(composite); + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeCloneBuilderImpl.java b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeCloneBuilderImpl.java new file mode 100644 index 0000000000..fee8e02f4e --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeCloneBuilderImpl.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.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.CompositeBuilderMonitor; + +public class CompositeCloneBuilderImpl { + + public CompositeCloneBuilderImpl(CompositeBuilderMonitor monitor) { + } + + /** + * Expand composite component implementations. + * + * @param composite + * @param problems + */ + public 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 + */ + public 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/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeConfigurationBuilderImpl.java b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeConfigurationBuilderImpl.java new file mode 100644 index 0000000000..111424d685 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeConfigurationBuilderImpl.java @@ -0,0 +1,1065 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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.HashMap; +import java.util.List; +import java.util.Map; + +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.CompositeService; +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.ComponentPreProcessor; +import org.apache.tuscany.sca.assembly.builder.CompositeBuilderMonitor; +import org.apache.tuscany.sca.assembly.builder.Problem.Severity; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; + +public class CompositeConfigurationBuilderImpl { + + private AssemblyFactory assemblyFactory; + private SCABindingFactory scaBindingFactory; + private CompositeBuilderMonitor monitor; + private InterfaceContractMapper interfaceContractMapper; + + + public CompositeConfigurationBuilderImpl(AssemblyFactory assemblyFactory, + SCABindingFactory scaBindingFactory, + InterfaceContractMapper interfaceContractMapper, + CompositeBuilderMonitor monitor) { + this.assemblyFactory = assemblyFactory; + this.scaBindingFactory = scaBindingFactory; + this.interfaceContractMapper = interfaceContractMapper; + this.monitor = monitor; + } + + /** + * Configure components in the composite. + * + * @param composite + * @param problems + */ + public void configureComponents(Composite composite) { + configureComponents(composite, null); + configureSourcedProperties(composite, 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 = scaBindingFactory.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()); + } + + String bindingURI; + if (binding.getURI() == null) { + if (compositeServices.size() > 1) { + // Binding URI defaults to parent URI / binding name + bindingURI = String.valueOf(binding.getName()); + if (parentURI != null) { + bindingURI = URI.create(parentURI + '/').resolve(bindingURI).toString(); + } + } else { + // If there's only one service then binding URI defaults + // to the parent URI + if (parentURI != null) { + bindingURI = parentURI; + } else { + bindingURI = String.valueOf(binding.getName()); + } + } + } else { + // Combine the specified binding URI with the component URI + bindingURI = binding.getURI(); + if (parentURI != null) { + bindingURI = URI.create(parentURI + '/').resolve(bindingURI).toString(); + } + } + + binding.setURI(bindingURI); + } + + 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 = scaBindingFactory.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())) { + warning("Duplicate component name: " + composite.getName() + + " : " + + component.getName(), composite); + } 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 = scaBindingFactory.createSCABinding(); + componentService.getBindings().add(scaBinding); + } + + // Set binding names and URIs + for (Binding binding : componentService.getBindings()) { + + // Binding name defaults to the service name + if (binding.getName() == null) { + binding.setName(componentService.getName()); + } + + String bindingURI; + if (binding.getURI() == null) { + if (componentServices.size() > 1) { + // Binding URI defaults to component URI / binding name + bindingURI = String.valueOf(binding.getName()); + bindingURI = URI.create(component.getURI() + '/').resolve(bindingURI).toString(); + } else { + // If there's only one service then binding URI defaults + // to the component URI + bindingURI = component.getURI(); + } + } else { + // Combine the specified binding URI with the component URI + bindingURI = binding.getURI(); + bindingURI = URI.create(component.getURI()).resolve(bindingURI).toString(); + } + + binding.setURI(bindingURI); + } + 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 = scaBindingFactory.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) { + monitor.problem(new ProblemImpl(Severity.WARNING, message, model)); + } + + /** + * 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("Property not found for component property: " + component.getName() + + "/" + + componentProperty.getName(), component); + } + } + + // 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("Component property mustSupply attribute incompatible with property: " + component + .getName() + + "/" + + componentProperty.getName(), + component); + } + + // 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("No value configured on a mustSupply property: " + component.getName() + + "/" + + componentProperty.getName(), component); + } + + // Check that a a component property does not override the + // many attribute + if (!property.isMany() && componentProperty.isMany()) { + warning("Component property many attribute incompatible with property: " + component + .getName() + + "/" + + componentProperty.getName(), + component); + } + + // 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("No type specified on component property: " + component.getName() + + "/" + + componentProperty.getName(), component); + } + } + } + } + + /** + * 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()) { + Reference reference = references.get(componentReference.getName()); + if (reference != null) { + componentReference.setReference(reference); + } else { + if (!componentReference.getName().startsWith("$self$.")) { + warning("Reference not found for component reference: " + component.getName() + + "/" + + componentReference.getName(), component); + } + } + } + + // 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 (!ReferenceUtil.isValidMultiplicityOverride(reference.getMultiplicity(), + componentReference + .getMultiplicity())) { + warning("Component reference multiplicity incompatible with reference multiplicity: " + component + .getName() + + "/" + + componentReference.getName(), + component); + } + } else { + componentReference.setMultiplicity(reference.getMultiplicity()); + } + + // Reconcile interface + if (componentReference.getInterfaceContract() != null) { + if (!componentReference.getInterfaceContract().equals(reference + .getInterfaceContract())) { + if (!interfaceContractMapper.isCompatible(reference.getInterfaceContract(), + componentReference + .getInterfaceContract())) { + warning("Component reference interface incompatible with reference interface: " + component + .getName() + + "/" + + componentReference.getName(), + component); + } + } + } else { + componentReference.setInterfaceContract(reference.getInterfaceContract()); + } + + // 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()) { + Service service = services.get(componentService.getName()); + if (service != null) { + componentService.setService(service); + } else { + warning("Service not found for component service: " + component.getName() + + "/" + + componentService.getName(), component); + } + } + + // 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 + if (componentService.getInterfaceContract() != null) { + if (!componentService.getInterfaceContract().equals(service + .getInterfaceContract())) { + if (!interfaceContractMapper.isCompatible(componentService + .getInterfaceContract(), service.getInterfaceContract())) { + warning("Component service interface incompatible with service interface: " + component + .getName() + + "/" + + componentService.getName(), + component); + } + } + } else { + componentService.setInterfaceContract(service.getInterfaceContract()); + } + + // 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("Duplicate component service name: " + component.getName() + + "/" + + componentService.getName(), component); + } else { + componentServices.put(componentService.getName(), componentService); + } + } + for (ComponentReference componentReference : component.getReferences()) { + if (componentReferences.containsKey(componentReference.getName())) { + warning("Duplicate component reference name: " + component.getName() + + "/" + + componentReference.getName(), component); + } else { + componentReferences.put(componentReference.getName(), componentReference); + } + } + for (ComponentProperty componentProperty : component.getProperties()) { + if (componentProperties.containsKey(componentProperty.getName())) { + warning("Duplicate component property name: " + component.getName() + + "/" + + componentProperty.getName(), component); + } 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("No implementation for component: " + component.getName(), component); + + } else if (implementation.isUnresolved()) { + + // The implementation must be fully resolved + warning("Component implementation not found: " + component.getName() + + " : " + + implementation.getURI(), component); + + } else { + + // Index properties, services and references, also check for + // duplicates + for (Property property : implementation.getProperties()) { + if (properties.containsKey(property.getName())) { + warning("Duplicate property name: " + component.getName() + + "/" + + property.getName(), component); + } else { + properties.put(property.getName(), property); + } + } + for (Service service : implementation.getServices()) { + if (services.containsKey(service.getName())) { + warning("Duplicate service name: " + component.getName() + + "/" + + service.getName(), component); + } else { + services.put(service.getName(), service); + } + } + for (Reference reference : implementation.getReferences()) { + if (references.containsKey(reference.getName())) { + warning("Duplicate reference name: " + component.getName() + + "/" + + reference.getName(), component); + } 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) { + 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; + } + + /** + * Activate composite services in nested composites. + * + * @param composite + * @param problems + */ + public void activateCompositeServices(Composite composite) { + + // Process nested composites recursively + activateNestedCompositeServices(composite); + + // Process top level composite services + for (Service service : composite.getServices()) { + CompositeService compositeService = (CompositeService)service; + + // Get the inner most promoted service + ComponentService promotedService = getPromotedComponentService(compositeService); + if (promotedService != null) { + Component promotedComponent = getPromotedComponent(compositeService); + + // Default to use the interface from the promoted service + if (compositeService.getInterfaceContract() == null && promotedService.getInterfaceContract() != null) { + compositeService.setInterfaceContract(promotedService.getInterfaceContract()); + } + + // 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()); + if (compositeService.getCallback() != null) { + newComponentService.getCallback().getBindings().addAll(compositeService + .getCallback().getBindings()); + } + } + + // Change the composite service to now promote the newly + // created component service directly + compositeService.setPromotedComponent(promotedComponent); + compositeService.setPromotedService(newComponentService); + } + } + } + + /** + * Activate composite services in nested composites. + * + * @param composite + * @param problems + */ + public void activateNestedCompositeServices(Composite composite) { + + // Process nested composites recursively + for (Component component : composite.getComponents()) { + Implementation implementation = component.getImplementation(); + if (implementation instanceof Composite) { + + // First process nested composites + activateNestedCompositeServices((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 inner most promoted service + ComponentService promotedService = + getPromotedComponentService(compositeService); + if (promotedService != null) { + Component promotedComponent = getPromotedComponent(compositeService); + + // Default to use the interface from the promoted + // service + if (compositeService.getInterfaceContract() == null) { + compositeService.setInterfaceContract(promotedService + .getInterfaceContract()); + } + if (componentService.getInterfaceContract() == null) { + componentService.setInterfaceContract(promotedService + .getInterfaceContract()); + } + + // 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()); + if (compositeService.getCallback() != null) { + newComponentService.getCallback().getBindings() + .addAll(compositeService.getCallback().getBindings()); + } + } + + // Change the composite service to now promote the + // newly created component service directly + compositeService.setPromotedComponent(promotedComponent); + compositeService.setPromotedService(newComponentService); + } + } + } + } + } + } + + /** + * @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 { + PropertyUtil.sourceComponentProperties(compositeProperties, component); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + Implementation impl = component.getImplementation(); + if (impl instanceof Composite) { + configureSourcedProperties((Composite)impl, component.getProperties()); + } + } + } + + /** + * 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; + } + } + + /** + * Follow a service promotion chain down to the inner most (non composite) + * component. + * + * @param compositeService + * @return + */ + private 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; + } + } + + private ComponentProperty getComponentPropertyByName(String propertyName, List properties) { + if (properties != null) { + for (ComponentProperty aProperty : properties) { + if (aProperty.getName().equals(propertyName)) { + return aProperty; + } + } + } + return null; + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeIncludeBuilderImpl.java b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeIncludeBuilderImpl.java new file mode 100644 index 0000000000..ced482dbf6 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeIncludeBuilderImpl.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.assembly.builder.impl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.builder.CompositeBuilderMonitor; +import org.apache.tuscany.sca.policy.PolicySetAttachPoint; + +public class CompositeIncludeBuilderImpl { + + public CompositeIncludeBuilderImpl(CompositeBuilderMonitor monitor) { + } + + /** + * Collect all includes in a graph of includes. + * + * @param composite + * @param includes + */ + private void collectIncludes(Composite composite, List includes) { + for (Composite include : composite.getIncludes()) { + includes.add(include); + collectIncludes(include, includes); + } + } + + /** + * Copy a list of includes into a composite. + * + * @param composite + */ + public void fuseIncludes(Composite composite) { + + // First collect all includes + List includes = new ArrayList(); + collectIncludes(composite, includes); + + // 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()); + if ( composite instanceof PolicySetAttachPoint ) { + ((PolicySetAttachPoint)composite).getPolicySets().addAll(((PolicySetAttachPoint)clone).getPolicySets()); + ((PolicySetAttachPoint)composite).getRequiredIntents().addAll(((PolicySetAttachPoint)clone).getRequiredIntents()); + } + } + + // Clear the list of includes + composite.getIncludes().clear(); + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeWireBuilderImpl.java b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeWireBuilderImpl.java new file mode 100644 index 0000000000..1cf27af913 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeWireBuilderImpl.java @@ -0,0 +1,1220 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import javax.xml.namespace.QName; + +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.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.Contract; +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.Service; +import org.apache.tuscany.sca.assembly.Wire; +import org.apache.tuscany.sca.assembly.OptimizableBinding; +import org.apache.tuscany.sca.assembly.builder.CompositeBuilderMonitor; +import org.apache.tuscany.sca.assembly.builder.Problem.Severity; +import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; +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.ProfileIntent; +import org.apache.tuscany.sca.policy.QualifiedIntent; + +public class CompositeWireBuilderImpl { + + private CompositeBuilderMonitor monitor; + private AssemblyFactory assemblyFactory; + private InterfaceContractMapper interfaceContractMapper; + private List domainPolicySets; + + //Represents a target component and service + private class Target { + Component component; + ComponentService service; + + Target(Component component, ComponentService service) { + this.component = component; + this.service = service; + } + + Component getComponent() { + return component; + } + + ComponentService getService() { + return service; + } + }; + + public CompositeWireBuilderImpl(AssemblyFactory assemblyFactory, InterfaceContractMapper interfaceContractMapper, List domainPolicySets, CompositeBuilderMonitor monitor) { + this.assemblyFactory = assemblyFactory; + this.interfaceContractMapper = interfaceContractMapper; + this.monitor = monitor; + this.domainPolicySets = domainPolicySets; + } + + /** + * Wire component references to component services and connect promoted + * services/references to component services/references inside a composite. + * + * @param composite + */ + public void wireComposite(Composite composite) { + + // Wire nested composites recursively + for (Component component : composite.getComponents()) { + Implementation implementation = component.getImplementation(); + if (implementation instanceof Composite) { + wireComposite((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 to their targets + connectComponentReferences(composite, components, componentServices, componentReferences); + + // Connect component references as described in wires + connectWires(composite, componentServices, componentReferences); + + // Validate that references are wired or promoted, according + // to their multiplicity + for (ComponentReference componentReference : componentReferences.values()) { + if (!ReferenceUtil.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) { + warning("No targets for reference: " + componentReference.getName(), composite); + } + } else { + warning("Too many targets on reference: " + componentReference.getName(), composite); + } + } + } + } + + /** + * 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); + if (!componentService.isCallback()) { + + // Check how many non callback 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) { + monitor.problem(new ProblemImpl(Severity.WARNING, message, model)); + } + + /** + * 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 + if (compositeService.getInterfaceContract() == null) { + compositeService.setInterfaceContract(promotedService.getInterfaceContract()); + } + + } else { + warning("Promoted component service not found: " + promotedServiceName, composite); + } + } + } + + } + + /** + * 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 + if (compositeReference.getInterfaceContract() == null) { + compositeReference.setInterfaceContract(componentReference.getInterfaceContract()); + } + + } else { + warning("Promoted component reference not found: " + componentReferenceName, composite); + } + } + } + } + } + + private List createComponentReferenceTargets(Composite composite, + Map components, + Map componentServices, + ComponentReference componentReference) { + List targets = new ArrayList(); + + 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()) { + for (ComponentService targetComponentService : targetComponent.getServices()) { + if (componentReference.getInterfaceContract() == null || + interfaceContractMapper.isCompatible(componentReference.getInterfaceContract(), targetComponentService.getInterfaceContract())) { + Target target = new Target(targetComponent, targetComponentService); + targets.add(target); + if (multiplicity == Multiplicity.ZERO_ONE || multiplicity == Multiplicity.ONE_ONE) { + break; + } + } + } + } + + if (multiplicity == Multiplicity.ONE_N || multiplicity == Multiplicity.ONE_ONE) { + if (targets.size() == 0) { + warning("No target services found for the component reference to be autowired: " + componentReference + .getName(), + componentReference); + } + } + + } else if (!componentReference.getTargets().isEmpty()) { + + // 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())) { + + Target target = new Target(targetComponent, targetComponentService); + targets.add(target); + + // 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("Incompatible interfaces on component reference and target: " + componentReference + .getName() + + " : " + + componentService.getName(), + composite); + } + } else { + // clone 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()); + + warning("Component reference target not found, it might be a remote service: " + componentService.getName(), composite); + } + } + } else if (componentReference.getReference() != null) { + + // 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())) { + + Target target = new Target(targetComponent, targetComponentService); + targets.add(target); + + // 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("Incompatible interfaces on component reference and target: " + componentReference + .getName() + + " : " + + componentService.getName(), + composite); + } + } else { + warning("Reference target not found: " + componentService.getName(), composite); + } + } + } + return targets; + } + + + /** + * 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 targets = createComponentReferenceTargets(composite, + components, + componentServices, + componentReference); + + // Select the reference bindings matching the target service bindings + List selectedBindings = new ArrayList(); + + // Handle callback + boolean bidirectional = false; + if (componentReference.getInterfaceContract() != null && componentReference.getInterfaceContract().getCallbackInterface() != null) { + bidirectional = true; + } + List selectedCallbackBindings = bidirectional ? new ArrayList() : null; + + for (Target target : targets) { + + Component targetComponent = target.getComponent(); + ComponentService targetComponentService = target.getService(); + if (targetComponentService.getService() instanceof CompositeService) { + + // Find the promoted component service + targetComponentService = ((CompositeService)targetComponentService.getService()).getPromotedService(); + } + + determinePolicySet(componentReference, targetComponentService); + + // Match the binding against the bindings of the target service + Binding selected = BindingUtil.resolveBindings(componentReference, targetComponent, targetComponentService); + if (selected == null) { + warning("Component reference doesn't have a matching binding", componentReference); + } else { + selectedBindings.add(selected); + } + if (bidirectional) { + Binding selectedCallback = BindingUtil.resolveCallbackBindings(componentReference, targetComponent, targetComponentService); + if (selectedCallback != null) { + selectedCallbackBindings.add(selectedCallback); + } + } + } + + if (!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); + } + } + } + } + + /** + * 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("Wire source not found: " + source.getName(), composite); + } + } 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("Wire target not found: " + source.getName(), composite); + } + } 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); + } else { + warning("Incompatible interfaces on wire source and target: " + source.getName() + + " : " + + target.getName(), composite); + } + } + } + + // Clear the list of wires + composite.getWires().clear(); + } + + /** + * Wire composite references in nested composites. + * + * @param composite + * @param problems + */ + public void wireCompositeReferences(Composite composite) { + + // Process nested composites recursively + // [rfeng] I comment out the following loop as there's no need to do the recursive wiring. + /* + for (Component component : composite.getComponents()) { + Implementation implementation = component.getImplementation(); + if (implementation instanceof Composite) { + wireCompositeReferences((Composite)implementation); + } + } + */ + + // Process composite references declared in this composite + for (Reference reference : composite.getReferences()) { + CompositeReference compositeReference = (CompositeReference)reference; + List promotedReferences = getPromotedComponentReferences(compositeReference); + for (ComponentReference promotedReference : promotedReferences) { + + reconcileReferenceBindings(compositeReference, promotedReference); + 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()); + } + } + } + } + + // Process the 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) { + CompositeReference compositeReference = (CompositeReference)implReference; + List promotedReferences = + getPromotedComponentReferences(compositeReference); + for (ComponentReference promotedReference : promotedReferences) { + + // Override the configuration of the promoted reference + reconcileReferenceBindings(componentReference, promotedReference); + 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 + .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(); + ComponentService componentService = compositeService.getPromotedService(); + 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); + } + } + } + } + } + } + } + + /** + * Follow a reference promotion chain down to the inner most (non composite) + * component references. + * + * @param compositeReference + * @return + */ + private List getPromotedComponentReferences(CompositeReference compositeReference) { + List componentReferences = new ArrayList(); + collectPromotedComponentReferences(compositeReference, componentReferences); + return componentReferences; + } + + /** + * Follow a reference promotion chain down to the inner most (non composite) + * component references. + * + * @param compositeReference + * @param componentReferences + * @return + */ + private 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 + */ + private void reconcileReferenceBindings(Reference reference, ComponentReference promotedReference) { + Set bindings = new HashSet(); + bindings.addAll(promotedReference.getBindings()); + bindings.addAll(reference.getBindings()); + promotedReference.getBindings().clear(); + for (Binding binding : bindings) { + if ((!(binding instanceof OptimizableBinding)) || binding.getURI() != null) { + promotedReference.getBindings().add(binding); + } + } + if (promotedReference.getMultiplicity() == Multiplicity.ONE_ONE || promotedReference.getMultiplicity() == Multiplicity.ZERO_ONE) { + if (promotedReference.getBindings().size() > 1) { + warning("Component reference " + promotedReference.getName() + " has more than one wires", + promotedReference); + } + } + 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); + } + } + } + + public void computePolicies(Composite composite) { + List compositeIntents = null; + List compositePolicySets = null; + if (composite instanceof PolicySetAttachPoint) { + compositeIntents = ((PolicySetAttachPoint)composite).getRequiredIntents(); + compositePolicySets = ((PolicySetAttachPoint)composite).getPolicySets(); + } + + //Initialize service bindings + for (Service service : composite.getServices()) { + CompositeService compositeService = (CompositeService)service; + + //inherit intents and policysets defined at composite level + addInheritedIntents(compositeIntents, service.getRequiredIntents()); + addInheritedPolicySets(compositePolicySets, service.getPolicySets(), false); + + //inherit intents and policies from promoted service + addInheritedIntents(compositeService.getPromotedService().getRequiredIntents(), + compositeService.getRequiredIntents()); + addInheritedPolicySets(compositeService.getPromotedService().getPolicySets(), + compositeService.getPolicySets(), true); + + if (compositeService.getCallback() != null) { + addInheritedIntents(compositeService.getRequiredIntents(), + compositeService.getCallback().getRequiredIntents()); + addInheritedPolicySets(compositeService.getPolicySets(), + compositeService.getCallback().getPolicySets(), + false); + } + + computeBindingIntentsAndPolicySets(service); + } + + for (Reference reference : composite.getReferences()) { + addInheritedIntents(compositeIntents, reference.getRequiredIntents()); + addInheritedPolicySets(compositePolicySets, reference.getPolicySets(), false); + + CompositeReference compReference = (CompositeReference)reference; + for ( Reference promotedReference : compReference.getPromotedReferences() ) { + addInheritedIntents(promotedReference.getRequiredIntents(), + reference.getRequiredIntents()); + + addInheritedPolicySets(promotedReference.getPolicySets(), + reference.getPolicySets(), true); + } + + if (compReference.getCallback() != null) { + addInheritedIntents(compReference.getRequiredIntents(), + compReference.getCallback().getRequiredIntents()); + addInheritedPolicySets(compReference.getPolicySets(), + compReference.getCallback().getPolicySets(), + false); + } + + computeBindingIntentsAndPolicySets(reference); + } + + for (Component component : composite.getComponents()) { + //Inherit intents defined at the composite level + addInheritedIntents(compositeIntents, component.getRequiredIntents()); + + // Inherit policysets defined at the composite level + addInheritedPolicySets(compositePolicySets, component.getPolicySets(), false); + + for (ComponentService componentService : component.getServices()) { + //inherit intents and policysets from component + addInheritedIntents(component.getRequiredIntents(), componentService.getRequiredIntents()); + addInheritedPolicySets(component.getPolicySets(), componentService.getPolicySets(), false); + + Service service = componentService.getService(); + if (service != null) { + // reconcile intents and policysets + addInheritedIntents(service.getRequiredIntents(), componentService.getRequiredIntents()); + addInheritedPolicySets(service.getPolicySets(), componentService.getPolicySets(), true); + } + + if ( componentService.getCallback() != null ) { + addInheritedIntents(componentService.getRequiredIntents(), + componentService.getCallback().getRequiredIntents()); + addInheritedPolicySets(componentService.getPolicySets(), + componentService.getCallback().getPolicySets(), + false); + } + + //compute intents and policyset for each binding + computeBindingIntentsAndPolicySets(componentService); + } + + for (ComponentReference componentReference : component.getReferences()) { + //inherit intents and policysets from component + addInheritedIntents(component.getRequiredIntents(), componentReference.getRequiredIntents()); + addInheritedPolicySets(component.getPolicySets(), componentReference.getPolicySets(), false); + + Reference reference = componentReference.getReference(); + if (reference != null) { + // reconcile intents and policysets + addInheritedIntents(reference.getRequiredIntents(), componentReference.getRequiredIntents()); + addInheritedPolicySets(reference.getPolicySets(), componentReference.getPolicySets(), true); + } + + if ( componentReference.getCallback() != null ) { + addInheritedIntents(componentReference.getRequiredIntents(), + componentReference.getCallback().getRequiredIntents()); + addInheritedPolicySets(componentReference.getPolicySets(), + componentReference.getCallback().getPolicySets(), + false); + } + + //compute intents and policyset for each binding + computeBindingIntentsAndPolicySets(componentReference); + } + } + + } + + private void addInheritedIntents(List sourceList, List targetList) { + if (sourceList != null) { + targetList.addAll(sourceList); + } + } + + private void addInheritedPolicySets(List sourceList, List targetList, boolean checkOverrides) { + //check overrides is true when policysets are to be copied from componentType to component level + if ( checkOverrides ) { + //aggregate all the provided intents present in the target + List targetProvidedIntents = new ArrayList(); + for ( PolicySet policySet : targetList ) { + targetProvidedIntents.addAll(policySet.getProvidedIntents()); + } + + //for every policy set in the source check if it provides one of the intents that is + //already provided by the policysets in the destination and do not copy them. + for ( PolicySet policySet : sourceList ) { + for ( Intent sourceProvidedIntent : policySet.getProvidedIntents() ) { + if ( !targetProvidedIntents.contains(sourceProvidedIntent) ) { + targetList.add(policySet); + } + } + } + } else { + targetList.addAll(sourceList); + } + } + + private void computeBindingIntentsAndPolicySets(Service service) { + computeIntents(service.getBindings(), service.getRequiredIntents()); + computePolicySets(service, service.getBindings(), service.getPolicySets()); + if ( service.getCallback() != null ) { + computeIntents(service.getCallback().getBindings(), + service.getCallback().getRequiredIntents()); + computePolicySets(service, + service.getCallback().getBindings(), + service.getCallback().getPolicySets()); + } + determinePolicySet(service, null); + } + + private void computeBindingIntentsAndPolicySets(Reference reference) { + computeIntents(reference.getBindings(), reference.getRequiredIntents()); + computePolicySets(reference, reference.getBindings(), reference.getPolicySets()); + + if ( reference.getCallback() != null ) { + computeIntents(reference.getCallback().getBindings(), + reference.getCallback().getRequiredIntents()); + computePolicySets(reference, + reference.getCallback().getBindings(), + reference.getCallback().getPolicySets()); + } + determinePolicySet(reference, null); + } + + private void computeIntents(List bindings, List inheritedIntents) { + boolean found = false; + List expandedIntents = null; + + for (Binding binding : bindings) { + if (binding instanceof IntentAttachPoint) { + + IntentAttachPoint policiedBinding = (IntentAttachPoint)binding; + IntentAttachPointType bindingType = policiedBinding.getType(); + + //expand profile intents specified in the binding + if ( policiedBinding.getRequiredIntents().size() > 0 ) { + expandedIntents = expandProfileIntents(policiedBinding.getRequiredIntents()); + policiedBinding.getRequiredIntents().clear(); + policiedBinding.getRequiredIntents().addAll(expandedIntents); + } + + //validate intents specified for the binding + for (Intent intent : policiedBinding.getRequiredIntents()) { + for (QName constrained : intent.getConstrains()) { + if (bindingType.getName().getNamespaceURI().equals(constrained + .getNamespaceURI()) && bindingType.getName().getLocalPart() + .startsWith(constrained.getLocalPart())) { + found = true; + break; + } + } + + if (!found) { + warning("Policy Intent '" + intent.getName() + + "' does not constrain binding type " + + bindingType, binding); + } + } + + //expand profile intents in inherited intents + expandedIntents = expandProfileIntents(inheritedIntents); + inheritedIntents.clear(); + inheritedIntents.addAll(expandedIntents); + + //validate if inherited intent applies to the binding and + //only add such intents to the binding + for (Intent intent : inheritedIntents) { + for (QName constrained : intent.getConstrains()) { + if (bindingType.getName().getNamespaceURI().equals(constrained + .getNamespaceURI()) && bindingType.getName().getLocalPart() + .startsWith(constrained.getLocalPart())) { + policiedBinding.getRequiredIntents().add(intent); + break; + } + } + } + + Map intentsTable = new HashMap(); + //remove duplicates + for ( Intent intent : policiedBinding.getRequiredIntents() ) { + intentsTable.put(intent.getName(), 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()); + } + } + } + policiedBinding.getRequiredIntents().clear(); + policiedBinding.getRequiredIntents().addAll(intentsTable.values()); + + //exclude intents that are inherently supported by the binding type + List requiredIntents = new ArrayList(policiedBinding.getRequiredIntents()); + for ( Intent intent : requiredIntents ) { + if ( bindingType.getAlwaysProvidedIntents() != null && + bindingType.getAlwaysProvidedIntents().contains(intent) ) { + policiedBinding.getRequiredIntents().remove(intent); + } + } + + } + } + } + + private void computePolicySets(Base parent, + List bindings, + List inheritedPolicySets) { + String appliesTo = null; + HashMap policySetTable = new HashMap(); + + for (Binding binding : bindings) { + if (binding instanceof PolicySetAttachPoint) { + PolicySetAttachPoint policiedBinding = (PolicySetAttachPoint)binding; + IntentAttachPointType bindingType = policiedBinding.getType(); + + //validate policysets specified for the binding + for (PolicySet policySet : policiedBinding.getPolicySets()) { + appliesTo = policySet.getAppliesTo(); + + if (!isPolicySetApplicable(parent, appliesTo, bindingType)) { + warning("Policy Set '" + policySet.getName() + + "' does not apply to binding type " + + bindingType, binding); + + } + } + + for (PolicySet policySet : inheritedPolicySets) { + appliesTo = policySet.getAppliesTo(); + if (isPolicySetApplicable(parent, appliesTo, bindingType)) { + policiedBinding.getPolicySets().add(policySet); + } + } + + //get rid of duplicate entries + for ( PolicySet policySet : policiedBinding.getPolicySets() ) { + policySetTable.put(policySet.getName(), policySet); + } + policiedBinding.getPolicySets().clear(); + policiedBinding.getPolicySets().addAll(policySetTable.values()); + + //expand profile intents + List expandedIntents = null; + for ( PolicySet policySet : policiedBinding.getPolicySets() ) { + expandedIntents = expandProfileIntents(policySet.getProvidedIntents()); + policySet.getProvidedIntents().clear(); + policySet.getProvidedIntents().addAll(expandedIntents); + } + } + } + } + + private boolean isPolicySetApplicable(Base parent, + String xpath, + IntentAttachPointType bindingType) { + + //FIXME: For now do a simple check and later implement whatever is mentioned in the next comment + if ( xpath != null && bindingType != null && xpath.indexOf(bindingType.getName().getLocalPart()) != -1) { + return true; + } else { + return false; + } + + + //create a xml node out of the parent object.. i.e. write the parent object as scdl fragment + //invoke PropertyUtil.evaluate(null, node, xpath) + //verify the result Node's QName against the bindingType's name + + /*if (parent instanceof ComponentReference) { + } else if (parent instanceof ComponentReference) { + } else if (parent instanceof Component) { + } else if (parent instanceof CompositeService) { + } else if (parent instanceof CompositeReference) { + + } + return true;*/ + } + + private List expandProfileIntents(List intents) { + List expandedIntents = new ArrayList(); + for ( Intent intent : intents ) { + if ( intent instanceof ProfileIntent ) { + ProfileIntent profileIntent = (ProfileIntent)intent; + List requiredIntents = profileIntent.getRequiredIntents(); + expandedIntents.addAll(expandProfileIntents(requiredIntents)); + } else { + expandedIntents.add(intent); + } + } + return expandedIntents; + } + + + private 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 void trimProvidedIntents(List requiredIntents, List policySets) { + for ( PolicySet policySet : policySets ) { + trimProvidedIntents(requiredIntents, policySet); + } + } + + + + private void determineDomainPolicySets(Contract contract, PolicySetAttachPoint policiedBinding) { + if ( domainPolicySets != null && policiedBinding.getRequiredIntents().size() > 0 ) { + IntentAttachPointType bindingType = policiedBinding.getType(); + for ( PolicySet policySet : domainPolicySets ) { + if ( isPolicySetApplicable(contract, policySet.getAppliesTo(), bindingType) ) { + int prevSize = policiedBinding.getRequiredIntents().size(); + trimProvidedIntents(policiedBinding.getRequiredIntents(), policySet); + //if any intent was trimmed off, then this policyset must be attached to the binding + if ( prevSize != policiedBinding.getRequiredIntents().size() ) { + policiedBinding.getPolicySets().add(policySet); + } + } + } + + if ( policiedBinding.getRequiredIntents().size() > 0 ) { + if ( contract instanceof Service ) { + warning("There are unfulfilled intents for binding in service - " + contract.getName(), contract); + } else { + warning("There are unfulfilled intents for binding in reference - " + contract.getName(), contract); + } + } + } + } + + + private void determinePolicySet(Contract source, Contract target) { + + for ( Binding aBinding : source.getBindings() ) { + if ( aBinding instanceof PolicySetAttachPoint ) { + PolicySetAttachPoint policiedBinding = (PolicySetAttachPoint)aBinding; + IntentAttachPointType bindingType = policiedBinding.getType(); + + //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.getName().getNamespaceURI().equals(constrained + .getNamespaceURI()) && bindingType.getName().getLocalPart() + .startsWith(constrained.getLocalPart())) { + policiedBinding.getRequiredIntents().add(intent); + break; + } + } + } + } + } + + 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 + determineDomainPolicySets(source, policiedBinding); + } + } + } + + +} diff --git a/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/PrintUtil.java b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/PrintUtil.java new file mode 100644 index 0000000000..efd10bfe9a --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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 hierachy 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/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ProblemImpl.java b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ProblemImpl.java new file mode 100644 index 0000000000..848700ac7f --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ProblemImpl.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.assembly.builder.impl; + +import java.io.PrintWriter; +import java.io.StringWriter; + +import org.apache.tuscany.sca.assembly.builder.Problem; + +/** + * Reports a composite assembly problem. + * + * @version $Rev$ $Date$ + */ +public class ProblemImpl implements Problem { + + private String message; + private Severity severity; + private Object model; + private Object resource; + private Exception cause; + + /** + * Constructs a new problem. + * + * @param severity + * @param message + * @param model + */ + public ProblemImpl(Severity severity, String message, Object model) { + this.severity = severity; + this.message = message; + this.model = model; + } + + /** + * Constructs a new problem. + * + * @param severity + * @param message + * @param model + * @param resource + */ + public ProblemImpl(Severity severity, String message, Object model, Object resource) { + this.severity = severity; + this.message = message; + this.model = model; + this.resource = resource; + } + + /** + * Constructs a new problem. + * + * @param severity + * @param message + * @param cause + */ + public ProblemImpl(Severity severity, String message, Exception cause) { + this.severity = severity; + this.message = message; + this.cause = cause; + } + + public Severity getSeverity() { + return severity; + } + + public String getMessage() { + return message; + } + + public Object getModel() { + return model; + } + + public Object getResource() { + return resource; + } + + public Exception getCause() { + return cause; + } + + @Override + public String toString() { + StringWriter sw = new StringWriter(); + PrintWriter writer = new PrintWriter(sw); + writer.format("[%s] %s %s", severity, message, resource); + //PrintUtil util = new PrintUtil(writer, false); + //if (model != null) { + // writer.println(); + // util.print(model); + //} + if (cause != null) { + writer.println(); + cause.printStackTrace(writer); + } + return sw.toString(); + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/PropertyUtil.java b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/PropertyUtil.java new file mode 100644 index 0000000000..2a73de11ae --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/PropertyUtil.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.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.util.Iterator; +import java.util.List; +import java.util.Map; + +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.XPath; +import javax.xml.xpath.XPathConstants; +import javax.xml.xpath.XPathExpression; +import javax.xml.xpath.XPathExpressionException; +import javax.xml.xpath.XPathFactory; + +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.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. + */ +public class PropertyUtil { + private static final XPathFactory XPATH_FACTORY = XPathFactory.newInstance(); + private static final DocumentBuilderFactory DOC_BUILDER_FACTORY = DocumentBuilderFactory.newInstance(); + private static final TransformerFactory TRANSFORMER_FACTORY = TransformerFactory.newInstance(); + + static private Document evaluate(NamespaceContext nsContext, Node node, String xPathExpression) + throws XPathExpressionException, ParserConfigurationException { + XPath path = XPATH_FACTORY.newXPath(); + + if (nsContext != null) { + path.setNamespaceContext(nsContext); + } else { + path.setNamespaceContext(new DOMNamespaceContext(node)); + } + + XPathExpression expression = path.compile(xPathExpression); + Node result = (Node)expression.evaluate(node, XPathConstants.NODE); + if (result == null) { + return null; + } + + // TODO: How to wrap the result into a Document? + Document document = DOC_BUILDER_FACTORY.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; + } + } + + static private Document loadFromFile(String file) throws MalformedURLException, IOException, + TransformerException, ParserConfigurationException { + URI uri = URI.create(file); + URL url = null; + if (!uri.isAbsolute()) { + //FIXME Should already be given an absolute file + url = Thread.currentThread().getContextClassLoader().getResource(file); + } else { + url = uri.toURL(); + } + InputStream is = url.openStream(); + + Source streamSource = new SAXSource(new InputSource(is)); + DOMResult result = new DOMResult(); + javax.xml.transform.Transformer transformer = TRANSFORMER_FACTORY.newTransformer(); + transformer.transform(streamSource, result); + is.close(); + + return (Document)result.getNode(); + } + + static void sourceComponentProperties(Map compositeProperties, + Component componentDefinition) 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(); + + // Adding /value because the document root is "value" + String path = source.substring(index); + String xpath = null; + + if ("/".equals(path)) { + // trailing / is not legal for xpath + xpath = "/value"; + } else { + xpath = "/value" + path; + } + + // FIXME: How to deal with namespaces? + Document node = evaluate(null, compositePropDefValues, xpath); + + 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())); + + } + } + } + + private static class DOMNamespaceContext implements NamespaceContext { + private Node node; + + /** + * @param node + */ + public DOMNamespaceContext(Node node) { + super(); + this.node = node; + } + + public String getNamespaceURI(String prefix) { + return node.lookupNamespaceURI(prefix); + } + + public String getPrefix(String namespaceURI) { + return node.lookupPrefix(namespaceURI); + } + + public Iterator getPrefixes(String namespaceURI) { + return null; + } + + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ReferenceUtil.java b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ReferenceUtil.java new file mode 100644 index 0000000000..a4599e96f6 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ReferenceUtil.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.builder.impl; + +import java.util.List; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.Multiplicity; +import org.apache.tuscany.sca.assembly.OptimizableBinding; + +/** + * This class encapsulates utility methods to deal with reference definitions + * + */ +class ReferenceUtil { + 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; + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/AbstractPropertyImpl.java b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/AbstractPropertyImpl.java new file mode 100644 index 0000000000..270121f901 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/AbstractPropertyImpl.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.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) { + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/AbstractReferenceImpl.java b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/AbstractReferenceImpl.java new file mode 100644 index 0000000000..d0ee3832c5 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/AbstractServiceImpl.java b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/AbstractServiceImpl.java new file mode 100644 index 0000000000..346764b1b4 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/AssemblyFactoryImpl.java b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/AssemblyFactoryImpl.java new file mode 100644 index 0000000000..1e623d35f2 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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.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; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.impl.OperationImpl; + +/** + * 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 Operation createOperation() { + return new OperationImpl(); + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/BaseImpl.java b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/BaseImpl.java new file mode 100644 index 0000000000..553e600bc9 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/CallbackImpl.java b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/CallbackImpl.java new file mode 100644 index 0000000000..f9c08e84a0 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/CallbackImpl.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 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.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(); + + 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) { + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentImpl.java b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentImpl.java new file mode 100644 index 0000000000..c74b908e5c --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentImpl.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.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.ConstrainingType; +import org.apache.tuscany.sca.assembly.Implementation; +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 { + 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; + + /** + * 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; + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentPropertyImpl.java b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentPropertyImpl.java new file mode 100644 index 0000000000..512ab0d2d0 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentPropertyImpl.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 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; + + /** + * 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; + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentReferenceImpl.java b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentReferenceImpl.java new file mode 100644 index 0000000000..63a4def855 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentReferenceImpl.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.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.CompositeReference; +import org.apache.tuscany.sca.assembly.Reference; + +/** + * 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; + + /** + * 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; + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentServiceImpl.java b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentServiceImpl.java new file mode 100644 index 0000000000..0c78a2505f --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentTypeImpl.java b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentTypeImpl.java new file mode 100644 index 0000000000..238e0c3d1e --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentTypeImpl.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.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; +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; + +/** + * Represents a component type. + * + * @version $Rev$ $Date$ + */ +public class ComponentTypeImpl extends ExtensibleImpl implements ComponentType, Cloneable, PolicySetAttachPoint { + private String uri; + private ConstrainingType constrainingType; + 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(); + + /** + * 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; + } + + public List getRequiredIntents() { + return requiredIntents; + } + + public List getPolicySets() { + return policySets; + } + + public IntentAttachPointType getType() { + return null; + } + + public void setType(IntentAttachPointType type) { + } + + @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/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/CompositeImpl.java b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/CompositeImpl.java new file mode 100644 index 0000000000..49815fceb9 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/CompositeImpl.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.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; + +public class CompositeImpl extends ComponentTypeImpl 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; + } + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/CompositeReferenceImpl.java b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/CompositeReferenceImpl.java new file mode 100644 index 0000000000..4348e08fcb --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/CompositeReferenceImpl.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.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 { + return super.clone(); + } + + public List getPromotedReferences() { + return promotedReferences; + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/CompositeServiceImpl.java b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/CompositeServiceImpl.java new file mode 100644 index 0000000000..6777a96982 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ConstrainingTypeImpl.java b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ConstrainingTypeImpl.java new file mode 100644 index 0000000000..14dee9f36b --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ConstrainingTypeImpl.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.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) { + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ContractImpl.java b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ContractImpl.java new file mode 100644 index 0000000000..358075fc96 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ContractImpl.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.impl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.sca.assembly.AbstractContract; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.policy.Intent; +import org.apache.tuscany.sca.policy.IntentAttachPointType; + +public class ContractImpl extends ExtensibleImpl implements AbstractContract { + private InterfaceContract interfaceContract; + private String name; + private List requiredIntents = 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) { + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ExtensibleImpl.java b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ExtensibleImpl.java new file mode 100644 index 0000000000..9a7ca09e43 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ExtensibleImpl.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.impl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.sca.assembly.Extensible; + +/** + * Convenience base class for extensible assembly model objects. + * + * @version $Rev$ $Date$ + */ +public abstract class ExtensibleImpl extends BaseImpl implements Extensible { + private List extensions = new ArrayList(); + + /** + * Constructs a new base model object. + */ + protected ExtensibleImpl() { + } + + public List getExtensions() { + return extensions; + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/PropertyImpl.java b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/PropertyImpl.java new file mode 100644 index 0000000000..518f9d2b40 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/PropertyImpl.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.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(); + + /** + * Constructs a new property. + */ + protected PropertyImpl() { + } + + @Override + public Object clone() throws CloneNotSupportedException { + return super.clone(); + } + + public List getPolicySets() { + return policySets; + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ReferenceImpl.java b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ReferenceImpl.java new file mode 100644 index 0000000000..314ddb113c --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ReferenceImpl.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.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.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; + + /** + * 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 List getPolicySets() { + return policySets; + } + + public List getTargets() { + return targets; + } + + public Callback getCallback() { + return callback; + } + + public void setCallback(Callback callback) { + this.callback = callback; + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ServiceImpl.java b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ServiceImpl.java new file mode 100644 index 0000000000..5a6e2486fe --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ServiceImpl.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.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.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; + + /** + * 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; + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/WireImpl.java b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/WireImpl.java new file mode 100644 index 0000000000..0fa1512156 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/WireImpl.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.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(); + + /** + * 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) { + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/assembly/src/main/resources/META-INF/services/org.apache.tuscany.sca.assembly.AssemblyFactory b/tags/java/sca/1.0-RC1b/modules/assembly/src/main/resources/META-INF/services/org.apache.tuscany.sca.assembly.AssemblyFactory new file mode 100644 index 0000000000..859c4bde4b --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/AssemblyFactoryTestCase.java b/tags/java/sca/1.0-RC1b/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/AssemblyFactoryTestCase.java new file mode 100644 index 0000000000..767b152624 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/AssemblyFactoryTestCase.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; + +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 { + + AssemblyFactory factory; + + @Override + public void setUp() throws Exception { + factory = new DefaultAssemblyFactory(); + } + + @Override + public void tearDown() throws Exception { + factory = null; + } + + public void testCreateComponent() { + createComponent("AccountServiceComponent1"); + } + + public void testCreateComponentType() { + createComponentType(); + } + + public void testCreateComposite() { + createComposite(); + } + + public void testCreateConstrainingType() { + createConstrainingType(); + } + + /** + * 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; + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestBinding.java b/tags/java/sca/1.0-RC1b/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestBinding.java new file mode 100644 index 0000000000..338c2d93bb --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestBinding.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.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; + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestImplementation.java b/tags/java/sca/1.0-RC1b/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestImplementation.java new file mode 100644 index 0000000000..61ca3945ea --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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.ComponentTypeImpl; + +/** + * A test component implementation model. + * + * @version $Rev$ $Date$ + */ +public class TestImplementation extends ComponentTypeImpl 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/tags/java/sca/1.0-RC1b/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestInterface.java b/tags/java/sca/1.0-RC1b/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestInterface.java new file mode 100644 index 0000000000..dbe0cb8225 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestInterfaceContract.java b/tags/java/sca/1.0-RC1b/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestInterfaceContract.java new file mode 100644 index 0000000000..ee6b95edc9 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestOperation.java b/tags/java/sca/1.0-RC1b/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestOperation.java new file mode 100644 index 0000000000..d94a7e93a3 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBuilderTestCase.java b/tags/java/sca/1.0-RC1b/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBuilderTestCase.java new file mode 100644 index 0000000000..854d15f546 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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; + +public class CompositeBuilderTestCase extends TestCase { + + private AssemblyFactory assemblyFactory; + + @Override + protected void setUp() throws Exception { + assemblyFactory = new DefaultAssemblyFactory(); + } + + @Override + protected void tearDown() throws Exception { + assemblyFactory = null; + } + + public void testFuseIncludes() { + 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).fuseIncludes(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() { + 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).expandCompositeImplementations(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/tags/java/sca/1.0-RC1b/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/builder/impl/PrintUtilTestCase.java b/tags/java/sca/1.0-RC1b/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/builder/impl/PrintUtilTestCase.java new file mode 100644 index 0000000000..b71e04551a --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/builder/impl/PrintUtilTestCase.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.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.apache.tuscany.sca.assembly.builder.impl.PrintUtil; +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/tags/java/sca/1.0-RC1b/modules/binding-dwr/DISCLAIMER b/tags/java/sca/1.0-RC1b/modules/binding-dwr/DISCLAIMER new file mode 100644 index 0000000000..d68a410903 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-dwr/DISCLAIMER @@ -0,0 +1,8 @@ +Apache Tuscany is an effort undergoing incubation at The Apache Software +Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is +required of all newly accepted projects until a further review indicates that +the infrastructure, communications, and decision making process have stabilized +in a manner consistent with other successful ASF projects. While incubation +status is not necessarily a reflection of the completeness or stability of the +code, it does indicate that the project has yet to be fully endorsed by the ASF. + diff --git a/tags/java/sca/1.0-RC1b/modules/binding-dwr/LICENSE b/tags/java/sca/1.0-RC1b/modules/binding-dwr/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-dwr/NOTICE b/tags/java/sca/1.0-RC1b/modules/binding-dwr/NOTICE new file mode 100644 index 0000000000..94481d6cfa --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-dwr/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2007 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/tags/java/sca/1.0-RC1b/modules/binding-dwr/pom.xml b/tags/java/sca/1.0-RC1b/modules/binding-dwr/pom.xml new file mode 100644 index 0000000000..d77436fb20 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-dwr/pom.xml @@ -0,0 +1,76 @@ + + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.0-incubating + ../pom.xml + + + tuscany-binding-dwr + Apache Tuscany SCA AJAX DWR Binding Extension + + + + + org.apache.tuscany.sca + tuscany-extension-helper + 1.0-incubating + + + + org.apache.tuscany.sca + tuscany-host-http + 1.0-incubating + + + + org.directwebremoting + dwr + 2.0.1 + + + + javax.servlet + servlet-api + 2.4 + provided + + + + junit + junit + 4.2 + test + + + + org.easymock + easymock + 2.2 + test + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRBinding.java b/tags/java/sca/1.0-RC1b/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRBinding.java new file mode 100644 index 0000000000..f2ed343ea0 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRBinding.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.dwr; + + + + +/** + * The runtime representation of the SCDL + */ +public class DWRBinding { + + // Empty as doesn't use any additional attributes or elements (yet). + +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRBindingActivator.java b/tags/java/sca/1.0-RC1b/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRBindingActivator.java new file mode 100644 index 0000000000..281be750d1 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRBindingActivator.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.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; + +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/tags/java/sca/1.0-RC1b/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRInvoker.java b/tags/java/sca/1.0-RC1b/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRInvoker.java new file mode 100644 index 0000000000..ab40ae40cb --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRInvoker.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.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; + +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/tags/java/sca/1.0-RC1b/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRInvokerFactory.java b/tags/java/sca/1.0-RC1b/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRInvokerFactory.java new file mode 100644 index 0000000000..c6697e1b46 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRInvokerFactory.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.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; + +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/tags/java/sca/1.0-RC1b/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRService.java b/tags/java/sca/1.0-RC1b/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRService.java new file mode 100644 index 0000000000..a99c9cfb65 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRService.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.dwr; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.core.invocation.JDKProxyFactory; +import org.apache.tuscany.sca.core.invocation.ProxyFactory; +import org.apache.tuscany.sca.extension.helper.ComponentLifecycle; +import org.apache.tuscany.sca.host.http.ServletHost; +import org.apache.tuscany.sca.interfacedef.java.JavaInterface; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + +public class DWRService implements ComponentLifecycle { + + 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.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); + } + + Class type = ((JavaInterface)rcs.getInterfaceContract().getInterface()).getJavaClass(); + + // Create a Java proxy to the target service + ProxyFactory proxyFactory = new JDKProxyFactory(); + Object proxy = proxyFactory.createProxy(type, rcs.getRuntimeWire(binding)); + + servlet.addService(binding.getName(), type, proxy); + } + + public void stop() { + servletHost.removeServletMapping(SERVLET_PATH); + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRServlet.java b/tags/java/sca/1.0-RC1b/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRServlet.java new file mode 100644 index 0000000000..8960ba8d96 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRServlet.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.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" + */ +public class DWRServlet extends DwrServlet { + private static final long serialVersionUID = 1L; + + transient private Map services; + transient private List referenceNames; + transient private boolean initialized; + transient private 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/tags/java/sca/1.0-RC1b/modules/binding-dwr/src/main/resources/META-INF/services/org.apache.tuscany.sca.extension.helper.BindingActivator b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-ejb/DISCLAIMER b/tags/java/sca/1.0-RC1b/modules/binding-ejb/DISCLAIMER new file mode 100644 index 0000000000..d68a410903 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-ejb/DISCLAIMER @@ -0,0 +1,8 @@ +Apache Tuscany is an effort undergoing incubation at The Apache Software +Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is +required of all newly accepted projects until a further review indicates that +the infrastructure, communications, and decision making process have stabilized +in a manner consistent with other successful ASF projects. While incubation +status is not necessarily a reflection of the completeness or stability of the +code, it does indicate that the project has yet to be fully endorsed by the ASF. + diff --git a/tags/java/sca/1.0-RC1b/modules/binding-ejb/LICENSE b/tags/java/sca/1.0-RC1b/modules/binding-ejb/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-ejb/NOTICE b/tags/java/sca/1.0-RC1b/modules/binding-ejb/NOTICE new file mode 100644 index 0000000000..94481d6cfa --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-ejb/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2007 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/tags/java/sca/1.0-RC1b/modules/binding-ejb/pom.xml b/tags/java/sca/1.0-RC1b/modules/binding-ejb/pom.xml new file mode 100644 index 0000000000..9588dbf4d4 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-ejb/pom.xml @@ -0,0 +1,136 @@ + + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.0-incubating + ../pom.xml + + + tuscany-binding-ejb + Apache Tuscany SCA EJB Binding Extension + + + + + org.apache.tuscany.sca + tuscany-extension-helper + 1.0-incubating + + + + org.apache.geronimo.specs + geronimo-ejb_3.0_spec + 1.0 + compile + + + + cglib + cglib-nodep + 2.1_3 + compile + + + + junit + junit + 4.2 + test + + + + org.easymock + easymock + 2.2 + test + + + + org.apache.tuscany.sca + tuscany-implementation-java-runtime + 1.0-incubating + test + + + + org.apache.geronimo.modules + geronimo-openejb + 2.0.1 + 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 + + + + + + + + + + + geronimo-repository + Geronimo Repository + http://svn.apache.org/repos/asf/geronimo/server/tags/2.0.1/repository + default + + false + + + true + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/EJBBinding.java b/tags/java/sca/1.0-RC1b/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/EJBBinding.java new file mode 100644 index 0000000000..c4b72ed274 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/EJBBinding.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.ejb; + + + +/** + * An implementation of EJBBinding. + */ +public class EJBBinding { + + /** + * corba location For exmaple, + * "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; + + /** + * 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; + } + + // TODO: uri needs to be part of runtime extension helper + + /** + * Sets binding URI. + * + * @param value the binding uri + */ + public void setUri(String value) { + this.uri = value; + } + + /** + * gets binding URI. + * + * @return value the binding uri + */ + public String getUri() { + return uri; + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/EJBBindingActivator.java b/tags/java/sca/1.0-RC1b/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/EJBBindingActivator.java new file mode 100644 index 0000000000..4cc95e2c90 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/EJBBindingActivator.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.ejb; + +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.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.java.JavaInterface; +import org.apache.tuscany.sca.invocation.Invoker; +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; + +public class EJBBindingActivator implements BindingActivator { + + public InvokerFactory createInvokerFactory(RuntimeComponent rc, RuntimeComponentReference rcr, final Binding b, final EJBBinding binding) { + // TODO: assumes a Java interface, need to support tuscany generic Interface + final Class si = ((JavaInterface)rcr.getInterfaceContract().getInterface()).getJavaClass(); + return new InvokerFactory() { + public Invoker createInvoker(Operation operation) { + return new EJBTargetInvoker((EJBBinding)binding, si, operation); + } + }; + } + + public ComponentLifecycle createService(RuntimeComponent rc, RuntimeComponentService rcs, Binding b, EJBBinding binding) { + throw new ServiceRuntimeException("services not yet implemented for binding.ejb"); + } + + public Class getBindingClass() { + return EJBBinding.class; + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/EJBBindingsActivator.java b/tags/java/sca/1.0-RC1b/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/EJBBindingsActivator.java new file mode 100644 index 0000000000..31a5a3e652 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/EJBBindingsActivator.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.ejb; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.xml.Constants; +import org.apache.tuscany.sca.core.ModuleActivator; +import org.apache.tuscany.sca.extension.helper.impl.BindingsActivator; + +public class EJBBindingsActivator extends BindingsActivator implements ModuleActivator { + + @Override + protected QName getBindingQName(Class bindingClass) { + return new QName(Constants.SCA10_NS, "binding.ejb"); + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/EJBTargetInvoker.java b/tags/java/sca/1.0-RC1b/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/EJBTargetInvoker.java new file mode 100644 index 0000000000..9a9ccb61c4 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/EJBTargetInvoker.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.ejb; + +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; + +/** + * EJBTargetInvoker + */ +public class EJBTargetInvoker implements Invoker { + + private Operation operation; + private String location; + private Class serviceInterface; + + public EJBTargetInvoker(EJBBinding ejbBinding, Class serviceInterface, Operation operation) { + this.serviceInterface = serviceInterface; + this.location = ejbBinding.getUri(); + this.operation = operation; + } + + public Message invoke(Message msg) { + try { + Object resp = doInvoke(msg.getBody()); + msg.setBody(resp); + } catch (Throwable e) { + e.printStackTrace(); + msg.setFaultBody(e); + } + 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); + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/corba/ClassLoadingUtil.java b/tags/java/sca/1.0-RC1b/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/corba/ClassLoadingUtil.java new file mode 100644 index 0000000000..543bd51d60 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-ejb/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$ + */ +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 + // dimentions, which is not unlike a black hole sigularity. + 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 sorce 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/tags/java/sca/1.0-RC1b/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/corba/DynamicStubClassLoader.java b/tags/java/sca/1.0-RC1b/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/corba/DynamicStubClassLoader.java new file mode 100644 index 0000000000..cff632eb3d --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-ejb/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 final static 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.omb.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/tags/java/sca/1.0-RC1b/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/corba/Java2IDLUtil.java b/tags/java/sca/1.0-RC1b/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/corba/Java2IDLUtil.java new file mode 100644 index 0000000000..9e512e83af --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-ejb/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 initialze 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 spec 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 bbe 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 gettter 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 occurnace of the specified "oldChar" with the nes 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 contianing 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/tags/java/sca/1.0-RC1b/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/corba/ObjectInputStreamExt.java b/tags/java/sca/1.0-RC1b/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/corba/ObjectInputStreamExt.java new file mode 100644 index 0000000000..1be4a98a48 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-ejb/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/tags/java/sca/1.0-RC1b/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/corba/StubMethodInterceptor.java b/tags/java/sca/1.0-RC1b/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/corba/StubMethodInterceptor.java new file mode 100644 index 0000000000..3ff0ed552a --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-ejb/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/tags/java/sca/1.0-RC1b/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/corba/UtilInitializer.java b/tags/java/sca/1.0-RC1b/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/corba/UtilInitializer.java new file mode 100644 index 0000000000..f9aa9ffa22 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-ejb/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/tags/java/sca/1.0-RC1b/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/util/EJBHandler.java b/tags/java/sca/1.0-RC1b/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/util/EJBHandler.java new file mode 100644 index 0000000000..945427ced2 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/util/EJBHandler.java @@ -0,0 +1,336 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, 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 + */ +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 + public 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 + */ + protected 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 + */ + protected 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 + */ + protected 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 + */ + protected Object readValue(InputStream in, Class type) { + return org.apache.tuscany.sca.binding.ejb.corba.Java2IDLUtil.readObject(type, in); + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/util/EJBLocator.java b/tags/java/sca/1.0-RC1b/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/util/EJBLocator.java new file mode 100644 index 0000000000..89d6e1bf55 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/util/EJBLocator.java @@ -0,0 +1,481 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, 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 + */ +public 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; + boolean managed = true; + + public 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); + } + } + + public EJBLocator(String hostName, int port) { + this.hostName = (hostName == null) ? DEFAULT_HOST : hostName; + this.port = port > 0 ? port : DEFAULT_NAMING_PORT; + this.root = SERVER_ROOT; + } + + public 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"); + } + } + + public 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 exmaple, + * "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 gotta 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; + } + } + + /** + * Resovled the JNDI name from the initial CosNaming context + * + * @param jndiName + * @return resovled CORBA ojbect + * @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) { + // Esacpe . into \. since it's an INS naming delimeter + return replace(encode2396(jndiName), ".", "\\."); + } + + /** + * Escape the "." into "%5C%2E" + * + * @param jndiName + * @return corbaname treating "." as a literal + */ + private static String toCorbaname(String jndiName) { + // Esacpe . into %5C%2E (\.) since it's an INS naming delimeter + // 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/tags/java/sca/1.0-RC1b/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/util/EJBObjectFactory.java b/tags/java/sca/1.0-RC1b/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/util/EJBObjectFactory.java new file mode 100644 index 0000000000..14a7e94e48 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/util/EJBObjectFactory.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.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; + +public 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 avaiable in the classpath. + *

+ */ + public 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 + */ + protected 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 + */ + protected static 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 + */ + protected 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 + */ + protected 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/tags/java/sca/1.0-RC1b/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/util/EJBStubHelper.java b/tags/java/sca/1.0-RC1b/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/util/EJBStubHelper.java new file mode 100644 index 0000000000..95d0542e4f --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-ejb/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; + +public final class EJBStubHelper { + + private static Object stub; + private static ServiceRuntimeException exception; + + private EJBStubHelper() { + } + + /** + * @param owner + * @param jndiName + * @return + */ + + public static Object lookup(NamingEndpoint endpoint, InterfaceInfo ejbInterface) { + return getStub(endpoint, ejbInterface); + } + + public 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/tags/java/sca/1.0-RC1b/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/util/InterfaceInfo.java b/tags/java/sca/1.0-RC1b/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/util/InterfaceInfo.java new file mode 100644 index 0000000000..c05f9ad631 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/util/InterfaceInfo.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.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; + +// import commonj.sdo.DataObject; + +/** + * The signature for a java interface + */ +public 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(); + + public 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); + } + } + + public static synchronized final 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 + */ + public Map getMethods() { + return methods; + } + + /** + * @return + */ + public MethodInfo getMethod(String name) { + return (MethodInfo)methods.get(name); + } + + /** + * @return + */ + public 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/tags/java/sca/1.0-RC1b/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/util/JavaReflectionAdapter.java b/tags/java/sca/1.0-RC1b/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/util/JavaReflectionAdapter.java new file mode 100644 index 0000000000..6a96b14d78 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/util/JavaReflectionAdapter.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.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. + */ +public 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 + 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 + */ + public 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 + */ + public 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 + */ + public Map getMethods() { + return methodMap; + } + + /** + * Invoke a method using Java reflection. + * + * @param method + * @param object + * @param args + * @return + * @throws InvocationTargetException + * @throws IllegalAccessException + */ + public 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 + */ + public 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/tags/java/sca/1.0-RC1b/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/util/MethodInfo.java b/tags/java/sca/1.0-RC1b/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/util/MethodInfo.java new file mode 100644 index 0000000000..e6f4032d06 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/util/MethodInfo.java @@ -0,0 +1,187 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, 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 + */ +public 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 final static 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); + } + + public 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; + } + + protected 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 + */ + public String getName() { + return name; + } + + /** + * @return + */ + public String[] getParameterTypes() { + return parameterTypes; + } + + /** + * @return + */ + public String getReturnType() { + return returnType; + } + + /** + * @return + */ + public 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. + */ + public String getIDLName() { + return IDLName; + } + + /** + * @param name The iDLName to set. + */ + public void setIDLName(String name) { + IDLName = name; + } + + /** + * @return the method + */ + public Method getMethod() { + return method; + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/util/NamingEndpoint.java b/tags/java/sca/1.0-RC1b/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/util/NamingEndpoint.java new file mode 100644 index 0000000000..1d99f157bb --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-ejb/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 exmaple, + * "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/tags/java/sca/1.0-RC1b/modules/binding-ejb/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator b/tags/java/sca/1.0-RC1b/modules/binding-ejb/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator new file mode 100644 index 0000000000..f935bb989d --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-ejb/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator @@ -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-ejb +org.apache.tuscany.sca.binding.ejb.EJBBindingsActivator diff --git a/tags/java/sca/1.0-RC1b/modules/binding-ejb/src/main/resources/META-INF/services/org.apache.tuscany.sca.extension.helper.BindingActivator b/tags/java/sca/1.0-RC1b/modules/binding-ejb/src/main/resources/META-INF/services/org.apache.tuscany.sca.extension.helper.BindingActivator new file mode 100644 index 0000000000..1e69e1a07c --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-ejb/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.ejb.EJBBindingActivator + diff --git a/tags/java/sca/1.0-RC1b/modules/binding-ejb/src/test/java/account/BankManagerFacade.java b/tags/java/sca/1.0-RC1b/modules/binding-ejb/src/test/java/account/BankManagerFacade.java new file mode 100644 index 0000000000..a8100d280b --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-ejb/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 + * + */ +@Remotable +public interface BankManagerFacade +{ + public java.lang.Double getAccountBalance( java.lang.String accountNo ); + public void changeAccountBalance( java.lang.String accountNo,java.lang.Double balance ); +} \ No newline at end of file diff --git a/tags/java/sca/1.0-RC1b/modules/binding-ejb/src/test/java/account/Customer.java b/tags/java/sca/1.0-RC1b/modules/binding-ejb/src/test/java/account/Customer.java new file mode 100644 index 0000000000..3c39a73586 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-ejb/src/test/java/account/Customer.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 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 String amount to be deposited + * @return total amount in customer accound after deposit + */ + Double depositAmount(java.lang.String accountNo, Double amount); + +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-ejb/src/test/java/account/CustomerImpl.java b/tags/java/sca/1.0-RC1b/modules/binding-ejb/src/test/java/account/CustomerImpl.java new file mode 100644 index 0000000000..3d3f785a50 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-ejb/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.AddService; + +@Service(Customer.class) +public class CustomerImpl implements Customer { + + private AddService extEJBService = null; + + public AddService getExtEJBService() { + return extEJBService; + } + + @Reference + public void setExtEJBService(AddService 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/tags/java/sca/1.0-RC1b/modules/binding-ejb/src/test/java/calculator/AddService.java b/tags/java/sca/1.0-RC1b/modules/binding-ejb/src/test/java/calculator/AddService.java new file mode 100644 index 0000000000..7cefba530a --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-ejb/src/test/java/calculator/AddService.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 calculator; + +/** + * @version $Rev$ $Date$ + */ +public interface AddService { + double add(double n1, double n2); +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-ejb/src/test/java/calculator/AddServiceHome.java b/tags/java/sca/1.0-RC1b/modules/binding-ejb/src/test/java/calculator/AddServiceHome.java new file mode 100644 index 0000000000..8b62f3c3d8 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-ejb/src/test/java/calculator/AddServiceHome.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 calculator; + +import java.rmi.RemoteException; + +import javax.ejb.CreateException; +import javax.ejb.EJBHome; + +public interface AddServiceHome extends EJBHome { + + public AddService create() throws CreateException, RemoteException; + +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-ejb/src/test/java/org/apache/geronimo/samples/bank/ejb/BankManagerFacade.java b/tags/java/sca/1.0-RC1b/modules/binding-ejb/src/test/java/org/apache/geronimo/samples/bank/ejb/BankManagerFacade.java new file mode 100644 index 0000000000..70e2461b0e --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-ejb/src/test/java/org/apache/geronimo/samples/bank/ejb/BankManagerFacade.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. + */ + +/* + * 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 ${version} + */ +public interface BankManagerFacade + extends javax.ejb.EJBObject +{ + + public void changeAccountBalance( java.lang.String accountNo,java.lang.Double balance ) + throws java.rmi.RemoteException; + + public java.lang.Double getAccountBalance( java.lang.String accountNo ) + throws java.rmi.RemoteException; + +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-ejb/src/test/java/org/apache/geronimo/samples/bank/ejb/BankManagerFacadeHome.java b/tags/java/sca/1.0-RC1b/modules/binding-ejb/src/test/java/org/apache/geronimo/samples/bank/ejb/BankManagerFacadeHome.java new file mode 100644 index 0000000000..56c80f60eb --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-ejb/src/test/java/org/apache/geronimo/samples/bank/ejb/BankManagerFacadeHome.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. + */ + +/* + * 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 ${version} + */ +public interface BankManagerFacadeHome + extends javax.ejb.EJBHome +{ + public static final String COMP_NAME="java:comp/env/ejb/BankManagerFacadeBean"; + public static final String JNDI_NAME="org.apache.geronimo.samples.bank.ejb.BankManagerFacadeBean"; + + public org.apache.geronimo.samples.bank.ejb.BankManagerFacade create() + throws javax.ejb.CreateException,java.rmi.RemoteException; + +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-ejb/src/test/java/org/apache/tuscany/sca/binding/ejb/tests/EJBReferenceTestCase.java b/tags/java/sca/1.0-RC1b/modules/binding-ejb/src/test/java/org/apache/tuscany/sca/binding/ejb/tests/EJBReferenceTestCase.java new file mode 100644 index 0000000000..a54c9bc41b --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-ejb/src/test/java/org/apache/tuscany/sca/binding/ejb/tests/EJBReferenceTestCase.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.ejb.tests; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.host.embedded.SCADomain; + +import account.Customer; + +/** + * Invokes the component which calls the reference using the EJB binding + */ +public class EJBReferenceTestCase extends TestCase { + private static final int MOCK_PORT = 8085; + private SCADomain scaDomain; + + @Override + protected 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 traffice for the MockServer, uncomment the next line + // new Thread(new SocketTracer(MOCK_PORT, OPENEJB_PORT)).start(); + + // Start the mock server to simulate the remote EJB + new Thread(new MockServer(MOCK_PORT)).start(); + + // Wait enough for the server to be started + Thread.sleep(500); + } + + @Override + protected void tearDown() throws Exception { + scaDomain.close(); + } + + 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); + assertEquals(1200.0, balance); + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-ejb/src/test/java/org/apache/tuscany/sca/binding/ejb/tests/MockServer.java b/tags/java/sca/1.0-RC1b/modules/binding-ejb/src/test/java/org/apache/tuscany/sca/binding/ejb/tests/MockServer.java new file mode 100644 index 0000000000..27d2a0be58 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-ejb/src/test/java/org/apache/tuscany/sca/binding/ejb/tests/MockServer.java @@ -0,0 +1,151 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.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, 58, 1, 27, 0, 54, 47, 104, 101, 108, 108, 111, 45, + 97, 100, 100, 115, 101, 114, 118, 105, 99, 101, 47, 65, 100, 100, 83, 101, 114, 118, 105, 99, 101, 66, 101, + 97, 110, 47, 99, 97, 108, 99, 117, 108, 97, 116, 111, 114, 46, 65, 100, 100, 83, 101, 114, 118, 105, 99, 101, + 112}, + + {79, 69, 74, 80, 47, 50, 46, 48, -84, -19, 0, 5, 119, 3, 1, 13, 1, 118, 114, 0, 25, 99, 97, 108, 99, 117, 108, + 97, 116, 111, 114, 46, 65, 100, 100, 83, 101, 114, 118, 105, 99, 101, 72, 111, 109, 101, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 120, 112, 118, 114, 0, 21, 99, 97, 108, 99, 117, 108, 97, 116, 111, 114, 46, 65, 100, 100, 83, + 101, 114, 118, 105, 99, 101, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 120, 112, 112, 112, 119, 38, 7, 0, 31, 104, + 101, 108, 108, 111, 45, 97, 100, 100, 115, 101, 114, 118, 105, 99, 101, 47, 65, 100, 100, 83, 101, 114, 118, + 105, 99, 101, 66, 101, 97, 110, -1, -1, 0, 0}, + + {79, 69, 74, 80, 47, 51, 46, 48, 0, -84, -19, 0, 5, 119, 1, 10, 116, 0, 31, 104, 101, 108, 108, 111, 45, 97, + 100, 100, 115, 101, 114, 118, 105, 99, 101, 47, 65, 100, 100, 83, 101, 114, 118, 105, 99, 101, 66, 101, 97, + 110, 119, 2, -1, -1, 112, 119, 1, 1, 112, 118, 114, 0, 25, 99, 97, 108, 99, 117, 108, 97, 116, 111, 114, 46, + 65, 100, 100, 83, 101, 114, 118, 105, 99, 101, 72, 111, 109, 101, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 120, 112, + 119, 9, 0, 6, 99, 114, 101, 97, 116, 101, 0}, + {79, 69, 74, 80, 47, 50, 46, 48, -84, -19, 0, 5, 119, 2, 1, 4, 112}, + + {79, 69, 74, 80, 47, 51, 46, 48, 0, -84, -19, 0, 5, 119, 1, 23, 116, 0, 31, 104, 101, 108, 108, 111, 45, 97, + 100, 100, 115, 101, 114, 118, 105, 99, 101, 47, 65, 100, 100, 83, 101, 114, 118, 105, 99, 101, 66, 101, 97, + 110, 119, 2, -1, -1, 112, 119, 1, 1, 112, 118, 114, 0, 21, 99, 97, 108, 99, 117, 108, 97, 116, 111, 114, 46, + 65, 100, 100, 83, 101, 114, 118, 105, 99, 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, 50, 46, 48, -84, -19, 0, 5, 119, 2, 1, 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/tags/java/sca/1.0-RC1b/modules/binding-ejb/src/test/java/org/apache/tuscany/sca/binding/ejb/tests/SocketTracer.java b/tags/java/sca/1.0-RC1b/modules/binding-ejb/src/test/java/org/apache/tuscany/sca/binding/ejb/tests/SocketTracer.java new file mode 100644 index 0000000000..275ae31f90 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-ejb/src/test/java/org/apache/tuscany/sca/binding/ejb/tests/SocketTracer.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.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 + */ +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/tags/java/sca/1.0-RC1b/modules/binding-ejb/src/test/resources/account/account.composite b/tags/java/sca/1.0-RC1b/modules/binding-ejb/src/test/resources/account/account.composite new file mode 100644 index 0000000000..14f77eed08 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-ejb/src/test/resources/account/account.composite @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/binding-feed/DISCLAIMER b/tags/java/sca/1.0-RC1b/modules/binding-feed/DISCLAIMER new file mode 100644 index 0000000000..d68a410903 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-feed/DISCLAIMER @@ -0,0 +1,8 @@ +Apache Tuscany is an effort undergoing incubation at The Apache Software +Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is +required of all newly accepted projects until a further review indicates that +the infrastructure, communications, and decision making process have stabilized +in a manner consistent with other successful ASF projects. While incubation +status is not necessarily a reflection of the completeness or stability of the +code, it does indicate that the project has yet to be fully endorsed by the ASF. + diff --git a/tags/java/sca/1.0-RC1b/modules/binding-feed/LICENSE b/tags/java/sca/1.0-RC1b/modules/binding-feed/LICENSE new file mode 100644 index 0000000000..6e529a25c4 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-feed/NOTICE b/tags/java/sca/1.0-RC1b/modules/binding-feed/NOTICE new file mode 100644 index 0000000000..eb1926d971 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-feed/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2007 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/tags/java/sca/1.0-RC1b/modules/binding-feed/pom.xml b/tags/java/sca/1.0-RC1b/modules/binding-feed/pom.xml new file mode 100644 index 0000000000..51bb5197e9 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-feed/pom.xml @@ -0,0 +1,105 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.0-incubating + ../pom.xml + + + tuscany-binding-feed + Apache Tuscany SCA Atom+RSS Feed Binding Extension + + + + org.apache.tuscany.sca + tuscany-assembly + 1.0-incubating + + + + org.apache.tuscany.sca + tuscany-interface-java + 1.0-incubating + + + + org.apache.tuscany.sca + tuscany-core-spi + 1.0-incubating + + + + org.apache.tuscany.sca + tuscany-host-http + 1.0-incubating + + + + commons-httpclient + commons-httpclient + 3.0.1 + + + + rome + rome + 0.9 + + + + javax.servlet + servlet-api + 2.4 + provided + + + + org.apache.tuscany.sca + tuscany-host-tomcat + 1.0-incubating + test + + + + org.apache.tuscany.sca + tuscany-implementation-java-runtime + 1.0-incubating + test + + + + org.apache.tuscany.sca + tuscany-host-embedded + 1.0-incubating + test + + + + junit + junit + 4.2 + test + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/AtomBinding.java b/tags/java/sca/1.0-RC1b/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/AtomBinding.java new file mode 100644 index 0000000000..85ee25bf42 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/AtomBinding.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.feed; + +import org.apache.tuscany.sca.assembly.Binding; + +/** + * Atom binding model. + */ +public interface AtomBinding extends Binding { +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/AtomBindingFactory.java b/tags/java/sca/1.0-RC1b/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/AtomBindingFactory.java new file mode 100644 index 0000000000..050ba9b73c --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/RSSBinding.java b/tags/java/sca/1.0-RC1b/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/RSSBinding.java new file mode 100644 index 0000000000..a71205ea77 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/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.feed; + +import org.apache.tuscany.sca.assembly.Binding; + +/** + * RSS Feed binding model. + */ +public interface RSSBinding extends Binding { +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/RSSBindingFactory.java b/tags/java/sca/1.0-RC1b/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/RSSBindingFactory.java new file mode 100644 index 0000000000..c95c8ac012 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/collection/Collection.java b/tags/java/sca/1.0-RC1b/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/collection/Collection.java new file mode 100644 index 0000000000..4cd48fd938 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/collection/Collection.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.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. + * + * @param uri the uri of the feed + * @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 + */ + Entry put(String id, Entry entry) throws NotFoundException; + + /** + * Delete an entry. + * + * @param id + */ + void delete(String id) throws NotFoundException; + +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/collection/MediaCollection.java b/tags/java/sca/1.0-RC1b/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/collection/MediaCollection.java new file mode 100644 index 0000000000..09942bcc23 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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 + */ + Entry putMedia(String id, String contentType, InputStream media) throws NotFoundException; + +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/collection/NotFoundException.java b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/impl/AtomBindingFactoryImpl.java b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/impl/AtomBindingImpl.java b/tags/java/sca/1.0-RC1b/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/impl/AtomBindingImpl.java new file mode 100644 index 0000000000..61ed6ff96d --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/impl/AtomBindingImpl.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.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. + */ +class AtomBindingImpl implements AtomBinding, PolicySetAttachPoint { + + private String name; + private String uri; + private List requiredIntents = new ArrayList(); + private List policySets = new ArrayList(); + private IntentAttachPointType intentAttachPointType; + + 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; + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/impl/RSSBindingFactoryImpl.java b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/impl/RSSBindingImpl.java b/tags/java/sca/1.0-RC1b/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/impl/RSSBindingImpl.java new file mode 100644 index 0000000000..3e9dc2d66b --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/impl/RSSBindingImpl.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.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. + */ +class RSSBindingImpl implements RSSBinding, PolicySetAttachPoint { + + private String name; + private String uri; + private List requiredIntents = new ArrayList(); + private List policySets = new ArrayList(); + private IntentAttachPointType intentAttachPointType; + + 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; + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/AtomBindingInvoker.java b/tags/java/sca/1.0-RC1b/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/AtomBindingInvoker.java new file mode 100644 index 0000000000..c684970136 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/AtomBindingInvoker.java @@ -0,0 +1,350 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, 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.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. + */ +class AtomBindingInvoker implements Invoker { + + Operation operation; + String uri; + HttpClient httpClient; + String authorizationHeader; + + 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()); + } + + /** + * Get operation invoker + * + * @version $Rev$ $Date$ + */ + 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 entry = + AtomEntryUtil.readEntry("atom_1.0", new InputStreamReader(getMethod.getResponseBodyAsStream())); + msg.setBody(entry); + + } 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 + * + * @version $Rev$ $Date$ + */ + 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 entry = (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(); + AtomEntryUtil.writeEntry(entry, "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 = + AtomEntryUtil + .readEntry("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 + * + * @version $Rev$ $Date$ + */ + 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 entry = (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(); + AtomEntryUtil.writeEntry(entry, "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 = + AtomEntryUtil.readEntry("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 + * + * @version $Rev$ $Date$ + */ + 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; + } + } + + /** + * GetCollection operation invoker + * + * @version $Rev$ $Date$ + */ + public static class GetCollectionInvoker extends AtomBindingInvoker { + + public GetCollectionInvoker(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 + * + * @version $Rev$ $Date$ + */ + 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 + * + * @version $Rev$ $Date$ + */ + 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/tags/java/sca/1.0-RC1b/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/AtomBindingProviderFactory.java b/tags/java/sca/1.0-RC1b/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/AtomBindingProviderFactory.java new file mode 100644 index 0000000000..0f2356b5e0 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/AtomBindingProviderFactory.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.AtomBinding; +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; + +/** + * Implementation of the Atom binding model. + */ +public class AtomBindingProviderFactory implements BindingProviderFactory { + + private MessageFactory messageFactory; + 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); + } + + 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); + } + + public Class getModelType() { + return AtomBinding.class; + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/AtomEntryUtil.java b/tags/java/sca/1.0-RC1b/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/AtomEntryUtil.java new file mode 100644 index 0000000000..f2566f81a5 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/AtomEntryUtil.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.feed.provider; + +import java.io.IOException; +import java.io.Reader; +import java.io.Writer; +import java.util.ArrayList; +import java.util.List; + +import javax.servlet.ServletException; + +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.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 AtomEntryUtil { + + /** + * Read an Atom entry + * + * @param request + * @return + * @throws IOException + * @throws JDOMException + * @throws FeedException + * @throws IllegalArgumentException + */ + static Entry readEntry(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 entry = (Entry)feed.getEntries().get(0); + return entry; + } + + /** + * Write an Atom entry. + * + * @param entry + * @param response + * @throws FeedException + * @throws IllegalArgumentException + * @throws IOException + * @throws ServletException + */ + static void writeEntry(Entry entry, String feedType, Writer writer) throws IllegalArgumentException, FeedException, + IOException { + Feed feed = new Feed(); + feed.setFeedType(feedType); + List entries = new ArrayList(); + entries.add(entry); + feed.setEntries(entries); + + 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/tags/java/sca/1.0-RC1b/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/AtomReferenceBindingProvider.java b/tags/java/sca/1.0-RC1b/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/AtomReferenceBindingProvider.java new file mode 100644 index 0000000000..9b7537d04c --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/AtomReferenceBindingProvider.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.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. + */ +class AtomReferenceBindingProvider implements ReferenceBindingProvider { + + private RuntimeComponentReference reference; + private AtomBinding binding; + private String authorizationHeader; + private HttpClient httpClient; + + 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")) { + return new AtomBindingInvoker.GetCollectionInvoker(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() { + httpClient = null; + } + + public boolean supportsOneWayInvocation() { + return false; + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/AtomServiceBindingProvider.java b/tags/java/sca/1.0-RC1b/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/AtomServiceBindingProvider.java new file mode 100644 index 0000000000..ff3d3a8c55 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/AtomServiceBindingProvider.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.binding.feed.provider; + +import org.apache.tuscany.sca.binding.feed.AtomBinding; +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. + */ +class AtomServiceBindingProvider implements ServiceBindingProvider { + + private RuntimeComponentService service; + private AtomBinding binding; + private ServletHost servletHost; + private MessageFactory messageFactory; + private String uri; + + AtomServiceBindingProvider(RuntimeComponent component, + RuntimeComponentService service, + AtomBinding binding, + ServletHost servletHost, + MessageFactory messageFactory) { + this.service = service; + this.binding = binding; + this.servletHost = servletHost; + this.messageFactory = messageFactory; + uri = binding.getURI(); + } + + 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, "atom_1.0"); + + String mapping = uri; + if (!mapping.endsWith("/")) { + mapping += "/"; + } + if (!mapping.endsWith("*")) { + mapping += "*"; + } + servletHost.addServletMapping(mapping, servlet); + } + + public void stop() { + servletHost.removeServletMapping(uri); + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/FeedBindingListenerServlet.java b/tags/java/sca/1.0-RC1b/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/FeedBindingListenerServlet.java new file mode 100644 index 0000000000..1f27becc2a --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/FeedBindingListenerServlet.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.feed.provider; + +import java.io.IOException; +import java.io.OutputStream; +import java.io.PrintWriter; +import java.util.StringTokenizer; +import java.util.logging.Logger; + +import javax.servlet.ServletConfig; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.commons.codec.binary.Base64; +import org.apache.tuscany.sca.binding.feed.collection.NotFoundException; +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.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. + */ +class FeedBindingListenerServlet extends HttpServlet { + private static final Logger logger = Logger.getLogger(FeedBindingListenerServlet.class.getName()); + private static final long serialVersionUID = 1L; + + private final static Namespace APP_NS = Namespace.getNamespace("app", "http://purl.org/atom/app#"); + private final static Namespace ATOM_NS = Namespace.getNamespace("atom", "http://www.w3.org/2005/Atom"); + + private RuntimeWire wire; + private Invoker getFeedInvoker; + private Invoker getInvoker; + private Invoker postInvoker; + private Invoker postMediaInvoker; + private Invoker putInvoker; + private Invoker putMediaInvoker; + private Invoker deleteInvoker; + private MessageFactory messageFactory; + private String feedType; + + /** + * Constructs a new binding listener. + * + * @param wire + * @param messageFactory + * @param feedType + */ + FeedBindingListenerServlet(RuntimeWire wire, MessageFactory messageFactory, String feedType) { + this.wire = wire; + this.messageFactory = messageFactory; + this.feedType = feedType; + + // Get the invokers for the supported operations + for (InvocationChain invocationChain : this.wire.getInvocationChains()) { + String operationName = invocationChain.getSourceOperation().getName(); + if (operationName.equals("getFeed")) { + getFeedInvoker = invocationChain.getHeadInvoker(); + } else if (operationName.equals("get")) { + getInvoker = invocationChain.getHeadInvoker(); + } 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(); + } + } + } + + @Override + public void init(ServletConfig config) { + } + + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + + // No authentication required for a get request + + // Get the request path + String path = request.getPathInfo(); + + // 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(); + outputter.setFormat(Format.getPrettyFormat()); + outputter.output(document, response.getWriter()); + + } else if (path == null || path.length() == 0 || path.equals("/")) { + + // Return a feed containing the entries in the collection + + // Get the Feed from the service implementation + Message requestMessage = messageFactory.createMessage(); + Message responseMessage = getFeedInvoker.invoke(requestMessage); + if (responseMessage.isFault()) { + throw new ServletException((Throwable)responseMessage.getBody()); + } + Feed feed = (Feed)responseMessage.getBody(); + if (feed != null) { + + // Write the Atom feed + response.setContentType("application/atom+xml; charset=utf-8"); + feed.setFeedType(requestFeedType); + WireFeedOutput feedOutput = new WireFeedOutput(); + try { + OutputStream output = response.getOutputStream(); + feedOutput.output(feed, new PrintWriter(output)); + } 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 + + // Get the entry from 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()); + } + Entry entry = responseMessage.getBody(); + + // Write the Atom entry + if (entry != null) { + response.setContentType("application/atom+xml; charset=utf-8"); + try { + AtomEntryUtil.writeEntry(entry, feedType, response.getWriter()); + } 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("/")) { + + // Get the Feed from the service + Message requestMessage = messageFactory.createMessage(); + Message responseMessage = getFeedInvoker.invoke(requestMessage); + if (responseMessage.isFault()) { + throw new ServletException((Throwable)responseMessage.getBody()); + } + Feed feed = (Feed)responseMessage.getBody(); + if (feed != null) { + + // Convert to an RSS feed + response.setContentType("application/rss+xml; charset=utf-8"); + feed.setFeedType("atom_1.0"); + SyndFeed syndFeed = new SyndFeedImpl(feed); + syndFeed.setFeedType(requestFeedType); + SyndFeedOutput syndOutput = new SyndFeedOutput(); + try { + OutputStream output = response.getOutputStream(); + syndOutput.output(syndFeed, new PrintWriter(output)); + } catch (FeedException e) { + throw new ServletException(e); + } + } else { + response.sendError(HttpServletResponse.SC_NOT_FOUND); + } + } else { + response.sendError(HttpServletResponse.SC_NOT_FOUND); + } + } + } + + @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 = request.getPathInfo(); + + if (path == null || path.length() == 0 || path.equals("/")) { + Entry createdEntry = null; + + // Create a new Atom entry + String contentType = request.getContentType(); + if (contentType.startsWith("application/atom+xml")) { + + // Read the entry from the request + Entry entry; + try { + entry = AtomEntryUtil.readEntry(feedType, request.getReader()); + } catch (JDOMException e) { + throw new ServletException(e); + } catch (FeedException e) { + throw new ServletException(e); + } + + // Let the component implementation create it + Message requestMessage = messageFactory.createMessage(); + requestMessage.setBody(new Object[] {entry}); + Message responseMessage = postInvoker.invoke(requestMessage); + if (responseMessage.isFault()) { + throw new ServletException((Throwable)responseMessage.getBody()); + } + createdEntry = responseMessage.getBody(); + + } 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()); + } + createdEntry = responseMessage.getBody(); + } else { + response.sendError(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE); + } + + // A new entry was created successfully + if (createdEntry != null) { + + // Set location of the created entry in the Location header + for (Object l : createdEntry.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 { + AtomEntryUtil.writeEntry(createdEntry, feedType, response.getWriter()); + } catch (FeedException e) { + throw new ServletException(e); + } + + } else { + response.sendError(HttpServletResponse.SC_NOT_FOUND); + } + + } else { + response.sendError(HttpServletResponse.SC_NOT_FOUND); + } + } + + @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.getPathInfo(); + + if (path != null && path.startsWith("/")) { + String id = path.substring(1); + Entry updatedEntry = null; + + // Update an Atom entry + String contentType = request.getContentType(); + if (contentType.startsWith("application/atom+xml")) { + + // Read the entry from the request + Entry entry; + try { + entry = AtomEntryUtil.readEntry(feedType, request.getReader()); + } catch (JDOMException e) { + throw new ServletException(e); + } catch (FeedException e) { + throw new ServletException(e); + } + + // Let the component implementation create it + Message requestMessage = messageFactory.createMessage(); + requestMessage.setBody(new Object[] {id, entry}); + Message responseMessage = putInvoker.invoke(requestMessage); + if (responseMessage.isFault()) { + Object body = responseMessage.getBody(); + if (body instanceof NotFoundException) { + response.sendError(HttpServletResponse.SC_NOT_FOUND); + } else { + throw new ServletException((Throwable)responseMessage.getBody()); + } + } else { + updatedEntry = 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 (body instanceof NotFoundException) { + if (body instanceof NotFoundException) { + response.sendError(HttpServletResponse.SC_NOT_FOUND); + } else { + throw new ServletException((Throwable)responseMessage.getBody()); + } + } else { + updatedEntry = (Entry) body; + } + + } else { + response.sendError(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE); + } + + // The entry was successfully updated + if (updatedEntry != null) { + + // Write the updated Atom entry + response.setContentType("application/atom+xml; charset=utf-8"); + try { + AtomEntryUtil.writeEntry(updatedEntry, feedType, response.getWriter()); + } catch (FeedException e) { + throw new ServletException(e); + } + + } else { + response.sendError(HttpServletResponse.SC_NOT_FOUND); + } + + } 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 = request.getPathInfo(); + + if (path.startsWith("/")) { + String id = path.substring(1); + + // 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 instanceof NotFoundException) { + response.sendError(HttpServletResponse.SC_NOT_FOUND); + } else { + throw new ServletException((Throwable)responseMessage.getBody()); + } + } + } else { + response.sendError(HttpServletResponse.SC_NOT_FOUND); + } + } + + /** + * 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/tags/java/sca/1.0-RC1b/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/RSSBindingInvoker.java b/tags/java/sca/1.0-RC1b/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/RSSBindingInvoker.java new file mode 100644 index 0000000000..4b3dbc7de3 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/RSSBindingInvoker.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.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 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. + */ +class RSSBindingInvoker implements Invoker { + private final static 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"); + } + 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; + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/RSSBindingProviderFactory.java b/tags/java/sca/1.0-RC1b/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/RSSBindingProviderFactory.java new file mode 100644 index 0000000000..98c53d6bed --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/RSSBindingProviderFactory.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.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; + +/** + * Implementation of the RSS binding provider factory. + */ +public class RSSBindingProviderFactory implements BindingProviderFactory { + + MessageFactory messageFactory; + 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); + } + + 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); + } + + public Class getModelType() { + return RSSBinding.class; + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/RSSReferenceBindingProvider.java b/tags/java/sca/1.0-RC1b/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/RSSReferenceBindingProvider.java new file mode 100644 index 0000000000..6ef305f2fb --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/RSSReferenceBindingProvider.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.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. + */ +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/tags/java/sca/1.0-RC1b/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/RSSServiceBindingProvider.java b/tags/java/sca/1.0-RC1b/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/RSSServiceBindingProvider.java new file mode 100644 index 0000000000..c48426da0b --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/RSSServiceBindingProvider.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.feed.provider; + +import org.apache.tuscany.sca.binding.feed.RSSBinding; +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. + */ +class RSSServiceBindingProvider implements ServiceBindingProvider { + + private RuntimeComponentService service; + private RSSBinding binding; + private ServletHost servletHost; + private MessageFactory messageFactory; + private String uri; + + RSSServiceBindingProvider(RuntimeComponent component, + RuntimeComponentService service, + RSSBinding binding, + ServletHost servletHost, + MessageFactory messageFactory) { + this.service = service; + this.binding = binding; + this.servletHost = servletHost; + this.messageFactory = messageFactory; + uri = binding.getURI(); + } + + 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, "rss_2.0"); + + servletHost.addServletMapping(uri, servlet); + } + + public void stop() { + servletHost.removeServletMapping(uri); + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-feed/src/main/resources/META-INF/services/org.apache.tuscany.sca.binding.feed.AtomBindingFactory b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-feed/src/main/resources/META-INF/services/org.apache.tuscany.sca.binding.feed.RSSBindingFactory b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-feed/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-feed/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-feed/src/test/java/org/apache/tuscany/sca/binding/feed/Consumer.java b/tags/java/sca/1.0-RC1b/modules/binding-feed/src/test/java/org/apache/tuscany/sca/binding/feed/Consumer.java new file mode 100644 index 0000000000..4a33637121 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-feed/src/test/java/org/apache/tuscany/sca/binding/feed/CustomerClient.java b/tags/java/sca/1.0-RC1b/modules/binding-feed/src/test/java/org/apache/tuscany/sca/binding/feed/CustomerClient.java new file mode 100644 index 0000000000..b7416011ba --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-feed/src/test/java/org/apache/tuscany/sca/binding/feed/CustomerClientImpl.java b/tags/java/sca/1.0-RC1b/modules/binding-feed/src/test/java/org/apache/tuscany/sca/binding/feed/CustomerClientImpl.java new file mode 100644 index 0000000000..5b08b036c1 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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()); + entry = 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/tags/java/sca/1.0-RC1b/modules/binding-feed/src/test/java/org/apache/tuscany/sca/binding/feed/CustomerCollectionImpl.java b/tags/java/sca/1.0-RC1b/modules/binding-feed/src/test/java/org/apache/tuscany/sca/binding/feed/CustomerCollectionImpl.java new file mode 100644 index 0000000000..255f90685b --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-feed/src/test/java/org/apache/tuscany/sca/binding/feed/CustomerCollectionImpl.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.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 Entry put(String id, Entry entry) { + System.out.println(">>> ResourceCollectionImpl.put id=" + id + " entry=" + entry.getTitle()); + + entry.setUpdated(new Date()); + entries.put(id, entry); + return 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/tags/java/sca/1.0-RC1b/modules/binding-feed/src/test/java/org/apache/tuscany/sca/binding/feed/Provider.java b/tags/java/sca/1.0-RC1b/modules/binding-feed/src/test/java/org/apache/tuscany/sca/binding/feed/Provider.java new file mode 100644 index 0000000000..a9ddc1a2c8 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-feed/src/test/resources/org/apache/tuscany/sca/binding/feed/Consumer.composite b/tags/java/sca/1.0-RC1b/modules/binding-feed/src/test/resources/org/apache/tuscany/sca/binding/feed/Consumer.composite new file mode 100644 index 0000000000..1987c042e6 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-feed/src/test/resources/org/apache/tuscany/sca/binding/feed/Consumer.composite @@ -0,0 +1,32 @@ + + + + + + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/binding-feed/src/test/resources/org/apache/tuscany/sca/binding/feed/Provider.composite b/tags/java/sca/1.0-RC1b/modules/binding-feed/src/test/resources/org/apache/tuscany/sca/binding/feed/Provider.composite new file mode 100644 index 0000000000..9268fbe211 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-feed/src/test/resources/org/apache/tuscany/sca/binding/feed/Provider.composite @@ -0,0 +1,33 @@ + + + + + + + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/binding-http/DISCLAIMER b/tags/java/sca/1.0-RC1b/modules/binding-http/DISCLAIMER new file mode 100644 index 0000000000..d68a410903 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-http/DISCLAIMER @@ -0,0 +1,8 @@ +Apache Tuscany is an effort undergoing incubation at The Apache Software +Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is +required of all newly accepted projects until a further review indicates that +the infrastructure, communications, and decision making process have stabilized +in a manner consistent with other successful ASF projects. While incubation +status is not necessarily a reflection of the completeness or stability of the +code, it does indicate that the project has yet to be fully endorsed by the ASF. + diff --git a/tags/java/sca/1.0-RC1b/modules/binding-http/LICENSE b/tags/java/sca/1.0-RC1b/modules/binding-http/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-http/NOTICE b/tags/java/sca/1.0-RC1b/modules/binding-http/NOTICE new file mode 100644 index 0000000000..94481d6cfa --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-http/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2007 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/tags/java/sca/1.0-RC1b/modules/binding-http/pom.xml b/tags/java/sca/1.0-RC1b/modules/binding-http/pom.xml new file mode 100644 index 0000000000..7a16bbd7b8 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-http/pom.xml @@ -0,0 +1,94 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.0-incubating + ../pom.xml + + + tuscany-binding-http + Apache Tuscany SCA HTTP Binding Extension + + + + org.apache.tuscany.sca + tuscany-assembly + 1.0-incubating + + + + org.apache.tuscany.sca + tuscany-interface-java-xml + 1.0-incubating + + + + org.apache.tuscany.sca + tuscany-core-spi + 1.0-incubating + + + + org.apache.tuscany.sca + tuscany-host-http + 1.0-incubating + + + + javax.servlet + servlet-api + 2.5 + provided + + + + org.apache.tuscany.sca + tuscany-host-embedded + 1.0-incubating + test + + + + org.apache.tuscany.sca + tuscany-host-jetty + 1.0-incubating + test + + + + org.apache.tuscany.sca + tuscany-implementation-resource + 1.0-incubating + test + + + + junit + junit + 4.2 + test + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/binding-http/src/main/java/org/apache/tuscany/sca/binding/http/HTTPResource.java b/tags/java/sca/1.0-RC1b/modules/binding-http/src/main/java/org/apache/tuscany/sca/binding/http/HTTPResource.java new file mode 100644 index 0000000000..7ed660a54f --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-http/src/main/java/org/apache/tuscany/sca/binding/http/HTTPResource.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.http; + +import java.net.URL; + +/** + * The service interface of resource implementations. + * + * @version $Rev$ $Date$ + */ +public interface HTTPResource { + + /** + * Returns the resource location URL. + * + * @return + */ + public URL getLocationURL(); + +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-http/src/main/java/org/apache/tuscany/sca/binding/http/HTTPResourceBinding.java b/tags/java/sca/1.0-RC1b/modules/binding-http/src/main/java/org/apache/tuscany/sca/binding/http/HTTPResourceBinding.java new file mode 100644 index 0000000000..be9483b3c0 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-http/src/main/java/org/apache/tuscany/sca/binding/http/HTTPResourceBinding.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.http; + +import org.apache.tuscany.sca.assembly.Binding; + + +/** + * HTTP resource binding model. + */ +public interface HTTPResourceBinding extends Binding { +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-http/src/main/java/org/apache/tuscany/sca/binding/http/HTTPResourceBindingFactory.java b/tags/java/sca/1.0-RC1b/modules/binding-http/src/main/java/org/apache/tuscany/sca/binding/http/HTTPResourceBindingFactory.java new file mode 100644 index 0000000000..cf59e07782 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-http/src/main/java/org/apache/tuscany/sca/binding/http/HTTPResourceBindingFactory.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 resource binding model. + * + * @version $Rev$ $Date$ + */ +public interface HTTPResourceBindingFactory { + + /** + * Creates a new HTTP resource binding. + * @return a new HTTP resource binding + */ + HTTPResourceBinding createHTTPResourceBinding(); + +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-http/src/main/java/org/apache/tuscany/sca/binding/http/impl/HTTPResourceBindingFactoryImpl.java b/tags/java/sca/1.0-RC1b/modules/binding-http/src/main/java/org/apache/tuscany/sca/binding/http/impl/HTTPResourceBindingFactoryImpl.java new file mode 100644 index 0000000000..9620c2bc04 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-http/src/main/java/org/apache/tuscany/sca/binding/http/impl/HTTPResourceBindingFactoryImpl.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.HTTPResourceBinding; +import org.apache.tuscany.sca.binding.http.HTTPResourceBindingFactory; + +/** + * Factory for the HTTP resource binding model. + * + * @version $Rev$ $Date$ + */ +public class HTTPResourceBindingFactoryImpl implements HTTPResourceBindingFactory { + + public HTTPResourceBinding createHTTPResourceBinding() { + return new HTTPResourceBindingImpl(); + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-http/src/main/java/org/apache/tuscany/sca/binding/http/impl/HTTPResourceBindingImpl.java b/tags/java/sca/1.0-RC1b/modules/binding-http/src/main/java/org/apache/tuscany/sca/binding/http/impl/HTTPResourceBindingImpl.java new file mode 100644 index 0000000000..aab392b2ed --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-http/src/main/java/org/apache/tuscany/sca/binding/http/impl/HTTPResourceBindingImpl.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.impl; + +import java.util.Collections; +import java.util.List; + +import org.apache.tuscany.sca.binding.http.HTTPResourceBinding; + + +/** + * Implementation of the HTTP resource binding model. + */ +class HTTPResourceBindingImpl implements HTTPResourceBinding { + + private String name; + private String uri; + + 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 + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-http/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPResourceBindingProviderFactory.java b/tags/java/sca/1.0-RC1b/modules/binding-http/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPResourceBindingProviderFactory.java new file mode 100644 index 0000000000..2cb7b1d530 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-http/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPResourceBindingProviderFactory.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.http.provider; + +import org.apache.tuscany.sca.binding.http.HTTPResourceBinding; +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; + + +/** + * Implementation of the Echo binding model. + */ +public class HTTPResourceBindingProviderFactory implements BindingProviderFactory { + + private MessageFactory messageFactory; + private ServletHost servletHost; + + public HTTPResourceBindingProviderFactory(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, HTTPResourceBinding binding) { + return null; + } + + public ServiceBindingProvider createServiceBindingProvider(RuntimeComponent component, RuntimeComponentService service, HTTPResourceBinding binding) { + return new HTTPResourceServiceBindingProvider(component, service, binding, messageFactory, servletHost); + } + + public Class getModelType() { + return HTTPResourceBinding.class; + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-http/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPResourceServiceBindingProvider.java b/tags/java/sca/1.0-RC1b/modules/binding-http/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPResourceServiceBindingProvider.java new file mode 100644 index 0000000000..640e68c0aa --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-http/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPResourceServiceBindingProvider.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.http.provider; + +import java.net.URL; + +import org.apache.tuscany.sca.binding.http.HTTPResourceBinding; +import org.apache.tuscany.sca.host.http.DefaultResourceServlet; +import org.apache.tuscany.sca.host.http.ServletHost; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +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.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 Echo binding provider. + */ +public class HTTPResourceServiceBindingProvider implements ServiceBindingProvider { + + private RuntimeComponentService service; + private HTTPResourceBinding binding; + private MessageFactory messageFactory; + private ServletHost servletHost; + private String uri; + + public HTTPResourceServiceBindingProvider(RuntimeComponent component, + RuntimeComponentService service, + HTTPResourceBinding binding, + MessageFactory messageFactory, + ServletHost servletHost) { + this.service = service; + this.binding = binding; + this.messageFactory = messageFactory; + this.servletHost = servletHost; + + uri = binding.getURI(); + if (!uri.endsWith("/")) { + uri += "/"; + } + if (!uri.endsWith("*")) { + uri += "*"; + } + } + + public InterfaceContract getBindingInterfaceContract() { + return service.getInterfaceContract(); + } + + public boolean supportsOneWayInvocation() { + return false; + } + + public void start() { + + // Get the target component implementation, for now we are assuming + // that it's an implementation.resource + RuntimeComponentService componentService = (RuntimeComponentService) service; + RuntimeWire wire = componentService.getRuntimeWire(binding); + + // Get the getLocationURL invoker + Invoker getLocationInvoker = null; + for (InvocationChain invocationChain : wire.getInvocationChains()) { + String operationName = invocationChain.getSourceOperation().getName(); + if (operationName.equals("getLocationURL")) { + getLocationInvoker = invocationChain.getHeadInvoker(); + } + } + if (getLocationInvoker == null) { + throw new IllegalStateException("No getLocationURL operation found on target component"); + } + + // Get the location URL + Message message = messageFactory.createMessage(); + message = getLocationInvoker.invoke(message); + URL locationURL = message.getBody(); + + // Register the default resource servlet with the servlet host + DefaultResourceServlet resourceServlet = new DefaultResourceServlet(locationURL.toString()); + servletHost.addServletMapping(uri, resourceServlet); + + } + + public void stop() { + + // Unregister from the hosting server + servletHost.removeServletMapping(uri); + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-http/src/main/resources/META-INF/services/org.apache.tuscany.sca.binding.http.HTTPResourceBindingFactory b/tags/java/sca/1.0-RC1b/modules/binding-http/src/main/resources/META-INF/services/org.apache.tuscany.sca.binding.http.HTTPResourceBindingFactory new file mode 100644 index 0000000000..ae416c25f0 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-http/src/main/resources/META-INF/services/org.apache.tuscany.sca.binding.http.HTTPResourceBindingFactory @@ -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.HTTPResourceBindingFactoryImpl diff --git a/tags/java/sca/1.0-RC1b/modules/binding-http/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor b/tags/java/sca/1.0-RC1b/modules/binding-http/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor new file mode 100644 index 0000000000..bdccbd7314 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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.assembly.xml.DefaultBeanModelProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.0#binding.http,model=org.apache.tuscany.sca.binding.http.HTTPResourceBinding,factory=org.apache.tuscany.sca.binding.http.HTTPResourceBindingFactory diff --git a/tags/java/sca/1.0-RC1b/modules/binding-http/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory b/tags/java/sca/1.0-RC1b/modules/binding-http/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory new file mode 100644 index 0000000000..1351707239 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-http/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.HTTPResourceBindingProviderFactory;model=org.apache.tuscany.sca.binding.http.HTTPResourceBinding diff --git a/tags/java/sca/1.0-RC1b/modules/binding-http/src/test/java/org/apache/tuscany/sca/binding/http/HTTPResourceBindingTestCase.java b/tags/java/sca/1.0-RC1b/modules/binding-http/src/test/java/org/apache/tuscany/sca/binding/http/HTTPResourceBindingTestCase.java new file mode 100644 index 0000000000..72eb537a8b --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-http/src/test/java/org/apache/tuscany/sca/binding/http/HTTPResourceBindingTestCase.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.http; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.net.Socket; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.host.embedded.SCADomain; + +/** + * @version $Rev$ $Date$ + */ +public class HTTPResourceBindingTestCase extends TestCase { + +// private static final String REQUEST1_HEADER = +// "GET /ResourceServiceComponent/test.html 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 int HTTP_PORT = 8085; + + private SCADomain scaDomain; + + @Override + protected void setUp() throws Exception { + scaDomain = SCADomain.newInstance("resource.composite"); + } + + @Override + protected void tearDown() throws Exception { + scaDomain.close(); + } + + // This works with port 8080 but we can't use that port on the build + // machine as it's already in use +// public void testResourceImplementation() 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("

hello") != -1); +// } + + public void testResourceImplementationWithBindingURI() 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); + } + + 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/tags/java/sca/1.0-RC1b/modules/binding-http/src/test/resources/content/test.html b/tags/java/sca/1.0-RC1b/modules/binding-http/src/test/resources/content/test.html new file mode 100644 index 0000000000..f4b79d7f01 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-http/src/test/resources/content/test.html @@ -0,0 +1,21 @@ + + +

hello + \ No newline at end of file diff --git a/tags/java/sca/1.0-RC1b/modules/binding-http/src/test/resources/resource.composite b/tags/java/sca/1.0-RC1b/modules/binding-http/src/test/resources/resource.composite new file mode 100644 index 0000000000..1f672e2c66 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-http/src/test/resources/resource.composite @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/binding-jsonrpc/DISCLAIMER b/tags/java/sca/1.0-RC1b/modules/binding-jsonrpc/DISCLAIMER new file mode 100644 index 0000000000..d68a410903 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-jsonrpc/DISCLAIMER @@ -0,0 +1,8 @@ +Apache Tuscany is an effort undergoing incubation at The Apache Software +Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is +required of all newly accepted projects until a further review indicates that +the infrastructure, communications, and decision making process have stabilized +in a manner consistent with other successful ASF projects. While incubation +status is not necessarily a reflection of the completeness or stability of the +code, it does indicate that the project has yet to be fully endorsed by the ASF. + diff --git a/tags/java/sca/1.0-RC1b/modules/binding-jsonrpc/LICENSE b/tags/java/sca/1.0-RC1b/modules/binding-jsonrpc/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-jsonrpc/NOTICE b/tags/java/sca/1.0-RC1b/modules/binding-jsonrpc/NOTICE new file mode 100644 index 0000000000..94481d6cfa --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-jsonrpc/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2007 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/tags/java/sca/1.0-RC1b/modules/binding-jsonrpc/pom.xml b/tags/java/sca/1.0-RC1b/modules/binding-jsonrpc/pom.xml new file mode 100644 index 0000000000..052de09470 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-jsonrpc/pom.xml @@ -0,0 +1,103 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.0-incubating + ../pom.xml + + + tuscany-binding-jsonrpc + Apache Tuscany SCA JSON-RPC Binding Extension + + + + com.metaparadigm + json-rpc + 1.0 + compile + + + + net.sf.json-lib + json-lib + 0.8 + test + + + + + org.apache.tuscany.sca + tuscany-extension-helper + 1.0-incubating + + + + org.apache.tuscany.sca + tuscany-implementation-java-runtime + 1.0-incubating + runtime + + + + org.apache.tuscany.sca + tuscany-interface-java + 1.0-incubating + + + + org.apache.tuscany.sca + tuscany-host-http + 1.0-incubating + + + + javax.servlet + servlet-api + 2.4 + provided + + + + org.apache.tuscany.sca + tuscany-host-jetty + 1.0-incubating + test + + + + junit + junit + 4.2 + test + + + + httpunit + httpunit + 1.6.1 + test + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCBinding.java b/tags/java/sca/1.0-RC1b/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCBinding.java new file mode 100644 index 0000000000..44c799f286 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCBinding.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.jsonrpc; + + +/** + * A model for the JSONRPC binding. + */ +public class JSONRPCBinding { + + // empty as right now the json-rpc binding has no attributes + +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCBindingActivator.java b/tags/java/sca/1.0-RC1b/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCBindingActivator.java new file mode 100644 index 0000000000..84f09c8561 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCBindingActivator.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.jsonrpc; + +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; +import org.osoa.sca.ServiceRuntimeException; + +public class JSONRPCBindingActivator implements BindingActivator { + + protected ServletHost servletHost; + + public JSONRPCBindingActivator(ServletHost servletHost) { + this.servletHost = servletHost; + } + + public Class getBindingClass() { + return JSONRPCBinding.class; + } + + public InvokerFactory createInvokerFactory(RuntimeComponent rc, RuntimeComponentReference rcr, Binding b, JSONRPCBinding binding) { + throw new ServiceRuntimeException("SCA reference support not yet implemented"); + } + + public ComponentLifecycle createService(RuntimeComponent rc, RuntimeComponentService rcs, Binding b, JSONRPCBinding binding) { + return new JSONRPCService(rc, rcs, b, binding, servletHost); + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCService.java b/tags/java/sca/1.0-RC1b/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCService.java new file mode 100644 index 0000000000..770afe0c60 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCService.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.jsonrpc; + +import java.net.URI; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.core.invocation.JDKProxyFactory; +import org.apache.tuscany.sca.core.invocation.ProxyFactory; +import org.apache.tuscany.sca.extension.helper.ComponentLifecycle; +import org.apache.tuscany.sca.host.http.ServletHost; +import org.apache.tuscany.sca.interfacedef.Interface; +import org.apache.tuscany.sca.interfacedef.java.JavaInterface; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + +/** + * Implementation of the JSONRPC binding provider. + * + * There are multiple servlets used to support the JSON-RPC binidng. + * One servlet to handle requests for the scaDomain script and seperate + * servlets for each SCA which uses . + */ +public class JSONRPCService implements ComponentLifecycle { + + private RuntimeComponentService service; + private ServletHost servletHost; + private Binding binding; + + public static final String SERVICE_PREFIX = "/SCADomain/"; + + // 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 + public static final String SCA_DOMAIN_SCRIPT = SERVICE_PREFIX + "scaDomain.js"; + + + public JSONRPCService(RuntimeComponent component, + RuntimeComponentService service, + Binding b, + JSONRPCBinding binding, + ServletHost servletHost) { + this.service = service; + this.binding = b; + this.servletHost = servletHost; + } + + public void start() { + + // Determine the service business interface + Class serviceInterface = getTargetJavaClass(service.getInterfaceContract().getInterface()); + + // Create a Java proxy to the target service + ProxyFactory proxyFactory = new JDKProxyFactory(); + Object proxy = proxyFactory.createProxy(serviceInterface, service.getRuntimeWire(binding)); + + // Create and register a servlet for this service + JSONRPCServiceServlet serviceServlet = new JSONRPCServiceServlet(binding.getName(), serviceInterface, proxy); + int port; + servletHost.addServletMapping(binding.getURI(), serviceServlet); + URI uri = URI.create(binding.getURI()); + port = uri.getPort(); + if (port == -1) + port = 8080; + + // get the ScaDomainScriptServlet, if it doesn't yet exist create one + // this uses removeServletMapping / addServletMapping as theres no getServletMapping facility + URI domainURI = URI.create("http://localhost:" + port + SCA_DOMAIN_SCRIPT); + ScaDomainScriptServlet scaDomainServlet = (ScaDomainScriptServlet) servletHost.getServletMapping(domainURI.toString()); + if (scaDomainServlet == null) { + scaDomainServlet = new ScaDomainScriptServlet(); + servletHost.addServletMapping(domainURI.toString(), scaDomainServlet); + } + + // Add this service to the scadomain script servlet + scaDomainServlet.addService(binding.getName()); + + } + + public void stop() { + + // Unregister from the service servlet mapping + int port; + servletHost.removeServletMapping(binding.getURI()); + URI uri = URI.create(binding.getURI()); + port = uri.getPort(); + if (port == -1) + port = 8080; + + // Unregister the service from the scaDomain script servlet + URI domainURI = URI.create("http://localhost:" + port + SCA_DOMAIN_SCRIPT); + ScaDomainScriptServlet scaDomainServlet = (ScaDomainScriptServlet) servletHost.getServletMapping(domainURI.toString()); + if (scaDomainServlet != null) { + scaDomainServlet.removeService(binding.getName()); + + // Remove the servlet if there's no more registered services + if (scaDomainServlet.getServiceNames().isEmpty()) { + servletHost.removeServletMapping(domainURI.toString()); + } + } + } + + 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(); + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCServiceServlet.java b/tags/java/sca/1.0-RC1b/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCServiceServlet.java new file mode 100644 index 0000000000..b9eb71e259 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCServiceServlet.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.jsonrpc; + +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.text.ParseException; + +import javax.servlet.ServletConfig; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +import org.json.JSONObject; + +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 + */ +public class JSONRPCServiceServlet extends JSONRPCServlet { + private static final long serialVersionUID = 1L; + + transient String serviceName; + transient Object serviceInstance; + transient Class serviceInterface; + + public JSONRPCServiceServlet(String serviceName, Class serviceInterface, Object serviceInstance) { + this.serviceName = serviceName; + 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 (request.getParameter("smd") != null) { + handleSMDRequest(request, response); + } else { + try { + handleServiceRequest(request, response); + } finally { + HttpSession session = request.getSession(); + if (session != null) { + session.removeAttribute("JSONRPCBridge"); + } + } + } + } + + private void handleServiceRequest(HttpServletRequest request, HttpServletResponse response) throws IOException { + /* + * Create a new bridge for every request to aviod all the problems with + * JSON-RPC-Java storing the bridge in the session + */ + HttpSession session = request.getSession(); + + JSONRPCBridge jsonrpcBridge = new JSONRPCBridge(); + jsonrpcBridge.registerObject(serviceName, serviceInstance, serviceInterface); + session.setAttribute("JSONRPCBridge", jsonrpcBridge); + + // 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; + JSONRPCResult jsonResp = null; + try { + jsonReq = new JSONObject(data.toString()); + } catch (ParseException e) { + throw new RuntimeException("Unable to parse request", e); + } + + String method = jsonReq.getString("method"); + if ((method != null) && (method.indexOf('.') < 0)) { + jsonReq.putOpt("method", serviceName + "." + method); + } + + // invoke the request + jsonResp = jsonrpcBridge.call(new Object[] {request}, jsonReq); + + byte[] bout = jsonResp.toString().getBytes("UTF-8"); + + 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(); + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/JavaToSmd.java b/tags/java/sca/1.0-RC1b/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/JavaToSmd.java new file mode 100644 index 0000000000..196d973a76 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/JavaToSmd.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.jsonrpc; + +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 + */ +public class JavaToSmd { + + public 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 paramater 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/tags/java/sca/1.0-RC1b/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/ScaDomainScriptServlet.java b/tags/java/sca/1.0-RC1b/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/ScaDomainScriptServlet.java new file mode 100644 index 0000000000..262a1adae3 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/ScaDomainScriptServlet.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.jsonrpc; + +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. + */ +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 + "." + serviceName + ";"); + } + + 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/tags/java/sca/1.0-RC1b/modules/binding-jsonrpc/src/main/resources/META-INF/services/org.apache.tuscany.sca.extension.helper.BindingActivator b/tags/java/sca/1.0-RC1b/modules/binding-jsonrpc/src/main/resources/META-INF/services/org.apache.tuscany.sca.extension.helper.BindingActivator new file mode 100644 index 0000000000..e35e70dacc --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-jsonrpc/src/main/resources/META-INF/services/org.apache.tuscany.sca.extension.helper.BindingActivator @@ -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.jsonrpc.JSONRPCBindingActivator diff --git a/tags/java/sca/1.0-RC1b/modules/binding-jsonrpc/src/main/resources/org/apache/tuscany/sca/binding/jsonrpc/jsonrpc.js b/tags/java/sca/1.0-RC1b/modules/binding-jsonrpc/src/main/resources/org/apache/tuscany/sca/binding/jsonrpc/jsonrpc.js new file mode 100644 index 0000000000..d837bab91c --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-jsonrpc/src/main/resources/org/apache/tuscany/sca/binding/jsonrpc/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/tags/java/sca/1.0-RC1b/modules/binding-jsonrpc/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/Echo.java b/tags/java/sca/1.0-RC1b/modules/binding-jsonrpc/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/Echo.java new file mode 100644 index 0000000000..584228abde --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-jsonrpc/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/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.jsonrpc; + +/** + * Interface of our sample JSONRPC service. + * + * @version $Rev$ $Date$ + */ +public interface Echo { + + String echo(String msg); +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-jsonrpc/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/EchoComponentImpl.java b/tags/java/sca/1.0-RC1b/modules/binding-jsonrpc/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/EchoComponentImpl.java new file mode 100644 index 0000000000..e63cafd6a6 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-jsonrpc/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/EchoComponentImpl.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.jsonrpc; + + + +/** + * 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; + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-jsonrpc/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCServiceTestCase.java b/tags/java/sca/1.0-RC1b/modules/binding-jsonrpc/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCServiceTestCase.java new file mode 100644 index 0000000000..1fa53a3817 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-jsonrpc/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCServiceTestCase.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.jsonrpc; + +import java.io.ByteArrayInputStream; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.host.embedded.SCADomain; +import org.json.JSONObject; + +import com.meterware.httpunit.PostMethodWebRequest; +import com.meterware.httpunit.WebConversation; +import com.meterware.httpunit.WebRequest; +import com.meterware.httpunit.WebResponse; + +/** + * @version $Rev: 536083 $ $Date: 2007-05-08 02:18:29 -0400 (Tue, 08 May 2007) $ + */ +public class JSONRPCServiceTestCase extends TestCase { + + private static final String SERVICE_PATH = "/EchoService"; + + private static final String SERVICE_URL = "http://localhost:8085/SCADomain" + SERVICE_PATH; + + private SCADomain domain; + + @Override + protected void setUp() throws Exception { + domain = SCADomain.newInstance("JSONRPCBinding.composite"); + } + + @Override + protected void tearDown() throws Exception { + domain.close(); + } + + 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); + + assertEquals(200, response.getResponseCode()); + JSONObject jsonResp = new JSONObject(response.getText()); + assertEquals("echo: Hello JSON-RPC", jsonResp.getString("result")); + } + + +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-jsonrpc/src/test/resources/JSONRPCBinding.composite b/tags/java/sca/1.0-RC1b/modules/binding-jsonrpc/src/test/resources/JSONRPCBinding.composite new file mode 100644 index 0000000000..491b42c69c --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-jsonrpc/src/test/resources/JSONRPCBinding.composite @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/binding-notification/DISCLAIMER b/tags/java/sca/1.0-RC1b/modules/binding-notification/DISCLAIMER new file mode 100644 index 0000000000..d68a410903 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-notification/DISCLAIMER @@ -0,0 +1,8 @@ +Apache Tuscany is an effort undergoing incubation at The Apache Software +Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is +required of all newly accepted projects until a further review indicates that +the infrastructure, communications, and decision making process have stabilized +in a manner consistent with other successful ASF projects. While incubation +status is not necessarily a reflection of the completeness or stability of the +code, it does indicate that the project has yet to be fully endorsed by the ASF. + diff --git a/tags/java/sca/1.0-RC1b/modules/binding-notification/LICENSE b/tags/java/sca/1.0-RC1b/modules/binding-notification/LICENSE new file mode 100644 index 0000000000..6e529a25c4 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-notification/NOTICE b/tags/java/sca/1.0-RC1b/modules/binding-notification/NOTICE new file mode 100644 index 0000000000..eb1926d971 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-notification/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2007 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/tags/java/sca/1.0-RC1b/modules/binding-notification/pom.xml b/tags/java/sca/1.0-RC1b/modules/binding-notification/pom.xml new file mode 100644 index 0000000000..df22f34e5a --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-notification/pom.xml @@ -0,0 +1,118 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.0-incubating + ../pom.xml + + + tuscany-binding-notification + Apache Tuscany SCA Notification Binding Extension + + + + org.apache.tuscany.sca + tuscany-sca-api + 1.0-incubating + + + org.apache.tuscany.sca + tuscany-core-spi + 1.0-incubating + + + org.apache.tuscany.sca + tuscany-core + 1.0-incubating + + + org.apache.tuscany.sca + tuscany-assembly-xml + 1.0-incubating + + + org.apache.tuscany.sca + tuscany-host-http + 1.0-incubating + + + org.apache.tuscany.sca + tuscany-implementation-notification + 1.0-incubating + + + stax + stax-api + 1.0.1 + + + org.codehaus.woodstox + wstx-asl + 3.2.1 + runtime + + + javax.servlet + servlet-api + 2.5 + provided + + + org.apache.tuscany.sca + tuscany-databinding-axiom + 1.0-incubating + runtime + + + org.apache.ws.commons.axiom + axiom-api + 1.2.5 + + + + + org.apache.tuscany.sca + tuscany-host-jetty + 1.0-incubating + test + + + junit + junit + 4.2 + test + + + org.easymock + easymock + 2.2 + test + + + org.apache.ws.commons.axiom + axiom-impl + 1.2.5 + test + + + diff --git a/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/DefaultNotificationBindingFactory.java b/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/DefaultNotificationBindingFactory.java new file mode 100644 index 0000000000..8e6a78551a --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/NotificationBinding.java b/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/NotificationBinding.java new file mode 100644 index 0000000000..940a69784b --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/NotificationBindingFactory.java b/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/NotificationBindingFactory.java new file mode 100644 index 0000000000..31a8b26c02 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/NotificationBindingImpl.java b/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/NotificationBindingImpl.java new file mode 100644 index 0000000000..f4c210ba7c --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/NotificationBindingModuleActivator.java b/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/NotificationBindingModuleActivator.java new file mode 100644 index 0000000000..a79441e288 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/NotificationBindingModuleActivator.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.binding.notification; + +import java.net.InetAddress; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory; +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.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.DefaultEncodingRegistry; +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.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.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 NotificationTypeManagerImpl ntm; + + private SubscribeEnDeCoder subscribeEnDeCoder; + private ConsumerReferenceEnDeCoder consumerReferenceEnDeCoder; + private EndpointAddressEnDeCoder endpointAddressEnDeCoder; + private NewConsumerEnDeCoder newConsumerEnDeCoder; + private NewProducerEnDeCoder newProducerEnDeCoder; + private NewConsumerResponseEnDeCoder newConsumerResponseEnDeCoder; + private NewProducerResponseEnDeCoder newProducerResponseEnDeCoder; + private NewBrokerEnDeCoder newBrokerEnDeCoder; + private BrokerConsumerReferenceEnDeCoder brokerConsumerReferenceEnDeCoder; + private BrokerProducerReferenceEnDeCoder brokerProducerReferenceEnDeCoder; + private NewBrokerResponseEnDeCoder newBrokerResponseEnDeCoder; + private BrokersEnDeCoder brokersEnDeCoder; + private BrokerEnDeCoder brokerEnDeCoder; + private EndConsumersEnDeCoder endConsumersEnDeCoder; + private EndProducersEnDeCoder endProducersEnDeCoder; + private EndpointReferenceEnDeCoder endpointReferenceEnDeCoder;; + private ReferencePropertiesEnDeCoder referencePropertiesEnDeCoder; + private BrokerIDEnDeCoder brokerIDEnDeCoder; + private ConnectionOverrideEnDeCoder connectionOverrideEnDeCoder; + private ConnectionOverrideResponseEnDeCoder connectionOverrideResponseEnDeCoder; + private NewBrokerAckEnDeCoder newBrokerAckEnDeCoder; + private NeighborBrokerConsumersEnDeCoder neighborBrokerConsumersEnDeCoder; + private RemoveBrokerEnDeCoder removeBrokerEnDeCoder; + private RemovedBrokerEnDeCoder removedBrokerEnDeCoder; + private NeighborsEnDeCoder neighborsEnDeCoder; + private ReplaceBrokerConnectionEnDeCoder replaceBrokerConnectionEnDeCoder; + + private static final String DEFAULT_PORT = "8086"; + + public void start(ExtensionPointRegistry registry) { + + EncodingRegistry encodingRegistry = new DefaultEncodingRegistry(); + subscribeEnDeCoder = new SubscribeEnDeCoder(encodingRegistry); + subscribeEnDeCoder.start(); + consumerReferenceEnDeCoder = new ConsumerReferenceEnDeCoder(encodingRegistry); + consumerReferenceEnDeCoder.start(); + endpointAddressEnDeCoder = new EndpointAddressEnDeCoder(encodingRegistry); + endpointAddressEnDeCoder.start(); + newConsumerEnDeCoder = new NewConsumerEnDeCoder(encodingRegistry); + newConsumerEnDeCoder.start(); + newProducerEnDeCoder = new NewProducerEnDeCoder(encodingRegistry); + newProducerEnDeCoder.start(); + newConsumerResponseEnDeCoder = new NewConsumerResponseEnDeCoder(encodingRegistry); + newConsumerResponseEnDeCoder.start(); + newProducerResponseEnDeCoder = new NewProducerResponseEnDeCoder(encodingRegistry); + newProducerResponseEnDeCoder.start(); + newBrokerEnDeCoder = new NewBrokerEnDeCoder(encodingRegistry); + newBrokerEnDeCoder.start(); + brokerConsumerReferenceEnDeCoder = new BrokerConsumerReferenceEnDeCoder(encodingRegistry); + brokerConsumerReferenceEnDeCoder.start(); + brokerProducerReferenceEnDeCoder = new BrokerProducerReferenceEnDeCoder(encodingRegistry); + brokerProducerReferenceEnDeCoder.start(); + newBrokerResponseEnDeCoder = new NewBrokerResponseEnDeCoder(encodingRegistry); + newBrokerResponseEnDeCoder.start(); + brokersEnDeCoder = new BrokersEnDeCoder(encodingRegistry); + brokersEnDeCoder.start(); + brokerEnDeCoder = new BrokerEnDeCoder(encodingRegistry); + brokerEnDeCoder.start(); + endConsumersEnDeCoder = new EndConsumersEnDeCoder(encodingRegistry); + endConsumersEnDeCoder.start(); + endProducersEnDeCoder = new EndProducersEnDeCoder(encodingRegistry); + endProducersEnDeCoder.start(); + endpointReferenceEnDeCoder = new EndpointReferenceEnDeCoder(encodingRegistry); + endpointReferenceEnDeCoder.start(); + referencePropertiesEnDeCoder = new ReferencePropertiesEnDeCoder(encodingRegistry); + referencePropertiesEnDeCoder.start(); + brokerIDEnDeCoder = new BrokerIDEnDeCoder(encodingRegistry); + brokerIDEnDeCoder.start(); + connectionOverrideEnDeCoder = new ConnectionOverrideEnDeCoder(encodingRegistry); + connectionOverrideEnDeCoder.start(); + connectionOverrideResponseEnDeCoder = new ConnectionOverrideResponseEnDeCoder(encodingRegistry); + connectionOverrideResponseEnDeCoder.start(); + newBrokerAckEnDeCoder = new NewBrokerAckEnDeCoder(encodingRegistry); + newBrokerAckEnDeCoder.start(); + neighborBrokerConsumersEnDeCoder = new NeighborBrokerConsumersEnDeCoder(encodingRegistry); + neighborBrokerConsumersEnDeCoder.start(); + removeBrokerEnDeCoder = new RemoveBrokerEnDeCoder(encodingRegistry); + removeBrokerEnDeCoder.start(); + removedBrokerEnDeCoder = new RemovedBrokerEnDeCoder(encodingRegistry); + removedBrokerEnDeCoder.start(); + neighborsEnDeCoder = new NeighborsEnDeCoder(encodingRegistry); + neighborsEnDeCoder.start(); + replaceBrokerConnectionEnDeCoder = new ReplaceBrokerConnectionEnDeCoder(encodingRegistry); + replaceBrokerConnectionEnDeCoder.start(); + + String httpPort = System.getProperty("notification.httpPort"); + if (httpPort == null) { + httpPort = DEFAULT_PORT; + } + + ServletHost servletHost = new ExtensibleServletHost(registry.getExtensionPoint(ServletHostExtensionPoint.class)); + + ntm = new NotificationTypeManagerImpl(); + ntm.setServletHost(servletHost); + ntm.setEncodingRegistry(encodingRegistry); + ntm.init(); + + String localHost = null; + try { + localHost = InetAddress.getLocalHost().getCanonicalHostName(); + } catch(Exception e) { + e.printStackTrace(); + localHost = "localhost"; + } + String localBaseUrl = "http://" + localHost + ((httpPort != null) ? (":" + httpPort) : ""); + + 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, + ntm, + encodingRegistry, + localBaseUrl); + ProviderFactoryExtensionPoint providerFactories = registry.getExtensionPoint(ProviderFactoryExtensionPoint.class); + providerFactories.addProviderFactory(nbpf); + } + + public void stop(ExtensionPointRegistry registry) { + subscribeEnDeCoder.stop(); + consumerReferenceEnDeCoder.stop(); + endpointAddressEnDeCoder.stop(); + newConsumerEnDeCoder.stop(); + newProducerEnDeCoder.stop(); + newConsumerResponseEnDeCoder.stop(); + newProducerResponseEnDeCoder.stop(); + newBrokerEnDeCoder.stop(); + brokerConsumerReferenceEnDeCoder.stop(); + brokerProducerReferenceEnDeCoder.stop(); + newBrokerResponseEnDeCoder.stop(); + brokersEnDeCoder.stop(); + brokerEnDeCoder.stop(); + endConsumersEnDeCoder.stop(); + endProducersEnDeCoder.stop(); + endpointReferenceEnDeCoder.stop(); + referencePropertiesEnDeCoder.stop(); + brokerIDEnDeCoder.stop(); + connectionOverrideEnDeCoder.stop(); + connectionOverrideResponseEnDeCoder.stop(); + newBrokerAckEnDeCoder.stop(); + neighborBrokerConsumersEnDeCoder.stop(); + removeBrokerEnDeCoder.stop(); + removedBrokerEnDeCoder.stop(); + neighborsEnDeCoder.stop(); + replaceBrokerConnectionEnDeCoder.stop(); + + StAXArtifactProcessorExtensionPoint processors = registry.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); + processors.removeArtifactProcessor(bindingProcessor); + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/NotificationBindingProcessor.java b/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/NotificationBindingProcessor.java new file mode 100644 index 0000000000..edf9a9777a --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/NotificationBindingProcessor.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.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.ContributionWireException; +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 { + } + + public void wire(NotificationBinding notificationBinding) throws ContributionWireException { + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/NotificationBindingProviderFactory.java b/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/NotificationBindingProviderFactory.java new file mode 100644 index 0000000000..2a7892fd19 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/NotificationBindingProviderFactory.java @@ -0,0 +1,233 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, 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.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.tuscany.sca.binding.notification.encoding.BrokerID; +import org.apache.tuscany.sca.binding.notification.encoding.EncodingRegistry; +import org.apache.tuscany.sca.binding.notification.encoding.EndpointReference; +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 representaion of the notification reference binding + * + * @version $Rev$ $Date$ + */ +public class NotificationBindingProviderFactory implements BindingProviderFactory, NotificationBrokerManager { + + private ServletHost servletHost; + private NotificationTypeManager notificationTypeManager; + private EncodingRegistry encodingRegistry; + private String httpUrl; + private Map referenceBindingProviders; + private Map serviceBindingProviders; + + private static NotificationBindingProviderFactory factoryInstance = null; + + public NotificationBindingProviderFactory(ServletHost servletHost, + NotificationTypeManager notificationTypeManager, + EncodingRegistry encodingRegistry, + String httpUrl) { + this.servletHost = servletHost; + this.notificationTypeManager = notificationTypeManager; + this.encodingRegistry = encodingRegistry; + this.httpUrl = httpUrl; + 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) { + 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) { + 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()); + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/NotificationBrokerManager.java b/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/NotificationBrokerManager.java new file mode 100644 index 0000000000..8a6d57e825 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/NotificationReferenceBindingInvoker.java b/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/NotificationReferenceBindingInvoker.java new file mode 100644 index 0000000000..121f6b46e0 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/NotificationReferenceBindingInvoker.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.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/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/NotificationReferenceBindingProvider.java b/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/NotificationReferenceBindingProvider.java new file mode 100644 index 0000000000..d7024c104f --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/NotificationReferenceBindingProvider.java @@ -0,0 +1,344 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, 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 representaion 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.setDefaultDataBinding(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/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/NotificationServiceBindingProvider.java b/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/NotificationServiceBindingProvider.java new file mode 100644 index 0000000000..b803b755de --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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 representaion 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.setDefaultDataBinding(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); + + 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, payload, incomingBrokerID }; + } + 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/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/NotificationTypeManager.java b/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/NotificationTypeManager.java new file mode 100644 index 0000000000..101d05f9cb --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/NotificationTypeManagerImpl.java b/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/NotificationTypeManagerImpl.java new file mode 100644 index 0000000000..94689b4d10 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/NotificationTypeManagerImpl.java @@ -0,0 +1,692 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, 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/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/AbstractBroker.java b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/AbstractBrokerEnDeCoder.java b/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/AbstractBrokerEnDeCoder.java new file mode 100644 index 0000000000..6b3119d16e --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/AbstractBrokerEnDeCoder.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.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/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/AbstractEnDeCoder.java b/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/AbstractEnDeCoder.java new file mode 100644 index 0000000000..ca1fe39039 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/AbstractEnDeCoder.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.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); + } + + /** + * Gets the qualified name of the XML fragment for the Encoding + * object. + * + * @return Qualified name of the XML fragment. + */ + protected abstract QName getEncodingObjectQName(); + + /** + * Returns the type of the encoding object. + * + * @return Encoding object type. + */ + protected abstract Class getEncodingObjectType(); +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/Broker.java b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/BrokerConsumerReference.java b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/BrokerConsumerReferenceEnDeCoder.java b/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/BrokerConsumerReferenceEnDeCoder.java new file mode 100644 index 0000000000..c7bbadd0cd --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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); + } + + @Override + protected QName getEncodingObjectQName() { + return QNAME; + } + + @Override + protected Class getEncodingObjectType() { + return BrokerConsumerReference.class; + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/BrokerEnDeCoder.java b/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/BrokerEnDeCoder.java new file mode 100644 index 0000000000..0bc4cf70e8 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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); + } + + @Override + protected QName getEncodingObjectQName() { + + return QNAME; + } + + @Override + protected Class getEncodingObjectType() { + + return Broker.class; + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/BrokerID.java b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/BrokerIDEnDeCoder.java b/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/BrokerIDEnDeCoder.java new file mode 100644 index 0000000000..a354f0ea79 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/BrokerIDEnDeCoder.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.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); + } + } + + @Override + protected QName getEncodingObjectQName() { + + return QNAME; + } + + @Override + protected Class getEncodingObjectType() { + + return BrokerID.class; + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/BrokerProducerReference.java b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/BrokerProducerReferenceEnDeCoder.java b/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/BrokerProducerReferenceEnDeCoder.java new file mode 100644 index 0000000000..352882a472 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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); + } + + @Override + protected QName getEncodingObjectQName() { + return QNAME; + } + + @Override + protected Class getEncodingObjectType() { + return BrokerProducerReference.class; + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/Brokers.java b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/BrokersEnDeCoder.java b/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/BrokersEnDeCoder.java new file mode 100644 index 0000000000..7ba94b3cff --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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); + } + } + + @Override + protected QName getEncodingObjectQName() { + + return QNAME; + } + + @Override + protected Class getEncodingObjectType() { + + return Brokers.class; + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/ConnectionOverride.java b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/ConnectionOverrideEnDeCoder.java b/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/ConnectionOverrideEnDeCoder.java new file mode 100644 index 0000000000..7db017444f --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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); + } + } + + @Override + protected QName getEncodingObjectQName() { + + return QNAME; + } + + @Override + protected Class getEncodingObjectType() { + + return ConnectionOverride.class; + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/ConnectionOverrideResponse.java b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/ConnectionOverrideResponseEnDeCoder.java b/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/ConnectionOverrideResponseEnDeCoder.java new file mode 100644 index 0000000000..7cfc5fd9fa --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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); + } + } + + @Override + protected QName getEncodingObjectQName() { + + return QNAME; + } + + @Override + protected Class getEncodingObjectType() { + + return ConnectionOverrideResponse.class; + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/Constants.java b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/ConsumerReference.java b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/ConsumerReferenceEnDeCoder.java b/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/ConsumerReferenceEnDeCoder.java new file mode 100644 index 0000000000..cda30fb184 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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); + } + + @Override + protected QName getEncodingObjectQName() { + return QNAME; + } + + @Override + protected Class getEncodingObjectType() { + return ConsumerReference.class; + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/DefaultEncodingRegistry.java b/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/DefaultEncodingRegistry.java new file mode 100644 index 0000000000..0e6596d656 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/DefaultEncodingRegistry.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.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); + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EnDeCoder.java b/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EnDeCoder.java new file mode 100644 index 0000000000..5b4488672e --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EnDeCoder.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.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; +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EncodingException.java b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EncodingObject.java b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EncodingRegistry.java b/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EncodingRegistry.java new file mode 100644 index 0000000000..f5803e2432 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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 obejct 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/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EncodingUtils.java b/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EncodingUtils.java new file mode 100644 index 0000000000..8d06c4d726 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EncodingUtils.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 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/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EndConsumers.java b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EndConsumersEnDeCoder.java b/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EndConsumersEnDeCoder.java new file mode 100644 index 0000000000..27d88f80ff --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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); + } + + @Override + protected QName getEncodingObjectQName() { + return QNAME; + } + + @Override + protected 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/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EndProducers.java b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EndProducersEnDeCoder.java b/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EndProducersEnDeCoder.java new file mode 100644 index 0000000000..b1e78c5ded --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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); + } + + @Override + protected QName getEncodingObjectQName() { + return QNAME; + } + + @Override + protected 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/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EndpointAddress.java b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EndpointAddressEnDeCoder.java b/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EndpointAddressEnDeCoder.java new file mode 100644 index 0000000000..00b7546836 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EndpointAddressEnDeCoder.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.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); + } + } + + @Override + protected QName getEncodingObjectQName() { + + return QNAME; + } + + @Override + protected Class getEncodingObjectType() { + + return EndpointAddress.class; + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EndpointReference.java b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EndpointReferenceEnDeCoder.java b/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EndpointReferenceEnDeCoder.java new file mode 100644 index 0000000000..00ad42074e --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EndpointReferenceEnDeCoder.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.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); + } + } + + @Override + protected QName getEncodingObjectQName() { + + return QNAME; + } + + @Override + protected Class getEncodingObjectType() { + + return EndpointReference.class; + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EndpointReferenceSequence.java b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EndpointReferenceSequenceEnDeCoder.java b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EndpointReferenceWrapper.java b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/EndpointReferenceWrapperEnDeCoder.java b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NeighborBrokerConsumers.java b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NeighborBrokerConsumersEnDeCoder.java b/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NeighborBrokerConsumersEnDeCoder.java new file mode 100644 index 0000000000..82fdb4430d --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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); + } + + @Override + protected QName getEncodingObjectQName() { + return QNAME; + } + + @Override + protected 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/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/Neighbors.java b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NeighborsEnDeCoder.java b/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NeighborsEnDeCoder.java new file mode 100644 index 0000000000..33020b5ab1 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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); + } + } + + @Override + protected QName getEncodingObjectQName() { + + return QNAME; + } + + @Override + protected Class getEncodingObjectType() { + + return Neighbors.class; + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NewBroker.java b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NewBrokerAck.java b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NewBrokerAckEnDeCoder.java b/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NewBrokerAckEnDeCoder.java new file mode 100644 index 0000000000..c848b3cec7 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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); + } + } + + @Override + protected QName getEncodingObjectQName() { + + return QNAME; + } + + @Override + protected Class getEncodingObjectType() { + + return NewBrokerAck.class; + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NewBrokerEnDeCoder.java b/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NewBrokerEnDeCoder.java new file mode 100644 index 0000000000..23dbb3eb2a --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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); + } + + @Override + protected QName getEncodingObjectQName() { + + return QNAME; + } + + @Override + protected Class getEncodingObjectType() { + + return NewBroker.class; + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NewBrokerResponse.java b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NewBrokerResponseEnDeCoder.java b/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NewBrokerResponseEnDeCoder.java new file mode 100644 index 0000000000..5c9ffa1499 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NewBrokerResponseEnDeCoder.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.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); + } + } + + @Override + protected QName getEncodingObjectQName() { + + return QNAME; + } + + @Override + protected Class getEncodingObjectType() { + + return NewBrokerResponse.class; + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NewConsumer.java b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NewConsumerEnDeCoder.java b/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NewConsumerEnDeCoder.java new file mode 100644 index 0000000000..510c400069 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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); + } + + @Override + protected QName getEncodingObjectQName() { + return QNAME; + } + + @Override + protected Class getEncodingObjectType() { + return NewConsumer.class; + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NewConsumerResponse.java b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NewConsumerResponseEnDeCoder.java b/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NewConsumerResponseEnDeCoder.java new file mode 100644 index 0000000000..f304997b72 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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); + } + + @Override + protected QName getEncodingObjectQName() { + return QNAME; + } + + @Override + protected 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/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NewProducer.java b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NewProducerEnDeCoder.java b/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NewProducerEnDeCoder.java new file mode 100644 index 0000000000..9760af6dd0 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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); + } + + @Override + protected QName getEncodingObjectQName() { + return QNAME; + } + + @Override + protected Class getEncodingObjectType() { + return NewProducer.class; + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NewProducerResponse.java b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NewProducerResponseEnDeCoder.java b/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/NewProducerResponseEnDeCoder.java new file mode 100644 index 0000000000..6c2ef3437f --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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); + } + + @Override + protected QName getEncodingObjectQName() { + return QNAME; + } + + @Override + protected 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/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/ReferenceProperties.java b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/ReferencePropertiesEnDeCoder.java b/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/ReferencePropertiesEnDeCoder.java new file mode 100644 index 0000000000..de33400647 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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); + } + } + + @Override + protected QName getEncodingObjectQName() { + + return QNAME; + } + + @Override + protected Class getEncodingObjectType() { + + return ReferenceProperties.class; + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/RemoveBroker.java b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/RemoveBrokerEnDeCoder.java b/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/RemoveBrokerEnDeCoder.java new file mode 100644 index 0000000000..2e44f61809 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/RemoveBrokerEnDeCoder.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.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); + } + } + + @Override + protected QName getEncodingObjectQName() { + + return QNAME; + } + + @Override + protected Class getEncodingObjectType() { + + return RemoveBroker.class; + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/RemovedBroker.java b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/RemovedBrokerEnDeCoder.java b/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/RemovedBrokerEnDeCoder.java new file mode 100644 index 0000000000..5999ce7500 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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); + } + + @Override + protected QName getEncodingObjectQName() { + return QNAME; + } + + @Override + protected Class getEncodingObjectType() { + return RemovedBroker.class; + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/ReplaceBrokerConnection.java b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/ReplaceBrokerConnectionEnDeCoder.java b/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/ReplaceBrokerConnectionEnDeCoder.java new file mode 100644 index 0000000000..2c68d3ee4e --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/ReplaceBrokerConnectionEnDeCoder.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.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); + } + } + + @Override + protected QName getEncodingObjectQName() { + + return QNAME; + } + + @Override + protected Class getEncodingObjectType() { + + return ReplaceBrokerConnection.class; + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/Subscribe.java b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/SubscribeEnDeCoder.java b/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/encoding/SubscribeEnDeCoder.java new file mode 100644 index 0000000000..e09c0c9e7d --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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); + } + } + + @Override + protected QName getEncodingObjectQName() { + + return QNAME; + } + + @Override + protected Class getEncodingObjectType() { + + return Subscribe.class; + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/util/IOUtils.java b/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/util/IOUtils.java new file mode 100644 index 0000000000..40e0a8e47f --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/util/IOUtils.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.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 { + + 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/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/util/NotificationServlet.java b/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/util/NotificationServlet.java new file mode 100644 index 0000000000..5d05bb560c --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/util/NotificationServlet.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.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 { + public byte[] handle(Map headers, byte[] payload); + } + + public interface NotificationServletStreamHandler { + public void handle(Map headers, ServletInputStream istream, int contentLength, ServletOutputStream ostream); + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/util/URIUtil.java b/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/util/URIUtil.java new file mode 100644 index 0000000000..2a2b16d3b0 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/java/org/apache/tuscany/sca/binding/notification/util/URIUtil.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.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/tags/java/sca/1.0-RC1b/modules/binding-notification/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-notification/src/test/java/org/apache/tuscany/sca/binding/notification/encoding/AxiomTestCase.java b/tags/java/sca/1.0-RC1b/modules/binding-notification/src/test/java/org/apache/tuscany/sca/binding/notification/encoding/AxiomTestCase.java new file mode 100644 index 0000000000..e46ecd0fa9 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-notification/src/test/java/org/apache/tuscany/sca/binding/notification/encoding/AxiomTestCase.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 java.io.ByteArrayInputStream; +import java.io.StringWriter; + +import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.impl.builder.StAXOMBuilder; +import org.junit.Assert; + +import junit.framework.TestCase; + +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/tags/java/sca/1.0-RC1b/modules/binding-notification/src/test/java/org/apache/tuscany/sca/binding/notification/encoding/EncodingTestCase.java b/tags/java/sca/1.0-RC1b/modules/binding-notification/src/test/java/org/apache/tuscany/sca/binding/notification/encoding/EncodingTestCase.java new file mode 100644 index 0000000000..e0d398f4d8 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-notification/src/test/java/org/apache/tuscany/sca/binding/notification/encoding/EncodingTestCase.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.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 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.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.ConsumerReferenceEnDeCoder; +import org.apache.tuscany.sca.binding.notification.encoding.DefaultEncodingRegistry; +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.NeighborBrokerConsumers; +import org.apache.tuscany.sca.binding.notification.encoding.NeighborBrokerConsumersEnDeCoder; +import org.apache.tuscany.sca.binding.notification.encoding.Neighbors; +import org.apache.tuscany.sca.binding.notification.encoding.NeighborsEnDeCoder; +import org.apache.tuscany.sca.binding.notification.encoding.NewBroker; +import org.apache.tuscany.sca.binding.notification.encoding.NewBrokerEnDeCoder; +import org.apache.tuscany.sca.binding.notification.encoding.NewBrokerResponse; +import org.apache.tuscany.sca.binding.notification.encoding.NewBrokerResponseEnDeCoder; +import org.apache.tuscany.sca.binding.notification.encoding.NewConsumerResponse; +import org.apache.tuscany.sca.binding.notification.encoding.NewConsumerResponseEnDeCoder; +import org.apache.tuscany.sca.binding.notification.encoding.NewProducerResponse; +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.RemoveBroker; +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.ReplaceBrokerConnection; +import org.apache.tuscany.sca.binding.notification.encoding.ReplaceBrokerConnectionEnDeCoder; +import org.apache.tuscany.sca.binding.notification.encoding.Subscribe; +import org.apache.tuscany.sca.binding.notification.encoding.SubscribeEnDeCoder; + +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/tags/java/sca/1.0-RC1b/modules/binding-osgi/DISCLAIMER b/tags/java/sca/1.0-RC1b/modules/binding-osgi/DISCLAIMER new file mode 100644 index 0000000000..d68a410903 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-osgi/DISCLAIMER @@ -0,0 +1,8 @@ +Apache Tuscany is an effort undergoing incubation at The Apache Software +Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is +required of all newly accepted projects until a further review indicates that +the infrastructure, communications, and decision making process have stabilized +in a manner consistent with other successful ASF projects. While incubation +status is not necessarily a reflection of the completeness or stability of the +code, it does indicate that the project has yet to be fully endorsed by the ASF. + diff --git a/tags/java/sca/1.0-RC1b/modules/binding-osgi/LICENSE b/tags/java/sca/1.0-RC1b/modules/binding-osgi/LICENSE new file mode 100644 index 0000000000..4b5ab74408 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-osgi/LICENSE @@ -0,0 +1,251 @@ + + 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 implementation-script temporarily includes one file under the following BSD license: + + Copyright (c) 2006, Sun Microsystems, Inc. + 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 Sun Microsystems, Inc. nor the names of + 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/tags/java/sca/1.0-RC1b/modules/binding-osgi/NOTICE b/tags/java/sca/1.0-RC1b/modules/binding-osgi/NOTICE new file mode 100644 index 0000000000..9a03eabdab --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-osgi/NOTICE @@ -0,0 +1,17 @@ +${pom.name} +Copyright (c) 2005 - 2007 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + +Unless otherwise indicated, all distribution made available by the Apache Software Foundation +is provided to you under the terms and conditions of the Apache License Version 2.0 ("AL"). +A copy of the AL is provided with this distribution as the LICENSE file present in the +root directory, and is also available at http://www.apache.org/licenses/. + +This product also includes software under the BSD license +(see the LICENSE file contained in this distribution), with +the following copyright: + +Copyright (c) 2006, Sun Microsystems, Inc. +All rights reserved. diff --git a/tags/java/sca/1.0-RC1b/modules/binding-osgi/pom.xml b/tags/java/sca/1.0-RC1b/modules/binding-osgi/pom.xml new file mode 100644 index 0000000000..d8a26f1e94 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-osgi/pom.xml @@ -0,0 +1,57 @@ + + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.0-incubating + ../pom.xml + + + tuscany-binding-osgi + Apache Tuscany Binding for OSGi + + + + + org.apache.tuscany.sca + tuscany-host-embedded + 1.0-incubating + + + + junit + junit + 3.8.1 + test + + + + org.easymock + easymock + 2.2 + test + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/binding-osgi/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator b/tags/java/sca/1.0-RC1b/modules/binding-osgi/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator new file mode 100644 index 0000000000..1021e0d536 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-osgi/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.osgi.XxxxModuleActivator diff --git a/tags/java/sca/1.0-RC1b/modules/binding-rmi/.ruleset b/tags/java/sca/1.0-RC1b/modules/binding-rmi/.ruleset new file mode 100644 index 0000000000..3886f07f2d --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-rmi/.ruleset @@ -0,0 +1,190 @@ + + + + PMD Plugin preferences rule set + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/binding-rmi/DISCLAIMER b/tags/java/sca/1.0-RC1b/modules/binding-rmi/DISCLAIMER new file mode 100644 index 0000000000..d68a410903 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-rmi/DISCLAIMER @@ -0,0 +1,8 @@ +Apache Tuscany is an effort undergoing incubation at The Apache Software +Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is +required of all newly accepted projects until a further review indicates that +the infrastructure, communications, and decision making process have stabilized +in a manner consistent with other successful ASF projects. While incubation +status is not necessarily a reflection of the completeness or stability of the +code, it does indicate that the project has yet to be fully endorsed by the ASF. + diff --git a/tags/java/sca/1.0-RC1b/modules/binding-rmi/LICENSE b/tags/java/sca/1.0-RC1b/modules/binding-rmi/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-rmi/NOTICE b/tags/java/sca/1.0-RC1b/modules/binding-rmi/NOTICE new file mode 100644 index 0000000000..94481d6cfa --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-rmi/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2007 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/tags/java/sca/1.0-RC1b/modules/binding-rmi/pom.xml b/tags/java/sca/1.0-RC1b/modules/binding-rmi/pom.xml new file mode 100755 index 0000000000..acc6f01aa8 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-rmi/pom.xml @@ -0,0 +1,59 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.0-incubating + ../pom.xml + + tuscany-binding-rmi + Apache Tuscany SCA RMI Binding Extension + + + + + org.apache.tuscany.sca + tuscany-extension-helper + 1.0-incubating + + + + org.apache.tuscany.sca + tuscany-host-rmi + 1.0-incubating + + + + cglib + cglib-nodep + 2.1_3 + + + + org.apache.tuscany.sca + tuscany-implementation-java-runtime + 1.0-incubating + test + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/RMIBinding.java b/tags/java/sca/1.0-RC1b/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/RMIBinding.java new file mode 100644 index 0000000000..e9986e216c --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/RMIBinding.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.rmi; + +import org.apache.tuscany.sca.extension.helper.utils.AbstractBinding; + +/** + * Represents a binding to an RMI service. + */ +public class RMIBinding extends AbstractBinding { + + 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; + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/RMIBindingActivator.java b/tags/java/sca/1.0-RC1b/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/RMIBindingActivator.java new file mode 100644 index 0000000000..066335fd57 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/RMIBindingActivator.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.rmi; + +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.rmi.ExtensibleRMIHost; +import org.apache.tuscany.sca.host.rmi.RMIHost; +import org.apache.tuscany.sca.host.rmi.RMIHostExtensionPoint; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + +public class RMIBindingActivator implements BindingActivator { + + private RMIHost rmiHost; + + public RMIBindingActivator(RMIHostExtensionPoint rmiHosts) { + this.rmiHost = new ExtensibleRMIHost(rmiHosts); + } + + public Class getBindingClass() { + return RMIBinding.class; + } + + public InvokerFactory createInvokerFactory(RuntimeComponent rc, RuntimeComponentReference rcr, Binding b, RMIBinding binding) { + return new RMIReferenceInvokerFactory(rc, rcr, binding, rmiHost); + } + + public ComponentLifecycle createService(RuntimeComponent rc, RuntimeComponentService rcs, Binding b, RMIBinding binding) { + return new RMIService(rc, rcs, binding, rmiHost); + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/RMIReferenceInvoker.java b/tags/java/sca/1.0-RC1b/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/RMIReferenceInvoker.java new file mode 100644 index 0000000000..f9d8fd59fe --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/RMIReferenceInvoker.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.rmi; + +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; + +public class RMIReferenceInvoker implements Invoker { + + 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); + } + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/RMIReferenceInvokerFactory.java b/tags/java/sca/1.0-RC1b/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/RMIReferenceInvokerFactory.java new file mode 100644 index 0000000000..2853946560 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/RMIReferenceInvokerFactory.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.rmi; + +import java.lang.reflect.Method; + +import org.apache.tuscany.sca.extension.helper.InvokerFactory; +import org.apache.tuscany.sca.host.rmi.RMIHost; +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.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.osoa.sca.ServiceRuntimeException; + +public class RMIReferenceInvokerFactory implements InvokerFactory { + + RuntimeComponentReference reference; + RMIHost rmiHost; + RMIBinding binding; + + public RMIReferenceInvokerFactory(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); + } + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/RMIService.java b/tags/java/sca/1.0-RC1b/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/RMIService.java new file mode 100644 index 0000000000..2c3be9539b --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/RMIService.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.rmi; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.rmi.Remote; +import java.rmi.server.UnicastRemoteObject; + +import net.sf.cglib.asm.ClassWriter; +import net.sf.cglib.asm.Constants; +import net.sf.cglib.asm.Type; +import net.sf.cglib.proxy.Enhancer; +import net.sf.cglib.proxy.MethodInterceptor; +import net.sf.cglib.proxy.MethodProxy; + +import org.apache.tuscany.sca.extension.helper.ComponentLifecycle; +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.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; +import org.osoa.sca.ServiceRuntimeException; + +public class RMIService implements ComponentLifecycle { + + private RuntimeComponent component; + private RuntimeComponentService service; + private RMIBinding binding; + private RMIHost rmiHost; + private RuntimeWire wire; + + public RMIService(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() { + } + + protected int getPort(String port) { + int portNumber = RMIHost.RMI_DEFAULT_PORT; + if (port != null && port.length() > 0) { + portNumber = Integer.decode(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 { + return invokeTarget(JavaInterfaceUtil.findOperation(method, serviceInterface.getOperations()), args); + } + }); + Class targetJavaInterface = getTargetJavaClass(serviceInterface); + if (!Remote.class.isAssignableFrom(targetJavaInterface)) { + RMIServiceClassLoader classloader = new RMIServiceClassLoader(getClass().getClassLoader()); + final byte[] byteCode = generateRemoteInterface(targetJavaInterface); + targetJavaInterface = classloader.defineClass(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.getCanonicalName(); + ClassWriter cw = new ClassWriter(false); + + String simpleName = serviceInterface.getSimpleName(); + cw.visit(Constants.V1_5, Constants.ACC_PUBLIC + Constants.ACC_ABSTRACT + Constants.ACC_INTERFACE, interfazeName + .replace('.', '/'), "java/lang/Object", new String[] {"java/rmi/Remote"}, simpleName + ".java"); + + 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(), + new String[] {"java/rmi/RemoteException"}, + null); + } + 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(byte[] byteArray) { + return defineClass(null, byteArray, 0, byteArray.length); + } + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-rmi/src/main/resources/META-INF/services/org.apache.tuscany.sca.extension.helper.BindingActivator b/tags/java/sca/1.0-RC1b/modules/binding-rmi/src/main/resources/META-INF/services/org.apache.tuscany.sca.extension.helper.BindingActivator new file mode 100644 index 0000000000..582f321be9 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-rmi/src/main/resources/META-INF/services/org.apache.tuscany.sca.extension.helper.BindingActivator @@ -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.rmi.RMIBindingActivator diff --git a/tags/java/sca/1.0-RC1b/modules/binding-rmi/src/test/java/helloworld/HelloWorldImpl.java b/tags/java/sca/1.0-RC1b/modules/binding-rmi/src/test/java/helloworld/HelloWorldImpl.java new file mode 100644 index 0000000000..acb81a00f6 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-rmi/src/test/java/helloworld/HelloWorldImpl.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 helloworld; + +import org.osoa.sca.annotations.Service; + + +/** + * This class implements the HelloWorld service. + */ +@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) { + return "Hi from " + greeter + " in RMI Service to - " + name; + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-rmi/src/test/java/helloworld/HelloWorldRmiImpl.java b/tags/java/sca/1.0-RC1b/modules/binding-rmi/src/test/java/helloworld/HelloWorldRmiImpl.java new file mode 100644 index 0000000000..73aedc3b6c --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-rmi/src/test/java/helloworld/HelloWorldRmiImpl.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 helloworld; + +import org.osoa.sca.annotations.Reference; +import org.osoa.sca.annotations.Service; + +/** + * This class implements the HelloWorld service. + */ +@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) { + return extService.sayHi(name, greeter) + " thro the RMI Reference"; + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-rmi/src/test/java/helloworld/HelloWorldRmiService.java b/tags/java/sca/1.0-RC1b/modules/binding-rmi/src/test/java/helloworld/HelloWorldRmiService.java new file mode 100644 index 0000000000..f636c8f7d8 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-rmi/src/test/java/helloworld/HelloWorldRmiService.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 helloworld; + +/** + * This is the business interface of the HelloWorld greetings service. + */ +public interface HelloWorldRmiService { + + String sayRmiHello(String name); + String sayRmiHi(String name, String greeter); + +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-rmi/src/test/java/helloworld/HelloWorldService.java b/tags/java/sca/1.0-RC1b/modules/binding-rmi/src/test/java/helloworld/HelloWorldService.java new file mode 100644 index 0000000000..d5dc509f3e --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-rmi/src/test/java/helloworld/HelloWorldService.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 helloworld; + +/** + * This is the business interface of the HelloWorld greetings service. + */ +public interface HelloWorldService { + + String sayHello(String name); + String sayHi(String name, String greeter); + +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-rmi/src/test/java/org/apache/tuscany/sca/binding/rmi/BindingTestCase.java b/tags/java/sca/1.0-RC1b/modules/binding-rmi/src/test/java/org/apache/tuscany/sca/binding/rmi/BindingTestCase.java new file mode 100644 index 0000000000..e626293c6e --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-rmi/src/test/java/org/apache/tuscany/sca/binding/rmi/BindingTestCase.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.binding.rmi; + +import helloworld.HelloWorldRmiService; +import junit.framework.Assert; + +import org.apache.tuscany.sca.host.embedded.SCADomain; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +public class BindingTestCase { + private static HelloWorldRmiService helloWorldRmiService; + private static SCADomain domain; + + @Test + public void testRmiService() { + System.out.println(helloWorldRmiService.sayRmiHello("Tuscany World!")); + Assert.assertEquals("Hello from the RMI Service to - Tuscany World! thro the RMI Reference", + helloWorldRmiService.sayRmiHello("Tuscany World!")); + + System.out.println(helloWorldRmiService.sayRmiHi("Tuscany World!", "Apache World")); + + Assert.assertEquals("Hi from Apache World in RMI Service to - Tuscany World! thro the RMI Reference", + helloWorldRmiService.sayRmiHi("Tuscany World!", "Apache World")); + } + + + + @BeforeClass + public static void init() throws Exception { +try { + domain = SCADomain.newInstance("RMIBindingTest.composite"); + helloWorldRmiService = + domain.getService(HelloWorldRmiService.class, "HelloWorldRmiServiceComponent"); +} catch (Exception e) { + e.printStackTrace(); +} + } + + @AfterClass + public static void destroy() throws Exception { + domain.close(); + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-rmi/src/test/resources/HelloWorldImpl.componentType b/tags/java/sca/1.0-RC1b/modules/binding-rmi/src/test/resources/HelloWorldImpl.componentType new file mode 100644 index 0000000000..224a68f88d --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-rmi/src/test/resources/HelloWorldImpl.componentType @@ -0,0 +1,23 @@ + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/binding-rmi/src/test/resources/HelloWorldRmiImpl.componentType b/tags/java/sca/1.0-RC1b/modules/binding-rmi/src/test/resources/HelloWorldRmiImpl.componentType new file mode 100644 index 0000000000..a83e7e6d1d --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-rmi/src/test/resources/HelloWorldRmiImpl.componentType @@ -0,0 +1,27 @@ + + + + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/binding-rmi/src/test/resources/RMIBindingTest.composite b/tags/java/sca/1.0-RC1b/modules/binding-rmi/src/test/resources/RMIBindingTest.composite new file mode 100644 index 0000000000..d29fe85586 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-rmi/src/test/resources/RMIBindingTest.composite @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/DISCLAIMER b/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/DISCLAIMER new file mode 100644 index 0000000000..d68a410903 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/DISCLAIMER @@ -0,0 +1,8 @@ +Apache Tuscany is an effort undergoing incubation at The Apache Software +Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is +required of all newly accepted projects until a further review indicates that +the infrastructure, communications, and decision making process have stabilized +in a manner consistent with other successful ASF projects. While incubation +status is not necessarily a reflection of the completeness or stability of the +code, it does indicate that the project has yet to be fully endorsed by the ASF. + diff --git a/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/LICENSE b/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/LICENSE new file mode 100644 index 0000000000..6e529a25c4 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/NOTICE b/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/NOTICE new file mode 100644 index 0000000000..eb1926d971 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2007 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/pom.xml b/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/pom.xml new file mode 100644 index 0000000000..eaf03e0f23 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/pom.xml @@ -0,0 +1,90 @@ + + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.0-incubating + ../pom.xml + + + tuscany-binding-sca-axis2 + Apache Tuscany SCA Axis2-based Default Binding Extension + + + + + org.apache.tuscany.sca + tuscany-node + 1.0-incubating + + + + org.apache.tuscany.sca + tuscany-binding-sca + 1.0-incubating + + + + org.apache.tuscany.sca + tuscany-binding-ws-axis2 + 1.0-incubating + + + + javax.servlet + servlet-api + 2.4 + provided + + + + org.easymock + easymock + 2.2 + test + + + + org.apache.tuscany.sca + tuscany-host-jetty + 1.0-incubating + test + + + + org.apache.tuscany.sca + tuscany-host-embedded + 1.0-incubating + test + + + + org.apache.tuscany.sca + tuscany-implementation-java-runtime + 1.0-incubating + test + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/main/java/org/apache/tuscany/sca/binding/sca/axis2/impl/Axis2SCABindingInvoker.java b/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/main/java/org/apache/tuscany/sca/binding/sca/axis2/impl/Axis2SCABindingInvoker.java new file mode 100644 index 0000000000..161bc25213 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/main/java/org/apache/tuscany/sca/binding/sca/axis2/impl/Axis2SCABindingInvoker.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.sca.axis2.impl; + +import java.lang.reflect.UndeclaredThrowableException; +import java.net.ConnectException; +import java.util.logging.Level; +import java.util.logging.Logger; + +import org.apache.axis2.AxisFault; +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 final static Logger logger = Logger.getLogger(Axis2SCABindingInvoker.class.getName()); + + private int retryCount = 100; + private int retryInterval = 5000; //ms + 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 b 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) { + throw new ServiceUnavailableException("Endpoint for service: " + provider.getSCABinding().getURI() + + " can't be found for component: " + + provider.getComponent().getName() + + " reference: " + + provider.getComponentReference().getName()); + } + if (to != null) { + to.mergeEndpoint(eprTo); + } else { + 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.getTo().getReferenceParameters().getCallbackReference(); + + if ((callbackEPR == null) || (callbackEPR.getURI().equals("/"))) { + + callbackEPR = provider.getCallbackEndpoint(); + + if (callbackEPR != null) { + msg.getTo().getReferenceParameters().setCallbackReference(callbackEPR); + } + } + + // do the axis2 stuff + Message returnMessage = null; + + // for (int i =0; i < retryCount; i++){ + + returnMessage = axis2Invoker.invoke(msg); + /* + if ( AxisFault.class.isInstance(returnMessage.getBody())){ + + AxisFault axisFault = returnMessage.getBody(); + + if (axisFault.getCause().getClass() == ConnectException.class) { + logger.log(Level.INFO, "Trying to send message to " + + msg.getTo().getURI()); + + // try and get the service endpoint again just in case + // it's moved + EndpointReference serviceEPR = provider.refreshServiceEndpoint(); + + if (serviceEPR == 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(serviceEPR); + } else { + break; + } + + } else { + break; + } + + try { + Thread.sleep(retryInterval); + } catch(InterruptedException ex) { + } + } + */ + return returnMessage; + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/main/java/org/apache/tuscany/sca/binding/sca/axis2/impl/Axis2SCABindingProviderFactory.java b/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/main/java/org/apache/tuscany/sca/binding/sca/axis2/impl/Axis2SCABindingProviderFactory.java new file mode 100644 index 0000000000..91aa8c9a26 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/main/java/org/apache/tuscany/sca/binding/sca/axis2/impl/Axis2SCABindingProviderFactory.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.sca.axis2.impl; + +import org.apache.tuscany.sca.binding.sca.DistributedSCABinding; +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.node.NodeFactory; +import org.apache.tuscany.sca.node.SCANode; +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 MessageFactory messageFactory; + private ServletHost servletHost; + private SCANode node = null; + + public Axis2SCABindingProviderFactory(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); + NodeFactory nodeFactory = modelFactories.getFactory(NodeFactory.class); + + if (nodeFactory != null) { + this.node = nodeFactory.getNode(); + } + } + + public ReferenceBindingProvider createReferenceBindingProvider(RuntimeComponent component, + RuntimeComponentReference reference, + DistributedSCABinding binding) { + return new Axis2SCAReferenceBindingProvider(node, component, reference, binding, servletHost, messageFactory); + } + + public ServiceBindingProvider createServiceBindingProvider(RuntimeComponent component, + RuntimeComponentService service, + DistributedSCABinding binding) { + return new Axis2SCAServiceBindingProvider(node, component, service, binding, servletHost, messageFactory); + } + + public Class getModelType() { + return DistributedSCABinding.class; + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/main/java/org/apache/tuscany/sca/binding/sca/axis2/impl/Axis2SCAReferenceBindingProvider.java b/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/main/java/org/apache/tuscany/sca/binding/sca/axis2/impl/Axis2SCAReferenceBindingProvider.java new file mode 100644 index 0000000000..40c36820b3 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/main/java/org/apache/tuscany/sca/binding/sca/axis2/impl/Axis2SCAReferenceBindingProvider.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.sca.axis2.impl; + +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.DefaultWebServiceBindingFactory; +import org.apache.tuscany.sca.binding.ws.WebServiceBinding; +import org.apache.tuscany.sca.binding.ws.axis2.Axis2ReferenceBindingProvider; +import org.apache.tuscany.sca.binding.ws.axis2.Java2WSDLHelper; +import org.apache.tuscany.sca.core.assembly.EndpointReferenceImpl; +import org.apache.tuscany.sca.domain.SCADomainService; +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.interfacedef.java.JavaInterfaceContract; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.MessageFactory; +import org.apache.tuscany.sca.node.SCANode; +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 SCANode node; + 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(SCANode node, + RuntimeComponent component, + RuntimeComponentReference reference, + DistributedSCABinding binding, + ServletHost servletHost, + MessageFactory messageFactory) { + this.node = node; + this.component = component; + this.reference = reference; + this.binding = binding.getSCABinding(); + wsBinding = (new DefaultWebServiceBindingFactory()).createWebServiceBinding(); + + // Turn the java interface contract into a wsdl interface contract + InterfaceContract contract = reference.getInterfaceContract(); + if ((contract instanceof JavaInterfaceContract)) { + contract = Java2WSDLHelper.createWSDLInterfaceContract((JavaInterfaceContract)contract, null); + } + + // Set to use the Axiom data binding + contract.getInterface().setDefaultDataBinding(OMElement.class.getName()); + + wsBinding.setBindingInterfaceContract(contract); + wsBinding.setName(this.binding.getName()); + + axisReferenceBindingProvider = new Axis2ReferenceBindingProvider(component, + reference, + wsBinding, + servletHost, + messageFactory); + } + + 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 && node != null ){ + // try to resolve the service endpoint with the registry + SCADomainService serviceDiscovery = node.getDomainService(); + + if (serviceDiscovery != null){ + + // The binding URI might be null in the case where this reference is completely + // dynamic, for example, in the case of callbacks + if (binding.getURI() != null) { + String serviceUrl = serviceDiscovery.findServiceEndpoint(node.getDomainURI(), + binding.getURI(), + SCABinding.class.getName()); + + if ( (serviceUrl != null ) && + (!serviceUrl.equals(""))){ + serviceEPR = new EndpointReferenceImpl(serviceUrl); + } + } + } else { + throw new IllegalStateException("No domain service available while trying to find component: "+ + component.getName() + + " and service: " + + reference.getName()); + } + } + + return serviceEPR; + } + + /** + * Go back to the distributed domain to go and get the service endpoint + * + * @return An EPR for the target service that this reference refers to + */ + public EndpointReference refreshServiceEndpoint(){ + serviceEPR= null; + return getServiceEndpoint(); + } + + /** + * 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() { + // Try and resolve the service endpoint just in case it is available now + getServiceEndpoint(); + axisReferenceBindingProvider.start(); + } + + public void stop() { + axisReferenceBindingProvider.stop(); + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/main/java/org/apache/tuscany/sca/binding/sca/axis2/impl/Axis2SCAServiceBindingProvider.java b/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/main/java/org/apache/tuscany/sca/binding/sca/axis2/impl/Axis2SCAServiceBindingProvider.java new file mode 100644 index 0000000000..59b074d4a8 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/main/java/org/apache/tuscany/sca/binding/sca/axis2/impl/Axis2SCAServiceBindingProvider.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.axis2.impl; + +import java.net.InetAddress; +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URL; +import java.net.UnknownHostException; +import java.util.logging.Level; +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.DefaultWebServiceBindingFactory; +import org.apache.tuscany.sca.binding.ws.WebServiceBinding; +import org.apache.tuscany.sca.binding.ws.axis2.Axis2ServiceProvider; +import org.apache.tuscany.sca.binding.ws.axis2.Java2WSDLHelper; +import org.apache.tuscany.sca.domain.SCADomainService; +import org.apache.tuscany.sca.host.http.ServletHost; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceContract; +import org.apache.tuscany.sca.invocation.MessageFactory; +import org.apache.tuscany.sca.node.SCANode; +import org.apache.tuscany.sca.provider.ServiceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + +/** + * 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 final static Logger logger = Logger.getLogger(Axis2SCAServiceBindingProvider.class.getName()); + + private SCANode node; + private SCABinding binding; + private Axis2ServiceProvider axisProvider; + private WebServiceBinding wsBinding; + + private boolean started = false; + + + public Axis2SCAServiceBindingProvider(SCANode node, + RuntimeComponent component, + RuntimeComponentService service, + DistributedSCABinding binding, + ServletHost servletHost, + MessageFactory messageFactory) { + this.node = node; + this.binding = binding.getSCABinding(); + wsBinding = (new DefaultWebServiceBindingFactory()).createWebServiceBinding(); + + // Turn the java interface contract into a wsdl interface contract + InterfaceContract contract = service.getInterfaceContract(); + if ((contract instanceof JavaInterfaceContract)) { + contract = Java2WSDLHelper.createWSDLInterfaceContract((JavaInterfaceContract)contract, null); + } + + // Set to use the Axiom data binding + contract.getInterface().setDefaultDataBinding(OMElement.class.getName()); + + wsBinding.setBindingInterfaceContract(contract); + wsBinding.setName(this.binding.getName()); + wsBinding.setURI(this.binding.getURI()); + + axisProvider = new Axis2SCAServiceProvider(component, + service, + this.binding, + wsBinding, + servletHost, + messageFactory); + + + if (node != null){ + // get the url out of the binding and send it to the registry if + // a distributed domain is configured + SCADomainService domainService = node.getDomainService(); + + if (domainService != null) { + // work out what the component service name is that will be registered + // it should be the path element of the binding uri + String componentServiceName = this.binding.getURI(); + + try { + URI servicePath = new URI(this.binding.getURI()); + componentServiceName = servicePath.getPath(); + + // strip any leading slash + if (componentServiceName.charAt(0) == '/'){ + componentServiceName = componentServiceName.substring(1, componentServiceName.length()); + } + } catch(Exception ex) { + // do nothing, the binding uri string will be used + } + + // work out what the endpoint address is that the component service name will be registered + // against. Be default this is the url calculated by the web services binding but + // we have to adjust that to: + // 1. correct the host and port in the case that this is a web app as the container controlls the port + // 2. correct the host name in the case that it's localhost + String componentServiceUrlString = wsBinding.getURI(); + URL componentServiceUrl; + + try { + componentServiceUrl = new URL(componentServiceUrlString); + } catch (MalformedURLException ex) { + throw new IllegalStateException("Unable to conver url " + + componentServiceUrlString + + " as generated by the web service binding into a URL"); + } + + String originalHost = componentServiceUrl.getHost(); + String newHost = originalHost; + int originalPort = componentServiceUrl.getPort(); + int newPort = originalPort; + + // TODO - could do with a change to the ServletHost API so that we can just ask the servlet + // host if it is controlling the URL + if (servletHost.getClass().getName().equals("WebbAppServletHost")){ + // the service URL will likely be completely different to that + // calculated by the ws binding so replace it with the node url + // The node url will have been set via init parameters in the web app + URL nodeUrl = node.getNodeURL(); + + if (nodeUrl != null){ + newHost = nodeUrl.getHost(); + newPort = nodeUrl.getPort(); + } else { + throw new IllegalStateException("Node running inside a webapp and node was not created with a valid node url"); + } + } + + // no good registering localhost as a host name when nodes are spread across + // machines + if ( newHost.equals("localhost")){ + try { + newHost = InetAddress.getLocalHost().getHostName(); + } catch(UnknownHostException ex) { + throw new IllegalStateException("Got unknown host while trying to get the local host name in order to regsiter service with the domain"); + } + } + + // replace the old with the new + componentServiceUrlString = componentServiceUrlString.replace(String.valueOf(originalPort), String.valueOf(newPort)); + componentServiceUrlString = componentServiceUrlString.replace(originalHost, newHost); + + try { + domainService.registerServiceEndpoint(node.getDomainURI(), + node.getNodeURI(), + componentServiceName, + SCABinding.class.getName(), + componentServiceUrlString); + } catch(Exception ex) { + logger.log(Level.WARNING, + "Unable to register service: " + + node.getDomainURI() + " " + + node.getNodeURI() + " " + + componentServiceName + " " + + SCABinding.class.getName() + " " + + componentServiceUrlString); + } + } else { + /* don't think we should thrown an exception here as it + * may be a stand alone node + throw new IllegalStateException("No service manager available for component: "+ + component.getName() + + " and service: " + + service.getName()); + */ + } + } else { + throw new IllegalStateException("No distributed domain available for component: "+ + component.getName() + + " and service: " + + service.getName()); + } + + } + + 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() { + axisProvider.stop(); + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/main/java/org/apache/tuscany/sca/binding/sca/axis2/impl/Axis2SCAServiceProvider.java b/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/main/java/org/apache/tuscany/sca/binding/sca/axis2/impl/Axis2SCAServiceProvider.java new file mode 100644 index 0000000000..fd7b2cdb29 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/main/java/org/apache/tuscany/sca/binding/sca/axis2/impl/Axis2SCAServiceProvider.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.sca.axis2.impl; + +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.host.http.ServletHost; +import org.apache.tuscany.sca.invocation.MessageFactory; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + +/** + * 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) { + + super(component, + service, + wsBinding, + servletHost, + messageFactory); + + 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/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/AsynchTestCase.java b/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/AsynchTestCase.java new file mode 100644 index 0000000000..df21513e51 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/AsynchTestCase.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.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 extends BaseTest { + + public static TestDomain domainA; + public static TestDomain domainB; + + @BeforeClass + public static void init() throws Exception { + System.out.println("Setting up distributed nodes"); + + try { + // create and start domains + domainA = createDomain("nodeG"); + domainB = createDomain("nodeH"); + + } 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 { + domainA.stop(); + domainB.stop(); + } + + @Test + public void testHelloWorldAsynch() throws Exception { + HelloWorldClient helloWorldClientB; + helloWorldClientB = domainA.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/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/BaseTest.java b/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/BaseTest.java new file mode 100644 index 0000000000..d5fac40e3f --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/BaseTest.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; + + +public class BaseTest { + + public static String DEFULT_DOMAIN_NAME = "mydomain"; + public static TestServiceDiscoveryImpl serviceDiscovery = new TestServiceDiscoveryImpl(); + + public static TestDomain createDomain(String nodeName) throws Exception { + + return new TestDomain(DEFULT_DOMAIN_NAME, nodeName,serviceDiscovery); + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/CallbackTestCase.java b/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/CallbackTestCase.java new file mode 100644 index 0000000000..e48a451f21 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/CallbackTestCase.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.sca.axis2; + +import java.net.URL; + +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 extends BaseTest { + + public static TestDomain domainA; + public static TestDomain domainB; + + @BeforeClass + public static void init() throws Exception { + System.out.println("Setting up distributed nodes"); + + try { + // create and start domains + domainA = createDomain("nodeE"); + domainB = createDomain("nodeF"); + + } 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 { + domainA.stop(); + domainB.stop(); + } + + //@Test + public void testHelloWorldCallbackLocal() throws Exception { + HelloWorldClient helloWorldClientB; + helloWorldClientB = domainB.getService(HelloWorldClient.class, "BHelloWorldClientCallbackLocal"); + Assert.assertEquals("Hello callback fred", helloWorldClientB.getGreetings("fred")); + } + + @Test + public void testHelloWorldCallbackRemote() throws Exception { + HelloWorldClient helloWorldClientA; + helloWorldClientA = domainA.getService(HelloWorldClient.class, "AHelloWorldClientCallbackRemote"); + Assert.assertEquals("Hello callback fred", helloWorldClientA.getGreetings("fred")); + + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/NodeFactoryImpl.java b/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/NodeFactoryImpl.java new file mode 100644 index 0000000000..c2b1e5906c --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/NodeFactoryImpl.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.sca.axis2; + +import org.apache.tuscany.sca.node.NodeFactory; +import org.apache.tuscany.sca.node.SCANode; + +/** + * A factory that always returns the same domain object + * + * @version $Rev: 556897 $ $Date: 2007-09-15 12:27:27 +0100 (Sat, 15 Sep 2007) $ + */ +public class NodeFactoryImpl implements NodeFactory { + + SCANode node = null; + + public NodeFactoryImpl(SCANode node){ + this.node = node; + } + + /** + * Returns the domain object + * + * @return the domain + */ + public SCANode getNode(){ + return node; + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/PromotionTestCase.java b/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/PromotionTestCase.java new file mode 100644 index 0000000000..8d59575f0e --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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 java.net.URL; + +import junit.framework.Assert; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +public class PromotionTestCase extends BaseTest { + + public static TestDomain domainA; + public static TestDomain domainB; + + @BeforeClass + public static void init() throws Exception { + System.out.println("Setting up distributed nodes"); + + try { + // create and start domains + domainA = createDomain("nodeC"); + domainB = createDomain("nodeD"); + + + } 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 { + domainA.stop(); + domainB.stop(); + } + + @Test + public void testHelloWorldPromotion() throws Exception { +/* + HelloWorldClient helloWorldClientA; + helloWorldClientA = domainA.getService(HelloWorldClient.class, "AHelloWorldClientRemotePromotion"); + Assert.assertEquals(helloWorldClientA.getGreetings("fred"), "Hello fred"); +*/ + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/SimpleTestCase.java b/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/SimpleTestCase.java new file mode 100644 index 0000000000..fdcc3c30ea --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/SimpleTestCase.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.sca.axis2; + +import java.net.URL; + +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 SimpleTestCase extends BaseTest { + + public static TestDomain domainA; + public static TestDomain domainB; + + @BeforeClass + public static void init() throws Exception { + System.out.println("Setting up distributed nodes"); + + try { + // create and start domains + domainA = createDomain("nodeA"); + domainB = createDomain("nodeB");; + + } 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 { + domainA.stop(); + domainB.stop(); + } + + @Test + public void testHelloWorldLocal() throws Exception { + HelloWorldClient helloWorldClientA = domainA.getService(HelloWorldClient.class, "AHelloWorldClientLocal"); + Assert.assertEquals(helloWorldClientA.getGreetings("fred"), "Hello fred"); + + } + + @Test + public void testHelloWorldRemote() throws Exception { + HelloWorldClient helloWorldClientA; + helloWorldClientA = domainA.getService(HelloWorldClient.class, "AHelloWorldClientRemote"); + Assert.assertEquals(helloWorldClientA.getGreetings("fred"), "Hello fred"); + + } + + @Test + public void testHelloWorldLocalAndRemote() throws Exception { + HelloWorldClient helloWorldClientA = domainA.getService(HelloWorldClient.class, "AHelloWorldClientLocalAndRemote"); + HelloWorldClient helloWorldClientB = domainB.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 = domainA.getService(HelloWorldClient.class, "AHelloWorldClientMultipleServices"); + HelloWorldClient helloWorldClientA2 = domainA.getService(HelloWorldClient.class, "AHelloWorldClientMultipleServices2"); + HelloWorldClient helloWorldClientB = domainB.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 = domainA.getService(HelloWorldClient.class, "AHelloWorldClientMultipleBindings"); + Assert.assertEquals(helloWorldClientA.getGreetings("fred"), "Hello fred"); + + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/TestDomain.java b/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/TestDomain.java new file mode 100644 index 0000000000..358c8cbe22 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/TestDomain.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.binding.sca.axis2; + +import java.net.URL; + +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.assembly.ActivationException; +import org.apache.tuscany.sca.core.context.ServiceReferenceImpl; +import org.apache.tuscany.sca.domain.SCADomainService; +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.node.ComponentManager; +import org.apache.tuscany.sca.node.ContributionManager; +import org.apache.tuscany.sca.node.SCANode; +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.CallableReference; +import org.osoa.sca.ServiceReference; +import org.osoa.sca.ServiceRuntimeException; + +/** + * The very minimum domain implementation to get these tests going without creating a dependency on + * domain-impl + * + * @version $Rev: 552343 $ $Date$ + */ +public class TestDomain implements SCANode { + + private String nodeName; + private String domainURI; + private static SCADomainService serviceDiscovery; + private ReallySmallRuntime nodeRuntime; + + private ClassLoader cl = BaseTest.class.getClassLoader(); + private Composite nodeComposite = null; + + + public TestDomain(String domainURI, String nodeName, TestServiceDiscoveryImpl serviceDiscovery) + throws Exception { + this.domainURI = domainURI; + this.nodeName = nodeName; + this.serviceDiscovery = serviceDiscovery; + + 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(domainURI); + + // add the top level composite into the composite activator + nodeRuntime.getCompositeActivator().setDomainComposite(nodeComposite); + + // make the domain available to the model. + ModelFactoryExtensionPoint factories = nodeRuntime.getExtensionPointRegistry().getExtensionPoint(ModelFactoryExtensionPoint.class); + NodeFactoryImpl domainFactory = new NodeFactoryImpl(this); + factories.addFactory(domainFactory); + + // 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, //resolver, + false); + Composite composite = contribution.getDeployables().get(0); + + // Add the deployable composite to the domain + nodeComposite.getIncludes().add(composite); + nodeRuntime.getCompositeBuilder().build(composite); + nodeRuntime.getCompositeActivator().activate(composite); + nodeRuntime.getCompositeActivator().start(composite); + + } catch (Exception ex) { + System.err.println("Exception when creating domain " + ex.getMessage()); + ex.printStackTrace(System.err); + throw ex; + } + } + + public void start() + throws ActivationException { + + } + + public void stop() + throws ActivationException { + nodeRuntime.stop(); + } + + + public String getNodeURI(){ + return nodeName; + } + + public String getDomainURI(){ + return domainURI; + } + + + public URL getNodeURL(){ + return null; + } + + public URL getDomainURL(){ + return null; + } + + public SCADomainService getDomainService(){ + return serviceDiscovery; + } + + public ContributionManager getContributionManager(){ + return null; + } + + public ComponentManager getComponentManager(){ + return null; + } + + public > R cast(B target) throws IllegalArgumentException { + return null; + } + + 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$." + 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/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/TestServiceDiscoveryImpl.java b/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/TestServiceDiscoveryImpl.java new file mode 100644 index 0000000000..adb1b65284 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/TestServiceDiscoveryImpl.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.sca.axis2; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.sca.domain.SCADomainService; +import org.apache.tuscany.sca.domain.ServiceInfo; + + +/** + * Stores details of services exposed and retrieves details of remote services + * + * @version $Rev: 552343 $ $Date: 2007-07-01 18:43:40 +0100 (Sun, 01 Jul 2007) $ + */ +public class TestServiceDiscoveryImpl implements SCADomainService{ + + List serviceEndpoints = new ArrayList(); + + public class ServiceEndpoint { + private String domainUri; + private String nodeUri; + private String serviceName; + private String bindingName; + private String url; + + public ServiceEndpoint(String domainUri, String nodeUri, String serviceName, String bindingName, String URL){ + this.domainUri = domainUri; + this.nodeUri = nodeUri; + this.serviceName = serviceName; + this.bindingName = bindingName; + this.url = URL; + } + + public boolean match(String domainUri, String serviceName, String bindingName) { + // trap the case where the we are trying to map + // ComponentName/Service name with a registered ComponentName - this is OK + // ComponentName with a registered ComponentName/ServiceName - this should fail + + boolean serviceNameMatch = false; + + if (this.serviceName.equals(serviceName)) { + serviceNameMatch = true; + } else { + int s = serviceName.indexOf('/'); + if ((s != -1) && + (this.serviceName.equals(serviceName.substring(0, s)))){ + serviceNameMatch = true; + } + } + + return ((this.domainUri.equals(domainUri)) && + (serviceNameMatch) && + (this.bindingName.equals(bindingName))); + } + + public String getUrl() { + return url; + } + + @Override + public String toString (){ + return "[" + + domainUri + " " + + nodeUri + " " + + serviceName + " " + + bindingName + " " + + url + + "]"; + } + } + + /** + * Accepts information about a service endpoint and holds onto it + * + * @param domainUri the string uri for the distributed domain + * @param nodeUri the string uri for the current node + * @param serviceName the name of the service that is exposed and the provided endpoint + * @param bindingName the remote binding that is providing the endpoint + * @param url the enpoint url + */ + public String registerServiceEndpoint(String domainUri, String nodeUri, String serviceName, String bindingName, String URL){ + // if the service name ends in a "/" remove it + String modifiedServiceName = null; + if ( serviceName.endsWith("/") ) { + modifiedServiceName = serviceName.substring(0, serviceName.length() - 1); + } else { + modifiedServiceName = serviceName; + } + ServiceEndpoint serviceEndpoint = new ServiceEndpoint (domainUri, nodeUri, modifiedServiceName, bindingName, URL); + serviceEndpoints.add(serviceEndpoint); + System.err.println("Registering service: " + serviceEndpoint.toString()); + return ""; + } + + public String removeServiceEndpoint(String domainUri, String nodeUri, String serviceName, String bindingName){ + return ""; + } + /** + * Locates information about a service endpoint + * + * @param domainUri the string uri for the distributed domain + * @param serviceName the name of the service that is exposed and the provided endpoint + * @param bindingName the remote binding that we want to find an endpoint for + * @return url the endpoint url + */ + public String findServiceEndpoint(String domainUri, String serviceName, String bindingName){ + System.err.println("Finding service: [" + + domainUri + " " + + serviceName + " " + + bindingName + + "]"); + + String url = null; + + for(ServiceEndpoint serviceEndpoint : serviceEndpoints){ + if ( serviceEndpoint.match(domainUri, serviceName, bindingName)){ + url = serviceEndpoint.getUrl(); + System.err.println("Matching service url: " + url); + } + } + return url; + } + + public ServiceInfo getServiceInfo() { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/HelloWorldCallbackRemote.java b/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/HelloWorldCallbackRemote.java new file mode 100644 index 0000000000..4db846cdf2 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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 { + + public String getGreetingsCallbackRemote(String s); + +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/HelloWorldClient.java b/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/HelloWorldClient.java new file mode 100644 index 0000000000..d4d743648c --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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 { + + public String getGreetings(String s); + +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/HelloWorldServiceCallbackOnewayRemote.java b/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/HelloWorldServiceCallbackOnewayRemote.java new file mode 100644 index 0000000000..0415368c20 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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 + public void getGreetingsRemote(String s); + +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/HelloWorldServiceCallbackRemote.java b/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/HelloWorldServiceCallbackRemote.java new file mode 100644 index 0000000000..23861bdf9f --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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 { + + public String getGreetingsRemote(String s); + +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/HelloWorldServiceLocal.java b/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/HelloWorldServiceLocal.java new file mode 100644 index 0000000000..157fcc5251 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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 { + + public String getGreetingsLocal(String s); + +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/HelloWorldServiceRemote.java b/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/HelloWorldServiceRemote.java new file mode 100644 index 0000000000..46373ce90d --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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 { + + public String getGreetingsRemote(String s); + +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/HelloWorldServiceRemote2.java b/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/HelloWorldServiceRemote2.java new file mode 100644 index 0000000000..ef34c87fc0 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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 { + + public String getGreetingsRemote2(String s); + +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/impl/HelloWorldClientCallbackOnewayRemoteImpl.java b/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/impl/HelloWorldClientCallbackOnewayRemoteImpl.java new file mode 100644 index 0000000000..ed76b45f67 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/impl/HelloWorldClientCallbackOnewayRemoteImpl.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.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.apache.tuscany.sca.binding.sca.axis2.helloworld.HelloWorldServiceCallbackRemote; +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/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/impl/HelloWorldClientCallbackRemoteImpl.java b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/impl/HelloWorldClientLocalImpl.java b/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/impl/HelloWorldClientLocalImpl.java new file mode 100644 index 0000000000..0e1f07f3f2 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/impl/HelloWorldClientLocalImpl.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.HelloWorldClient; +import org.apache.tuscany.sca.binding.sca.axis2.helloworld.HelloWorldServiceLocal; +import org.apache.tuscany.sca.binding.sca.axis2.helloworld.HelloWorldServiceRemote; +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/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/impl/HelloWorldClientRemote2Impl.java b/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/impl/HelloWorldClientRemote2Impl.java new file mode 100644 index 0000000000..804d1f1910 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/impl/HelloWorldClientRemote2Impl.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.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.apache.tuscany.sca.binding.sca.axis2.helloworld.HelloWorldServiceRemote; +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/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/impl/HelloWorldClientRemoteImpl.java b/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/impl/HelloWorldClientRemoteImpl.java new file mode 100644 index 0000000000..ad83358b39 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/impl/HelloWorldClientRemoteImpl.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.HelloWorldClient; +import org.apache.tuscany.sca.binding.sca.axis2.helloworld.HelloWorldServiceLocal; +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/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/impl/HelloWorldServiceCallbackOnewayRemoteImpl.java b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/impl/HelloWorldServiceCallbackRemoteImpl.java b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/impl/HelloWorldServiceLocalImpl.java b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/impl/HelloWorldServiceMultipleServicesImpl.java b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/java/org/apache/tuscany/sca/binding/sca/axis2/helloworld/impl/HelloWorldServiceRemoteImpl.java b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/resources/nodeA/HelloWorld.composite b/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/resources/nodeA/HelloWorld.composite new file mode 100644 index 0000000000..eecadac929 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/resources/nodeA/HelloWorld.composite @@ -0,0 +1,71 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/resources/nodeA/META-INF/sca-contribution.xml b/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/resources/nodeA/META-INF/sca-contribution.xml new file mode 100644 index 0000000000..d6b9e82250 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/resources/nodeB/HelloWorld.composite b/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/resources/nodeB/HelloWorld.composite new file mode 100644 index 0000000000..c9e2d122e0 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/resources/nodeB/HelloWorld.composite @@ -0,0 +1,70 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/resources/nodeB/META-INF/sca-contribution.xml b/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/resources/nodeB/META-INF/sca-contribution.xml new file mode 100644 index 0000000000..d6b9e82250 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/resources/nodeC/HelloWorld.composite b/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/resources/nodeC/HelloWorld.composite new file mode 100644 index 0000000000..d5d7773353 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/resources/nodeC/HelloWorld.composite @@ -0,0 +1,33 @@ + + + + + + + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/resources/nodeC/HelloWorldComponent.composite b/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/resources/nodeC/HelloWorldComponent.composite new file mode 100644 index 0000000000..485e0815d2 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/resources/nodeC/HelloWorldComponent.composite @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/resources/nodeC/META-INF/sca-contribution.xml b/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/resources/nodeC/META-INF/sca-contribution.xml new file mode 100644 index 0000000000..d6b9e82250 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/resources/nodeD/HelloWorld.composite b/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/resources/nodeD/HelloWorld.composite new file mode 100644 index 0000000000..9396dfd1f2 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/resources/nodeD/HelloWorld.composite @@ -0,0 +1,32 @@ + + + + + + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/resources/nodeD/HelloWorldComponent.composite b/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/resources/nodeD/HelloWorldComponent.composite new file mode 100644 index 0000000000..bf30bdf42d --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/resources/nodeD/HelloWorldComponent.composite @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/resources/nodeD/META-INF/sca-contribution.xml b/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/resources/nodeD/META-INF/sca-contribution.xml new file mode 100644 index 0000000000..d6b9e82250 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/resources/nodeE/HelloWorld.composite b/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/resources/nodeE/HelloWorld.composite new file mode 100644 index 0000000000..67c240592d --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/resources/nodeE/HelloWorld.composite @@ -0,0 +1,31 @@ + + + + + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/resources/nodeE/META-INF/sca-contribution.xml b/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/resources/nodeE/META-INF/sca-contribution.xml new file mode 100644 index 0000000000..d6b9e82250 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/resources/nodeF/HelloWorld.composite b/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/resources/nodeF/HelloWorld.composite new file mode 100644 index 0000000000..eb0a386b2c --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/resources/nodeF/HelloWorld.composite @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/resources/nodeF/META-INF/sca-contribution.xml b/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/resources/nodeF/META-INF/sca-contribution.xml new file mode 100644 index 0000000000..d6b9e82250 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/resources/nodeG/HelloWorld.composite b/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/resources/nodeG/HelloWorld.composite new file mode 100644 index 0000000000..fadb164636 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/resources/nodeG/HelloWorld.composite @@ -0,0 +1,31 @@ + + + + + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/resources/nodeG/META-INF/sca-contribution.xml b/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/resources/nodeG/META-INF/sca-contribution.xml new file mode 100644 index 0000000000..d6b9e82250 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/resources/nodeG/META-INF/sca-contribution.xml @@ -0,0 +1,24 @@ + + + + + \ No newline at end of file diff --git a/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/resources/nodeH/HelloWorld.composite b/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/resources/nodeH/HelloWorld.composite new file mode 100644 index 0000000000..e92c9ebd8e --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/resources/nodeH/HelloWorld.composite @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/resources/nodeH/META-INF/sca-contribution.xml b/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/resources/nodeH/META-INF/sca-contribution.xml new file mode 100644 index 0000000000..d6b9e82250 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-sca-axis2/src/test/resources/nodeH/META-INF/sca-contribution.xml @@ -0,0 +1,24 @@ + + + + + \ No newline at end of file diff --git a/tags/java/sca/1.0-RC1b/modules/binding-sca-xml/DISCLAIMER b/tags/java/sca/1.0-RC1b/modules/binding-sca-xml/DISCLAIMER new file mode 100644 index 0000000000..8e5c524323 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-sca-xml/DISCLAIMER @@ -0,0 +1,8 @@ +Apache Tuscany is an effort undergoing incubation at The Apache Software +Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is +required of all newly accepted projects until a further review indicates that +the infrastructure, communications, and decision making process have stabilized +in a manner consistent with other successful ASF projects. While incubation +status is not necessarily a reflection of the completeness or stability of the +code, it does indicate that the project has yet to be fully endorsed by the ASF. + diff --git a/tags/java/sca/1.0-RC1b/modules/binding-sca-xml/LICENSE b/tags/java/sca/1.0-RC1b/modules/binding-sca-xml/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-sca-xml/NOTICE b/tags/java/sca/1.0-RC1b/modules/binding-sca-xml/NOTICE new file mode 100644 index 0000000000..94481d6cfa --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-sca-xml/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2007 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/tags/java/sca/1.0-RC1b/modules/binding-sca-xml/pom.xml b/tags/java/sca/1.0-RC1b/modules/binding-sca-xml/pom.xml new file mode 100644 index 0000000000..41a1e51f26 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-sca-xml/pom.xml @@ -0,0 +1,57 @@ + + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.0-incubating + ../pom.xml + + + tuscany-binding-sca-xml + Apache Tuscany SCA Default Binding XML Model + + + + + + org.apache.tuscany.sca + tuscany-assembly-xml + 1.0-incubating + + + + org.apache.tuscany.sca + tuscany-binding-sca + 1.0-incubating + + + + org.easymock + easymock + 2.2 + test + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/binding-sca-xml/src/main/java/org/apache/tuscany/sca/binding/sca/xml/SCABindingProcessor.java b/tags/java/sca/1.0-RC1b/modules/binding-sca-xml/src/main/java/org/apache/tuscany/sca/binding/sca/xml/SCABindingProcessor.java new file mode 100644 index 0000000000..8ca4638890 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-sca-xml/src/main/java/org/apache/tuscany/sca/binding/sca/xml/SCABindingProcessor.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.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.AssemblyFactory; +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.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; + +/** + * A processor to read the XML that describes the SCA binding. + */ + +public class SCABindingProcessor implements StAXArtifactProcessor, Constants{ + + private PolicyFactory policyFactory; + private SCABindingFactory scaBindingFactory; + private PolicyAttachPointProcessor policyProcessor; + + 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) { + this.policyFactory = modelFactories.getFactory(PolicyFactory.class); + this.scaBindingFactory = modelFactories.getFactory(SCABindingFactory.class); + policyProcessor = new PolicyAttachPointProcessor(policyFactory); + } + + //FIXME Remove this constructor + public SCABindingProcessor(AssemblyFactory assemblyFactory, + PolicyFactory policyFactory, + SCABindingFactory scaBindingFactory) { + this.policyFactory = policyFactory; + this.scaBindingFactory = scaBindingFactory; + policyProcessor = new PolicyAttachPointProcessor(policyFactory); + } + + 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(); + + // 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); + } + + // 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 { + } + + public void write(SCABinding scaBinding, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException { + + // Write + policyProcessor.writePolicyPrefixes(scaBinding, writer); + 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()); + } + + writer.writeEndElement(); + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-sca-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-sca-xml/src/test/java/org/apace/tuscany/sca/binding/sca/xml/ReadTestCase.java b/tags/java/sca/1.0-RC1b/modules/binding-sca-xml/src/test/java/org/apace/tuscany/sca/binding/sca/xml/ReadTestCase.java new file mode 100644 index 0000000000..5e8df63355 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-sca-xml/src/test/java/org/apace/tuscany/sca/binding/sca/xml/ReadTestCase.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.apace.tuscany.sca.binding.sca.xml; + +import java.io.InputStream; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLOutputFactory; +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.DefaultAssemblyFactory; +import org.apache.tuscany.sca.assembly.SCABinding; +import org.apache.tuscany.sca.assembly.SCABindingFactory; +import org.apache.tuscany.sca.assembly.builder.impl.CompositeBuilderImpl; +import org.apache.tuscany.sca.assembly.xml.ComponentTypeProcessor; +import org.apache.tuscany.sca.assembly.xml.CompositeProcessor; +import org.apache.tuscany.sca.binding.sca.impl.SCABindingFactoryImpl; +import org.apache.tuscany.sca.binding.sca.xml.SCABindingProcessor; +import org.apache.tuscany.sca.contribution.DefaultModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.impl.ContributionFactoryImpl; +import org.apache.tuscany.sca.contribution.processor.DefaultStAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; +import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; +import org.apache.tuscany.sca.interfacedef.impl.InterfaceContractMapperImpl; +import org.apache.tuscany.sca.policy.DefaultPolicyFactory; +import org.apache.tuscany.sca.policy.PolicyFactory; + +/** + * Test reading WSDL interfaces. + * + * @version $Rev$ $Date$ + */ +public class ReadTestCase extends TestCase { + + XMLInputFactory inputFactory; + DefaultStAXArtifactProcessorExtensionPoint staxProcessors; + ExtensibleStAXArtifactProcessor staxProcessor; + private AssemblyFactory assemblyFactory; + private SCABindingFactory scaBindingFactory; + private PolicyFactory policyFactory; + private InterfaceContractMapper mapper; + + @Override + public void setUp() throws Exception { + ModelFactoryExtensionPoint factories = new DefaultModelFactoryExtensionPoint(); + assemblyFactory = new DefaultAssemblyFactory(); + factories.addFactory(assemblyFactory); + scaBindingFactory = new SCABindingFactoryImpl(); + factories.addFactory(scaBindingFactory); + policyFactory = new DefaultPolicyFactory(); + factories.addFactory(policyFactory); + mapper = new InterfaceContractMapperImpl(); + inputFactory = XMLInputFactory.newInstance(); + staxProcessors = new DefaultStAXArtifactProcessorExtensionPoint(factories); + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, XMLInputFactory.newInstance(), XMLOutputFactory.newInstance()); + + SCABindingFactory scaFactory = new SCABindingFactoryImpl(); + factories.addFactory(scaFactory); + + SCABindingProcessor wsdlProcessor = new SCABindingProcessor(assemblyFactory, + policyFactory, + scaFactory); + staxProcessors.addArtifactProcessor(wsdlProcessor); + } + + @Override + public void tearDown() throws Exception { + } + + public void testReadComponentType() throws Exception { + ComponentTypeProcessor componentTypeProcessor = new ComponentTypeProcessor(assemblyFactory, policyFactory, staxProcessor); + InputStream is = getClass().getResourceAsStream("/CalculatorServiceImpl.componentType"); + XMLStreamReader reader = inputFactory.createXMLStreamReader(is); + ComponentType componentType = componentTypeProcessor.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 { + CompositeProcessor compositeProcessor = new CompositeProcessor(new ContributionFactoryImpl(), assemblyFactory, policyFactory, mapper, staxProcessor); + InputStream is = getClass().getResourceAsStream("/Calculator.composite"); + XMLStreamReader reader = inputFactory.createXMLStreamReader(is); + Composite composite = compositeProcessor.read(reader); + assertNotNull(composite); + + CompositeBuilderImpl compositeUtil = new CompositeBuilderImpl(assemblyFactory, scaBindingFactory, mapper, null, null); + compositeUtil.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); + + //new PrintUtil(System.out).print(composite); + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-sca-xml/src/test/java/org/apace/tuscany/sca/binding/sca/xml/WriteTestCase.java b/tags/java/sca/1.0-RC1b/modules/binding-sca-xml/src/test/java/org/apace/tuscany/sca/binding/sca/xml/WriteTestCase.java new file mode 100644 index 0000000000..99f5bb6799 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-sca-xml/src/test/java/org/apace/tuscany/sca/binding/sca/xml/WriteTestCase.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.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.AssemblyFactory; +import org.apache.tuscany.sca.assembly.ComponentType; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory; +import org.apache.tuscany.sca.assembly.xml.ComponentTypeProcessor; +import org.apache.tuscany.sca.assembly.xml.CompositeProcessor; +import org.apache.tuscany.sca.assembly.xml.ConstrainingTypeProcessor; +import org.apache.tuscany.sca.binding.sca.impl.SCABindingFactoryImpl; +import org.apache.tuscany.sca.binding.sca.xml.SCABindingProcessor; +import org.apache.tuscany.sca.contribution.DefaultModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.impl.ContributionFactoryImpl; +import org.apache.tuscany.sca.contribution.processor.DefaultStAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; +import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; +import org.apache.tuscany.sca.interfacedef.impl.InterfaceContractMapperImpl; +import org.apache.tuscany.sca.policy.DefaultPolicyFactory; +import org.apache.tuscany.sca.policy.PolicyFactory; + +/** + * Test reading/write WSDL interfaces. + * + * @version $Rev$ $Date$ + */ +public class WriteTestCase extends TestCase { + + XMLInputFactory inputFactory; + DefaultStAXArtifactProcessorExtensionPoint staxProcessors; + ExtensibleStAXArtifactProcessor staxProcessor; + private AssemblyFactory factory; + private PolicyFactory policyFactory; + private InterfaceContractMapper mapper; + + @Override + public void setUp() throws Exception { + ModelFactoryExtensionPoint factories = new DefaultModelFactoryExtensionPoint(); + factory = new DefaultAssemblyFactory(); + factories.addFactory(factory); + policyFactory = new DefaultPolicyFactory(); + factories.addFactory(policyFactory); + + mapper = new InterfaceContractMapperImpl(); + inputFactory = XMLInputFactory.newInstance(); + staxProcessors = new DefaultStAXArtifactProcessorExtensionPoint(factories); + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, XMLInputFactory.newInstance(), XMLOutputFactory.newInstance()); + + SCABindingFactoryImpl scaFactory = new SCABindingFactoryImpl(); + factories.addFactory(scaFactory); + + staxProcessors.addArtifactProcessor(new CompositeProcessor(new ContributionFactoryImpl(), factory, policyFactory, mapper, staxProcessor)); + staxProcessors.addArtifactProcessor(new ComponentTypeProcessor(factory, policyFactory, staxProcessor)); + staxProcessors.addArtifactProcessor(new ConstrainingTypeProcessor(factory, policyFactory, staxProcessor)); + + SCABindingProcessor scaProcessor = new SCABindingProcessor(factory, + policyFactory, + scaFactory); + staxProcessors.addArtifactProcessor(scaProcessor); + } + + @Override + public void tearDown() throws Exception { + } + + public void testReadWriteComponentType() throws Exception { + InputStream is = getClass().getResourceAsStream("/CalculatorServiceImpl.componentType"); + ComponentType componentType = staxProcessor.read(is, ComponentType.class); + assertNotNull(componentType); + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + staxProcessor.write(componentType, bos); + assertEquals("" + + "" + + "", + bos.toString()); + //System.err.println(bos.toString()); + } + + public void testReadWriteComposite() throws Exception { + InputStream is = getClass().getResourceAsStream("/Calculator.composite"); + Composite composite = staxProcessor.read(is, Composite.class); + assertNotNull(composite); + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + staxProcessor.write(composite, bos); + assertEquals( + "" + + "", + bos.toString() ); + //System.err.println(bos.toString()); + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-sca-xml/src/test/resources/Calculator.composite b/tags/java/sca/1.0-RC1b/modules/binding-sca-xml/src/test/resources/Calculator.composite new file mode 100644 index 0000000000..9028662d05 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-sca-xml/src/test/resources/Calculator.composite @@ -0,0 +1,59 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/binding-sca-xml/src/test/resources/CalculatorServiceImpl.componentType b/tags/java/sca/1.0-RC1b/modules/binding-sca-xml/src/test/resources/CalculatorServiceImpl.componentType new file mode 100644 index 0000000000..f02e7d6fc0 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-sca-xml/src/test/resources/CalculatorServiceImpl.componentType @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tags/java/sca/1.0-RC1b/modules/binding-sca/DISCLAIMER b/tags/java/sca/1.0-RC1b/modules/binding-sca/DISCLAIMER new file mode 100644 index 0000000000..d68a410903 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-sca/DISCLAIMER @@ -0,0 +1,8 @@ +Apache Tuscany is an effort undergoing incubation at The Apache Software +Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is +required of all newly accepted projects until a further review indicates that +the infrastructure, communications, and decision making process have stabilized +in a manner consistent with other successful ASF projects. While incubation +status is not necessarily a reflection of the completeness or stability of the +code, it does indicate that the project has yet to be fully endorsed by the ASF. + diff --git a/tags/java/sca/1.0-RC1b/modules/binding-sca/LICENSE b/tags/java/sca/1.0-RC1b/modules/binding-sca/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-sca/NOTICE b/tags/java/sca/1.0-RC1b/modules/binding-sca/NOTICE new file mode 100644 index 0000000000..94481d6cfa --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-sca/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2007 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/tags/java/sca/1.0-RC1b/modules/binding-sca/pom.xml b/tags/java/sca/1.0-RC1b/modules/binding-sca/pom.xml new file mode 100644 index 0000000000..1cee5c9f1b --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-sca/pom.xml @@ -0,0 +1,86 @@ + + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.0-incubating + ../pom.xml + + + tuscany-binding-sca + Apache Tuscany SCA Default Binding Model + + + + + org.apache.tuscany.sca + tuscany-assembly + 1.0-incubating + + + + org.apache.tuscany.sca + tuscany-assembly-xml + 1.0-incubating + + + + org.apache.tuscany.sca + tuscany-core-spi + 1.0-incubating + + + + org.apache.tuscany.sca + tuscany-core + 1.0-incubating + + + + org.apache.tuscany.sca + tuscany-contribution-impl + 1.0-incubating + + + + org.apache.tuscany.sca + tuscany-node + 1.0-incubating + + + + org.apache.tuscany.sca + tuscany-domain + 1.0-incubating + + + + org.easymock + easymock + 2.2 + test + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/DistributedSCABinding.java b/tags/java/sca/1.0-RC1b/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/DistributedSCABinding.java new file mode 100644 index 0000000000..be89a30193 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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 { + + public SCABinding getSCABinding(); + public void setSCABinging(SCABinding scaBinding); + +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/DistributedSCABindingImpl.java b/tags/java/sca/1.0-RC1b/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/DistributedSCABindingImpl.java new file mode 100644 index 0000000000..e12fd82f97 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/DistributedSCABindingImpl.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.impl; + +import java.util.List; + +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 the sca binding model element + */ + public void setSCABinging(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){ + } + + +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/RuntimeSCABindingProvider.java b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/RuntimeSCABindingProviderFactory.java b/tags/java/sca/1.0-RC1b/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/RuntimeSCABindingProviderFactory.java new file mode 100644 index 0000000000..1ea8354695 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/RuntimeSCABindingProviderFactory.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.assembly.SCABinding; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.node.NodeFactory; +import org.apache.tuscany.sca.node.SCANode; +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; + private SCANode node = null; + + public RuntimeSCABindingProviderFactory(ExtensionPointRegistry extensionPoints) { + this.extensionPoints = extensionPoints; + ModelFactoryExtensionPoint factories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class); + NodeFactory domainFactory = factories.getFactory(NodeFactory.class); + + if (domainFactory != null) { + node = domainFactory.getNode(); + } + + } + + public ReferenceBindingProvider createReferenceBindingProvider(RuntimeComponent component, + RuntimeComponentReference reference, + SCABinding binding) { + + return new RuntimeSCAReferenceBindingProvider(extensionPoints, node, component, reference, binding); + } + + public ServiceBindingProvider createServiceBindingProvider(RuntimeComponent component, + RuntimeComponentService service, + SCABinding binding) { + return new RuntimeSCAServiceBindingProvider(extensionPoints, node, component, service, binding); + } + + public Class getModelType() { + return SCABinding.class; + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/RuntimeSCAReferenceBindingProvider.java b/tags/java/sca/1.0-RC1b/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/RuntimeSCAReferenceBindingProvider.java new file mode 100644 index 0000000000..d86cdd4c7c --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/RuntimeSCAReferenceBindingProvider.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.impl; + +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.domain.SCADomainService; +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.node.SCANode; +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 SCANode node; + 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, + SCANode domain, + RuntimeComponent component, + RuntimeComponentReference reference, + SCABinding binding) { + this.node = domain; + 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); + + + // determine if the target is remote. If we can tell now then this will + // do some initialization before we get to run time + isTargetRemote(); + } + + public boolean isTargetRemote() { + boolean targetIsRemote = false; + + // first look at the target service and see if this has been resolved + if (((OptimizableBinding)binding).getTargetComponentService() != null) { + if (((OptimizableBinding)binding).getTargetComponentService().isUnresolved() == true) { + targetIsRemote = true; + } else { + targetIsRemote = false; + } + } else { + // if no target is found then this could be a completely dynamic + // reference, e.g. a callback, so check the domain to see if the service is available + // at this node. The binding uri might be null here if the dynamic reference has been + // fully configured yet. It won't have all of the information until invocation time + if ((node != null) && (binding.getURI() != null)) { + SCADomainService serviceDiscovery = node.getDomainService(); + + String serviceUrl = + serviceDiscovery.findServiceEndpoint(node.getDomainURI(), + binding.getURI(), + SCABinding.class.getName()); + if ((serviceUrl == null) || serviceUrl.equals("")) { + targetIsRemote = false; + } else { + targetIsRemote = true; + } + + } + } + + // if we think the target is remote check that everything is configured correctly + if (targetIsRemote) { + // initialize the remote provider if it hasn't been done already + if (distributedProvider == null) { + if (!reference.getInterfaceContract().getInterface().isRemotable()) { + throw new IllegalStateException("Reference interface not remoteable 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()); + } + + if (node == null) { + throw new IllegalStateException("No distributed domain available for component: " + component + .getName() + + " and reference: " + + reference.getName()); + } + + // create the remote provider + DistributedSCABinding distributedBinding = new DistributedSCABindingImpl(); + distributedBinding.setSCABinging(binding); + + distributedProvider = distributedProviderFactory + .createReferenceBindingProvider(component, reference, distributedBinding); + } + } + + return targetIsRemote; + } + + public InterfaceContract getBindingInterfaceContract() { + if (isTargetRemote()) { + return distributedProvider.getBindingInterfaceContract(); + } else { + return reference.getInterfaceContract(); + } + } + + public boolean supportsOneWayInvocation() { + if (isTargetRemote()) { + return distributedProvider.supportsOneWayInvocation(); + } else { + return false; + } + } + + /** + * @param wire + */ + 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); + return service.getInvoker(scaBinding, wire.getSource().getInterfaceContract(), operation); + } + } + return null; + } + + public Invoker createInvoker(Operation operation) { + if (isTargetRemote()) { + return distributedProvider.createInvoker(operation); + } else { + RuntimeWire wire = reference.getRuntimeWire(binding); + Invoker invoker = getInvoker(wire, operation); + if (invoker == null) { + throw new ServiceUnavailableException("No service invoker is available for reference " + reference + .getName() + + " (bindingURI=" + + binding.getURI() + + " operation=" + + operation.getName() + + ")."); + } + return invoker; + } + } + + public void start() { + if (started) { + return; + } else { + started = true; + } + + // ComponentService service = ((WireableBinding)binding).getTargetComponentService(); + // if (service != null) { + // RuntimeWire wire = reference.getRuntimeWire(binding); + // InterfaceContract interfaceContract = service.getInterfaceContract(); + // boolean dynamicService = interfaceContract.getInterface().isDynamic(); + // if (!dynamicService) { + // wire.getTarget().setInterfaceContract(interfaceContract); + // } + // } + + if (distributedProvider != null) { + distributedProvider.start(); + } + } + + public void stop() { + if (distributedProvider != null) { + distributedProvider.stop(); + } + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/RuntimeSCAServiceBindingProvider.java b/tags/java/sca/1.0-RC1b/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/RuntimeSCAServiceBindingProvider.java new file mode 100644 index 0000000000..8c74147de4 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/RuntimeSCAServiceBindingProvider.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.sca.impl; + +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.Invoker; +import org.apache.tuscany.sca.node.SCANode; +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 SCANode node; + private RuntimeComponentService service; + private BindingProviderFactory distributedProviderFactory; + private ServiceBindingProvider distributedProvider; + private DistributedSCABinding distributedBinding; + + public RuntimeSCAServiceBindingProvider(ExtensionPointRegistry extensionPoints, + SCANode node, + RuntimeComponent component, + RuntimeComponentService service, + SCABinding binding) { + this.node = node; + 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 + // - distributed domain in which to look for remote endpoints + // - remotable interface on the service + if (distributedProviderFactory != null) { + if (this.node != null) { + if (!service.getInterfaceContract().getInterface().isRemotable()) { + throw new IllegalStateException("Reference interface not remoteable for component: "+ + component.getName() + + " and service: " + + service.getName()); + } + + // create a nested provider to handle the remote case + distributedBinding = new DistributedSCABindingImpl(); + distributedBinding.setSCABinging(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 { + return service.getInterfaceContract(); + } + } + + public boolean supportsOneWayInvocation() { + return false; + } + + public void start() { + if (distributedProvider != null) { + distributedProvider.start(); + } + } + + public void stop() { + if (distributedProvider != null) { + distributedProvider.stop(); + } + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/SCABindingFactoryImpl.java b/tags/java/sca/1.0-RC1b/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/SCABindingFactoryImpl.java new file mode 100644 index 0000000000..666c264e2e --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/SCABindingFactoryImpl.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.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 SCABinding createSCABinding() { + return new SCABindingImpl(); + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/SCABindingImpl.java b/tags/java/sca/1.0-RC1b/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/SCABindingImpl.java new file mode 100644 index 0000000000..8c5ec98dbf --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/SCABindingImpl.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.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.SCABinding; +import org.apache.tuscany.sca.assembly.OptimizableBinding; +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; + +/** + * he assemly mode object for an SCA binding. + * + * @version $Rev$ $Date$ + */ +public class SCABindingImpl implements SCABinding, Extensible, PolicySetAttachPoint, OptimizableBinding { + private String name; + private String uri; + private List extensions = new ArrayList(); + private List requiredIntents = new ArrayList(); + private List policySets = new ArrayList(); + private IntentAttachPointType intentAttachPointType; + + private Component targetComponent; + private ComponentService targetComponentService; + private Binding targetBinding; + + /** + * 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 biniding 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 targetting 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 + * + * @para uri the binding uri + */ + public void setURI(String uri) { + this.uri = uri; + } + + /** + * Returns a list of extension objects contained in this model object. + * + * @return a list of extension objects container in this model object + */ + public List getExtensions() { + return extensions; + } + + /** + * 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) { + } + + /** + * @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; + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-sca/src/main/resources/META-INF/services/org.apache.tuscany.sca.assembly.SCABindingFactory b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-sca/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-sca/src/test/java/org/apace/tuscany/sca/binding/sca/SCABindingTestCase.java b/tags/java/sca/1.0-RC1b/modules/binding-sca/src/test/java/org/apace/tuscany/sca/binding/sca/SCABindingTestCase.java new file mode 100644 index 0000000000..af2b11898b --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-sca/src/test/java/org/apace/tuscany/sca/binding/sca/SCABindingTestCase.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.apace.tuscany.sca.binding.sca; + +import java.io.InputStream; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLOutputFactory; +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.DefaultAssemblyFactory; +import org.apache.tuscany.sca.assembly.SCABinding; +import org.apache.tuscany.sca.assembly.SCABindingFactory; +import org.apache.tuscany.sca.assembly.builder.impl.CompositeBuilderImpl; +import org.apache.tuscany.sca.assembly.xml.CompositeModelResolver; +import org.apache.tuscany.sca.assembly.xml.CompositeProcessor; +import org.apache.tuscany.sca.binding.sca.impl.SCABindingFactoryImpl; +import org.apache.tuscany.sca.contribution.DefaultModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.impl.ContributionFactoryImpl; +import org.apache.tuscany.sca.contribution.processor.DefaultStAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; +import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; +import org.apache.tuscany.sca.interfacedef.impl.InterfaceContractMapperImpl; +import org.apache.tuscany.sca.policy.DefaultPolicyFactory; +import org.apache.tuscany.sca.policy.PolicyFactory; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +public class SCABindingTestCase { + + private XMLInputFactory inputFactory; + private DefaultStAXArtifactProcessorExtensionPoint staxProcessors; + private ExtensibleStAXArtifactProcessor staxProcessor; + private CompositeModelResolver resolver; + private AssemblyFactory assemblyFactory; + private SCABindingFactory scaBindingFactory; + private PolicyFactory policyFactory; + private InterfaceContractMapper mapper; + + @Before + public void init() throws Exception { + inputFactory = XMLInputFactory.newInstance(); + staxProcessors = new DefaultStAXArtifactProcessorExtensionPoint(new DefaultModelFactoryExtensionPoint()); + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, XMLInputFactory.newInstance(), XMLOutputFactory.newInstance()); + resolver = new CompositeModelResolver(null, null); + assemblyFactory = new DefaultAssemblyFactory(); + scaBindingFactory = new SCABindingFactoryImpl(); + policyFactory = new DefaultPolicyFactory(); + mapper = new InterfaceContractMapperImpl(); + } + + @After + public void destroy() throws Exception { + inputFactory = null; + staxProcessors = null; + resolver = null; + policyFactory = null; + assemblyFactory = null; + 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"); + CompositeProcessor compositeReader = new CompositeProcessor(new ContributionFactoryImpl(), assemblyFactory, policyFactory, mapper, staxProcessor); + XMLStreamReader reader = inputFactory.createXMLStreamReader(is); + Composite composite = compositeReader.read(reader); + + is.close(); + Assert.assertNotNull(composite); + + resolver.addModel(composite); + + compositeReader.resolve(composite, resolver); + + CompositeBuilderImpl compositeBuilder = new CompositeBuilderImpl(assemblyFactory, scaBindingFactory, mapper, null, null); + 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/tags/java/sca/1.0-RC1b/modules/binding-sca/src/test/resources/Calculator.composite b/tags/java/sca/1.0-RC1b/modules/binding-sca/src/test/resources/Calculator.composite new file mode 100644 index 0000000000..ec72c777ef --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-sca/src/test/resources/Calculator.composite @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/DISCLAIMER b/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/DISCLAIMER new file mode 100644 index 0000000000..d68a410903 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/DISCLAIMER @@ -0,0 +1,8 @@ +Apache Tuscany is an effort undergoing incubation at The Apache Software +Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is +required of all newly accepted projects until a further review indicates that +the infrastructure, communications, and decision making process have stabilized +in a manner consistent with other successful ASF projects. While incubation +status is not necessarily a reflection of the completeness or stability of the +code, it does indicate that the project has yet to be fully endorsed by the ASF. + diff --git a/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/LICENSE b/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/NOTICE b/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/NOTICE new file mode 100644 index 0000000000..94481d6cfa --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2007 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/pom.xml b/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/pom.xml new file mode 100755 index 0000000000..8ae6466f44 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/pom.xml @@ -0,0 +1,297 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.0-incubating + ../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.0-incubating + + + + org.apache.tuscany.sca + tuscany-interface-wsdl-xml + 1.0-incubating + + + + org.apache.tuscany.sca + tuscany-assembly-xml + 1.0-incubating + + + + org.apache.tuscany.sca + tuscany-binding-ws-xml + 1.0-incubating + + + + org.apache.tuscany.sca + tuscany-core-databinding + 1.0-incubating + + + + org.apache.tuscany.sca + tuscany-databinding-axiom + 1.0-incubating + + + + org.apache.tuscany.sca + tuscany-host-http + 1.0-incubating + + + + org.apache.tuscany.sca + tuscany-policy-security + 1.0-incubating + + + + org.apache.axis2 + axis2-kernel + 1.3 + + + org.apache.ant + ant + + + + + + org.apache.axis2 + axis2-java2wsdl + 1.3 + + + + org.apache.axis2 + axis2-adb + 1.3 + runtime + + + + org.apache.axis2 + axis2-codegen + 1.3 + runtime + + + + org.apache.ws.commons.axiom + axiom-api + 1.2.5 + + + + org.apache.ws.commons.axiom + axiom-impl + 1.2.5 + + + + org.apache.woden + woden + 1.0-incubating-M7b + runtime + + + + commons-logging + commons-logging + 1.1 + + + javax.servlet + servlet-api + + + + + + javax.servlet + servlet-api + 2.4 + provided + + + + + org.apache.neethi + neethi + 2.0.2 + + + + org.apache.ws.commons.schema + XmlSchema + 1.3.2 + + + + commons-httpclient + commons-httpclient + 3.0.1 + + + + javax.mail + mail + 1.4 + + + + backport-util-concurrent + backport-util-concurrent + 2.2 + runtime + + + + commons-codec + commons-codec + 1.3 + runtime + + + + org.apache.tuscany.sca + tuscany-host-jetty + 1.0-incubating + test + + + + org.apache.tuscany.sca + tuscany-host-embedded + 1.0-incubating + + + + org.apache.tuscany.sca + tuscany-implementation-java-runtime + 1.0-incubating + test + + + + org.apache.axis2 + axis2-mtompolicy + 1.3 + + + + org.apache.santuario + xmlsec + 1.4.0 + + + + xalan + xalan + 2.7.0 + + + + org.apache.ws.security + wss4j + 1.5.3 + + + + xml-apis + xml-apis + 1.3.03 + + + + org.apache.rampart + rampart-core + 1.3 + + + + org.apache.rampart + rampart-policy + 1.3 + + + + org.apache.rampart + rampart-trust + 1.3 + + + + org.apache.rampart + rampart + 1.3 + mar + runtime + + + javax.servlet + servlet-api + + + org.apache.ant + ant-nodeps + + + org.apache.axis2 + axis2-xmlbeans + + + xmlbeans + xbean + + + bouncycastle + bcprov-jdk15 + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2BindingInvoker.java b/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2BindingInvoker.java new file mode 100644 index 0000000000..5a58ba383b --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2BindingInvoker.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.binding.ws.axis2; + +import java.lang.reflect.InvocationTargetException; + +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.client.ServiceClient; +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.interfacedef.util.FaultException; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.runtime.ReferenceParameters; + +/** + * Axis2BindingInvoker uses an Axis2 OperationClient to invoke a remote web service + */ +public class Axis2BindingInvoker implements Invoker { + + private ServiceClient serviceClient; + private QName wsdlOperationName; + private Options options; + private SOAPFactory soapFactory; + + public static final QName QNAME_WSA_FROM = + new QName(AddressingConstants.Final.WSA_NAMESPACE, AddressingConstants.WSA_FROM); + public static final QName QNAME_WSA_TO = + new QName(AddressingConstants.Final.WSA_NAMESPACE, AddressingConstants.WSA_TO); + + public static final QName CALLBACK_REFERENCE_REFPARM_QN = new QName(Constants.SCA10_TUSCANY_NS, "CallbackReference"); + public static final QName CALLBACK_ID_REFPARM_QN = new QName(Constants.SCA10_TUSCANY_NS, "CallbackID"); + public static final QName CONVERSATION_ID_REFPARM_QN = new QName(Constants.SCA10_TUSCANY_NS, "ConversationID"); + + public Axis2BindingInvoker(ServiceClient serviceClient, + QName wsdlOperationName, + Options options, + SOAPFactory soapFactory) { + this.serviceClient = serviceClient; + this.wsdlOperationName = wsdlOperationName; + this.options = options; + this.soapFactory = soapFactory; + } + + 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()); + f.setLogical(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 { + 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(120000L); + + operationClient.execute(true); + + MessageContext responseMC = operationClient.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE); + + OMElement response = responseMC.getEnvelope().getBody().getFirstElement(); + + // FIXME: [rfeng] We have to pay performance penality 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 + 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 betweem OMElements and other types."); + } + } + } + MessageContext requestMC = new MessageContext(); + requestMC.setEnvelope(env); + + // Axis2 operationClients can not be shared so create a new one for each request + OperationClient operationClient = serviceClient.createClient(wsdlOperationName); + operationClient.setOptions(options); + + ReferenceParameters parameters = msg.getTo().getReferenceParameters(); + + // if target endpoint was not specified when this invoker was created, + // use dynamically specified target endpoint passed in on this call + EndpointReference toEPR = options.getTo(); + if (toEPR == null) { + org.apache.tuscany.sca.runtime.EndpointReference ep = msg.getTo(); + toEPR = new EndpointReference(ep.getURI()); + } + + // set callback endpoint and callback ID for WS-Addressing header + if (parameters.getCallbackReference() != null) { + toEPR.addReferenceParameter(CALLBACK_REFERENCE_REFPARM_QN, + parameters.getCallbackReference().getBinding().getURI()); + } + if (parameters.getCallbackID() != null) { + //FIXME: serialize callback ID to XML in case it is not a string + toEPR.addReferenceParameter(CALLBACK_ID_REFPARM_QN, parameters.getCallbackID().toString()); + } + + // set conversation ID for WS-Addressing header + //FIXME: get conversation ID from the message's callable reference + Object conversationId = parameters.getConversationID(); + if (conversationId != null) { + //FIXME: serialize conversation ID to XML in case it is not a string + toEPR.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 (toEPR != null) { + SOAPEnvelope sev = requestMC.getEnvelope(); + SOAPHeader sh = sev.getHeader(); + OMElement epr = + EndpointReferenceHelper.toOM(sev.getOMFactory(), + toEPR, + QNAME_WSA_TO, + AddressingConstants.Final.WSA_NAMESPACE); + sh.addChild(epr); + requestMC.setTo(toEPR); + } + + operationClient.addMessageContext(requestMC); + + return operationClient; + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2BindingProviderFactory.java b/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2BindingProviderFactory.java new file mode 100644 index 0000000000..610c376bc9 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2BindingProviderFactory.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.binding.ws.axis2; + +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.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; + +/** + * Axis2BindingProviderFactory + * + * @version $Rev$ $Date$ + */ + +public class Axis2BindingProviderFactory implements BindingProviderFactory { + + private MessageFactory messageFactory; + private ServletHost servletHost; + + public Axis2BindingProviderFactory(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); + } + + public ReferenceBindingProvider createReferenceBindingProvider(RuntimeComponent component, RuntimeComponentReference reference, WebServiceBinding binding) { + return new Axis2ReferenceBindingProvider(component, reference, binding, servletHost, messageFactory); + } + + public ServiceBindingProvider createServiceBindingProvider(RuntimeComponent component, RuntimeComponentService service, WebServiceBinding binding) { + return new Axis2ServiceBindingProvider(component, service, binding, servletHost, messageFactory); + } + + public Class getModelType() { + return WebServiceBinding.class; + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2OneWayBindingInvoker.java b/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2OneWayBindingInvoker.java new file mode 100644 index 0000000000..b33a9a9dfc --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2OneWayBindingInvoker.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; + +import java.lang.reflect.InvocationTargetException; + +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.client.ServiceClient; +import org.apache.axis2.context.MessageContext; +import org.apache.axis2.transport.http.HTTPConstants; +import org.apache.axis2.wsdl.WSDLConstants; +import org.apache.tuscany.sca.invocation.Message; + +public class Axis2OneWayBindingInvoker extends Axis2BindingInvoker { + + public Axis2OneWayBindingInvoker(ServiceClient serviceClient, + QName wsdlOperationName, + Options options, + SOAPFactory soapFactory) { + + super(serviceClient, wsdlOperationName, options, soapFactory); + } + + @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); + + operationClient.execute(false); + + // REVIEW it seems ok to return null + return null; + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ReferenceBindingProvider.java b/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ReferenceBindingProvider.java new file mode 100644 index 0000000000..dba9c5b3de --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ReferenceBindingProvider.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.ws.axis2; + +import org.apache.axiom.om.OMElement; +import org.apache.tuscany.sca.binding.ws.WebServiceBinding; +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.interfacedef.java.JavaInterfaceContract; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.MessageFactory; +import org.apache.tuscany.sca.provider.ReferenceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; + +public class Axis2ReferenceBindingProvider implements ReferenceBindingProvider { + + private WebServiceBinding wsBinding; + private Axis2ServiceClient axisClient; + + public Axis2ReferenceBindingProvider(RuntimeComponent component, + RuntimeComponentReference reference, + WebServiceBinding wsBinding, + ServletHost servletHost, + MessageFactory messageFactory) { + + this.wsBinding = wsBinding; + + InterfaceContract contract = wsBinding.getBindingInterfaceContract(); + if (contract == null) { + contract = reference.getInterfaceContract().makeUnidirectional(false); + if ((contract instanceof JavaInterfaceContract)) { + contract = Java2WSDLHelper.createWSDLInterfaceContract((JavaInterfaceContract)contract, wsBinding); + } + wsBinding.setBindingInterfaceContract(contract); + } + + // Set to use the Axiom data binding + contract.getInterface().setDefaultDataBinding(OMElement.class.getName()); + + axisClient = new Axis2ServiceClient(component, reference, wsBinding, servletHost, messageFactory); + } + + 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/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceBindingProvider.java b/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceBindingProvider.java new file mode 100644 index 0000000000..4133a11cbd --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceBindingProvider.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; + +import org.apache.axiom.om.OMElement; +import org.apache.tuscany.sca.binding.ws.WebServiceBinding; +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.interfacedef.java.JavaInterfaceContract; +import org.apache.tuscany.sca.invocation.Invoker; +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; + +public class Axis2ServiceBindingProvider implements ServiceBindingProvider { + + private WebServiceBinding wsBinding; + private Axis2ServiceProvider axisProvider; + + public Axis2ServiceBindingProvider(RuntimeComponent component, + RuntimeComponentService service, + WebServiceBinding wsBinding, + ServletHost servletHost, + MessageFactory messageFactory) { + + this.wsBinding = wsBinding; + + InterfaceContract contract = wsBinding.getBindingInterfaceContract(); + if (contract == null) { + contract = service.getInterfaceContract().makeUnidirectional(false); + if ((contract instanceof JavaInterfaceContract)) { + contract = Java2WSDLHelper.createWSDLInterfaceContract((JavaInterfaceContract)contract, wsBinding); + } + wsBinding.setBindingInterfaceContract(contract); + } + + // Set to use the Axiom data binding + contract.getInterface().setDefaultDataBinding(OMElement.class.getName()); + + axisProvider = new Axis2ServiceProvider(component, service, wsBinding, servletHost, messageFactory); + } + + public void start() { + axisProvider.start(); + } + + public void stop() { + axisProvider.stop(); + } + + public InterfaceContract getBindingInterfaceContract() { + return wsBinding.getBindingInterfaceContract(); + } + + public boolean supportsOneWayInvocation() { + return true; + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceClient.java b/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceClient.java new file mode 100644 index 0000000000..5eae51990c --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceClient.java @@ -0,0 +1,281 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, 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.util.List; + +import javax.wsdl.Binding; +import javax.wsdl.BindingOperation; +import javax.wsdl.Definition; +import javax.wsdl.Port; +import javax.wsdl.Service; +import javax.wsdl.extensions.soap.SOAPAddress; +import javax.wsdl.extensions.soap.SOAPOperation; +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.AxisService; +import org.apache.axis2.description.Parameter; +import org.apache.axis2.transport.http.HTTPConstants; +import org.apache.commons.httpclient.HttpClient; +import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager; +import org.apache.tuscany.sca.assembly.AbstractContract; +import org.apache.tuscany.sca.binding.ws.WebServiceBinding; +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.invocation.MessageFactory; +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; +import org.apache.tuscany.sca.policy.security.ws.Axis2ConfigParamPolicy; +import org.apache.tuscany.sca.runtime.RuntimeComponent; + +public class Axis2ServiceClient { + + private WebServiceBinding wsBinding; + private ServiceClient serviceClient; + private static final QName SOAP12_INTENT = new QName("http://www.osoa.org/xmlns/sca/1.0", "soap12"); + + public Axis2ServiceClient(RuntimeComponent component, + AbstractContract contract, + WebServiceBinding wsBinding, + ServletHost servletHost, + MessageFactory messageFactory) { + + this.wsBinding = wsBinding; + this.serviceClient = createServiceClient(); + } + + protected void start() { + } + + /** + * Create an Axis2 ServiceClient + */ + protected ServiceClient createServiceClient() { + try { + TuscanyAxisConfigurator tuscanyAxisConfigurator = new TuscanyAxisConfigurator(); + ConfigurationContext configContext = tuscanyAxisConfigurator.getConfigurationContext(); + + configureSecurity(configContext); + + Definition wsdlDefinition = wsBinding.getWSDLDefinition().getDefinition(); + setServiceAndPort(wsBinding); + QName serviceQName = wsBinding.getServiceName(); + String portName = wsBinding.getPortName(); + AxisService axisService = + AxisService.createClientSideAxisService(wsdlDefinition, serviceQName, portName, new Options()); + + return new ServiceClient(configContext, axisService); + } catch (AxisFault e) { + throw new RuntimeException(e); // TODO: better exception + } + } + + /** + * Ensure the WSDL definition contains a suitable service and port + */ + protected static void setServiceAndPort(WebServiceBinding wsBinding) { + Definition wsdlDefinition = wsBinding.getWSDLDefinition().getDefinition(); + QName serviceQName = wsBinding.getServiceName(); + String portName = wsBinding.getPortName(); + + // If no service is specified in the binding element, allow for WSDL that + // only contains a portType and not a service and port. Synthesize a + // service and port using WSDL4J and add them to the wsdlDefinition to + // keep Axis happy. + //FIXME: it would be better to do this for all WSDLs to explictly control the + // service and port that Axis will use, rather than just hoping the user has + // placed a suitable service and/or port first in the WSDL. + if (serviceQName == null && wsBinding.getBinding() != null) { + QName bindingQName = wsBinding.getBindingName(); + Port port = wsdlDefinition.createPort(); + portName = "$port$." + bindingQName.getLocalPart(); + port.setName(portName); + wsBinding.setPortName(portName); + port.setBinding(wsBinding.getBinding()); + Service service = wsdlDefinition.createService(); + serviceQName = new QName(bindingQName.getNamespaceURI(), + "$service$." + bindingQName.getLocalPart()); + service.setQName(serviceQName); + wsBinding.setServiceName(serviceQName); + service.addPort(port); + wsdlDefinition.addService(service); + } + } + + protected void stop() { + // 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(); + } + + /** + * 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 + + SOAPFactory soapFactory = requiresSOAP12() ? OMAbstractFactory.getSOAP12Factory() : OMAbstractFactory.getSOAP11Factory(); + QName wsdlOperationQName = new QName(operationName); + + Axis2BindingInvoker invoker; + if (operation.isNonBlocking()) { + invoker = new Axis2OneWayBindingInvoker(serviceClient, wsdlOperationQName, options, soapFactory); + } else { + invoker = new Axis2BindingInvoker(serviceClient, wsdlOperationQName, options, soapFactory); + } + return invoker; + } + + private boolean requiresSOAP12() { + if (wsBinding instanceof IntentAttachPoint) { + List intents = ((IntentAttachPoint)wsBinding).getRequiredIntents(); + for (Intent intent : intents) { + if (SOAP12_INTENT.equals(intent.getName())) { + return true; + } + } + } + return false; + } + + 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 = binding.getURI(); + if (ep == null && binding.getPort() != null) { + List wsdlPortExtensions = binding.getPort().getExtensibilityElements(); + for (final Object extension : wsdlPortExtensions) { + if (extension instanceof SOAPAddress) { + ep = ((SOAPAddress)extension).getLocationURI(); + break; + } + } + } + return ep != null ? new EndpointReference(ep) : null; + } + + 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 configureSecurity(ConfigurationContext configContext) throws AxisFault { + if ( wsBinding instanceof PolicySetAttachPoint ) { + PolicySetAttachPoint policiedBinding = (PolicySetAttachPoint)wsBinding; + Parameter configParam = null; + Axis2ConfigParamPolicy axis2ConfigParamPolicy = null; + for ( PolicySet policySet : policiedBinding.getPolicySets() ) { + for ( Object policy : policySet.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)); + configContext.getAxisConfiguration().addParameter(configParam); + } + } + } + } + } + } + + +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceInMessageReceiver.java b/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceInMessageReceiver.java new file mode 100644 index 0000000000..1684cc93dc --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceInMessageReceiver.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.ws.axis2; + +import java.lang.reflect.InvocationTargetException; + +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; + +public class Axis2ServiceInMessageReceiver extends AbstractInMessageReceiver { + + protected Operation operation; + + private Axis2ServiceProvider provider; + + public Axis2ServiceInMessageReceiver(Axis2ServiceProvider provider, Operation operation) { + this.provider = provider; + this.operation = operation; + } + + public Axis2ServiceInMessageReceiver() { + } + + @Override + public void invokeBusinessLogic(MessageContext inMC) throws AxisFault { + try { + OMElement requestOM = inMC.getEnvelope().getBody().getFirstElement(); + Object[] args = new Object[] {requestOM}; + provider.invokeTarget(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/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceInOutSyncMessageReceiver.java b/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceInOutSyncMessageReceiver.java new file mode 100644 index 0000000000..169ffde151 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceInOutSyncMessageReceiver.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.ws.axis2; + +import java.lang.reflect.InvocationTargetException; +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; + +public class Axis2ServiceInOutSyncMessageReceiver extends AbstractInOutSyncMessageReceiver { + private static final Logger logger = Logger.getLogger(Axis2ServiceInOutSyncMessageReceiver.class.getName()); + + protected Operation operation; + + private Axis2ServiceProvider provider; + + public Axis2ServiceInOutSyncMessageReceiver(Axis2ServiceProvider provider, Operation operation) { + this.provider = provider; + this.operation = operation; + } + + 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}; + } + OMElement responseOM = (OMElement)provider.invokeTarget(operation, args, inMC); + + 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(); + logger.log(Level.SEVERE, e.getMessage(), t); + 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); + } + throw new RuntimeException(e); + } catch (Throwable e) { + logger.log(Level.SEVERE, e.getMessage(), e); + throw AxisFault.makeFault(e); + } + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceProvider.java b/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceProvider.java new file mode 100644 index 0000000000..b8a8612a6c --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceProvider.java @@ -0,0 +1,532 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, 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.lang.reflect.InvocationTargetException; +import java.net.URI; +import java.net.URL; +import java.security.PrivilegedAction; +import java.util.Iterator; +import java.util.List; + +import javax.wsdl.Definition; +import javax.wsdl.Port; +import javax.wsdl.extensions.soap.SOAPAddress; +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.OMElement; +import org.apache.axiom.om.impl.builder.StAXOMBuilder; +import org.apache.axiom.soap.SOAPHeader; +import org.apache.axis2.AxisFault; +import org.apache.axis2.Constants; +import org.apache.axis2.addressing.AddressingConstants; +import org.apache.axis2.addressing.EndpointReferenceHelper; +import org.apache.axis2.context.ConfigurationContext; +import org.apache.axis2.context.MessageContext; +import org.apache.axis2.deployment.DeploymentErrorMsgs; +import org.apache.axis2.deployment.DeploymentException; +import org.apache.axis2.deployment.ModuleBuilder; +import org.apache.axis2.deployment.util.Utils; +import org.apache.axis2.description.AxisModule; +import org.apache.axis2.description.AxisOperation; +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.description.WSDLToAxisServiceBuilder; +import org.apache.axis2.engine.AxisConfiguration; +import org.apache.axis2.engine.MessageReceiver; +import org.apache.axis2.i18n.Messages; +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.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.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.security.ws.Axis2ConfigParamPolicy; +import org.apache.tuscany.sca.runtime.EndpointReference; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; +import org.apache.tuscany.sca.runtime.RuntimeWire; + +public class Axis2ServiceProvider { + + private AbstractContract contract; + private WebServiceBinding wsBinding; + private ServletHost servletHost; + private MessageFactory messageFactory; + private ConfigurationContext configContext; + + 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_TO = + new QName(AddressingConstants.Final.WSA_NAMESPACE, AddressingConstants.WSA_TO); + + public static final QName QNAME_WSA_REFERENCE_PARAMETERS = + new QName(AddressingConstants.Final.WSA_NAMESPACE, AddressingConstants.EPR_REFERENCE_PARAMETERS); + + // TODO: what to do about the base URI? + // This port number may be used to construct callback URIs. The value 8085 is used + // beacuse it matches the service port number used by the simple-callback-ws sample. + private static final String BASE_URI = "http://localhost:8085/"; + + public Axis2ServiceProvider(RuntimeComponent component, + AbstractContract contract, + WebServiceBinding wsBinding, + ServletHost servletHost, + MessageFactory messageFactory) { + + this.contract = contract; + this.wsBinding = wsBinding; + this.servletHost = servletHost; + this.messageFactory = messageFactory; + + try { + TuscanyAxisConfigurator tuscanyAxisConfigurator = new TuscanyAxisConfigurator(); + configContext = tuscanyAxisConfigurator.getConfigurationContext(); + //deployRampartModule(); + configureSecurity(); + } catch (AxisFault e) { + throw new RuntimeException(e); // TODO: better exception + } catch ( Exception e ) { + throw new RuntimeException(e); + } + + configContext.setContextRoot(servletHost.getContextPath()); + + String uri = computeActualURI(BASE_URI, component, contract).normalize().toString(); + if (uri.endsWith("/")) { + uri = uri.substring(0, uri.length() - 1); + } + wsBinding.setURI(uri); + } + + private void engageModules() throws AxisFault { + if ( wsBinding instanceof PolicySetAttachPoint ) { + PolicySetAttachPoint policiedBinding = (PolicySetAttachPoint)wsBinding; + if ( policiedBinding.getPolicySets().size() > 0 ) { + //TODO: need to verify if one of the policies are concerned with security + AxisModule m = new AxisModule("rampart"); + m.setFileName(wsBinding.getClass().getClassLoader().getResource("rampart-1.2.mar")); + configContext.getAxisConfiguration().addModule(m); + configContext.getAxisConfiguration().engageModule(m, configContext.getAxisConfiguration()); + } + } + } + + public void start() { + + // TODO: if specifies the wsdl service then should create a + // service for every port + + try { + AxisService axisService = createAxisService(); + configContext.getAxisConfiguration().addService(createAxisService()); + } catch (AxisFault e) { + throw new RuntimeException(e); + } + + Axis2ServiceServlet servlet = new Axis2ServiceServlet(); + servlet.init(configContext); + String servletURI = wsBinding.getURI(); + servletHost.addServletMapping(servletURI, servlet); + } + + public void stop() { + servletHost.removeServletMapping(wsBinding.getURI()); + try { + configContext.getAxisConfiguration().removeService(wsBinding.getURI()); + } catch (AxisFault e) { + throw new RuntimeException(e); + } + } + + /** + * Compute the endpoint URI based on section 2.1.1 of the WS binding spec 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 spec + * If the has no wsdlElement but does have a uri attribute then + * the uri takes precidence over any implicitly used WSDL. + * + * @param parent + */ + protected URI computeActualURI(String baseURI, RuntimeComponent component, AbstractContract contract) { + + org.apache.axis2.addressing.EndpointReference epr = null; + URI eprURI = null; + if (wsBinding.getEndPointReference() != null) { + epr = getEPR(); + if (epr.getAddress() != null) { + eprURI = URI.create(epr.getAddress()); + } + } + + URI wsdlURI = null; + if (wsBinding.getServiceName() != null && wsBinding.getBindingName() == null) { + // explicitly points at a wsdl port, may be a relative URI + wsdlURI = getEndpoint(wsBinding.getPort()); + } + + // if the wsdl port/endpoint has an absolute URI use that + if (wsdlURI != null && wsdlURI.isAbsolute()) { + if (wsBinding.getURI() != null) { +// TODO: throw new IllegalArgumentException("Cannot specify binding URI when wsdl has aboslute URI"); + } + return URI.create(wsdlURI.toString()); + } + + // if the wsa:EndpointReference has an address element with an absolute URI use that + if (eprURI != null && eprURI.isAbsolute()) { + //FIXME Throwing an exception breaks as wsBinding.getURI() will return the default URI + // derived from the service name or the URI actually configured in the .composite +// if (wsBinding.getURI() != null) { +// throw new IllegalArgumentException("Cannot specify binding URI when wsa:EndpointReference has aboslute address URI"); +// } + return URI.create(eprURI.toString()); + } + + // either there is no wsdl port endpoint URI or that URI is relative + + URI completeURI; + if (wsBinding.getURI() != null) { + completeURI = URI.create(wsBinding.getURI()); + if (!completeURI.isAbsolute()) { + completeURI = URI.create(baseURI + "/" + wsBinding.getURI()); + } + } else { + completeURI = URI.create(baseURI + "/" + wsBinding.getName()); + } + + if (eprURI != null) { + // there is a relative URI in the binding EPR + completeURI = URI.create(completeURI + "/" + eprURI); + } + + if (wsdlURI != null) { + // there is a relative URI in the wsdl port + completeURI = URI.create(completeURI + "/" + wsdlURI); + } + + return completeURI; + + } + + private org.apache.axis2.addressing.EndpointReference getEPR() { + 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); + } + } + + /** + * Returns the endpoint of a given port. + */ + protected URI getEndpoint(Port wsdlPort) { + if (wsdlPort != null) { + List wsdlPortExtensions = wsdlPort.getExtensibilityElements(); + for (Object extension : wsdlPortExtensions) { + if (extension instanceof SOAPAddress) { + return URI.create(((SOAPAddress)extension).getLocationURI()); + } + } + } + return null; + } + + private AxisService createAxisService() throws AxisFault { + AxisService axisService; + if (wsBinding.getWSDLDefinition() != null) { + axisService = createWSDLAxisService(); + } else { + axisService = createJavaAxisService(); + } + initAxisOperations(axisService); + return axisService; + } + + /** + * Create an AxisService from the interface class from the SCA service interface + */ + protected AxisService createJavaAxisService() throws AxisFault { + AxisService axisService = new AxisService(); + String path = URI.create(wsBinding.getURI()).getPath(); + axisService.setName(path); + axisService.setServiceDescription("Tuscany configured AxisService for service: " + wsBinding.getURI()); + 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; + } + + /** + * Create an AxisService from the WSDL doc used by ws binding + */ + protected AxisService createWSDLAxisService() throws AxisFault { + Definition definition = wsBinding.getWSDLDefinition().getDefinition(); + + // WSDLToAxisServiceBuilder only uses the service and port to find the wsdl4J Binding + // An SCA service with binding.ws does not require a service or port so we may not have + // these but ... + + Axis2ServiceClient.setServiceAndPort(wsBinding); + QName serviceQName = wsBinding.getServiceName(); + String portName = wsBinding.getPortName(); + + WSDLToAxisServiceBuilder builder = new WSDL11ToAxisServiceBuilder(definition, serviceQName, portName); + builder.setServerSide(true); + AxisService axisService = builder.populateService(); + + String path = URI.create(wsBinding.getURI()).getPath(); + axisService.setName(path); + axisService.setServiceDescription("Tuscany configured AxisService for service: " + wsBinding.getURI()); + + // 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); + + return axisService; + } + + 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); + } else { + msgrec = new Axis2ServiceInOutSyncMessageReceiver(this, op); + } + 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; + + //FIXME: can we use the Axis2 addressing support for this? + SOAPHeader header = inMC.getEnvelope().getHeader(); + if (header != null) { + OMElement to = header.getFirstChildWithName(QNAME_WSA_TO); + if (to != null) { + OMElement params = to.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 callbackAddrElement = + params.getFirstChildWithName(Axis2BindingInvoker.CALLBACK_REFERENCE_REFPARM_QN); + if (callbackAddrElement != null) { + if (contract.getInterfaceContract().getCallbackInterface() != null) { + callbackAddress = callbackAddrElement.getText(); + } + } + OMElement callbackIDElement = + params.getFirstChildWithName(Axis2BindingInvoker.CALLBACK_ID_REFPARM_QN); + if (callbackIDElement != null) { + if (contract.getInterfaceContract().getCallbackInterface() != null) { + callbackID = callbackIDElement.getText(); + } + } + } + } + } + + // create a message object and set the args as its body + Message msg = messageFactory.createMessage(); + msg.setBody(args); + + // if reference parameters are needed, create a new "To" EPR to hold them + EndpointReference to = null; + if (callbackAddress != null || + callbackID != null || + conversationID != null) { + to = new EndpointReferenceImpl(null); + msg.setTo(to); + } + + // set the reference parameters into the "To" EPR + if (callbackAddress != null) { + to.getReferenceParameters().setCallbackReference(new EndpointReferenceImpl(callbackAddress)); + } + if (callbackID != null) { + to.getReferenceParameters().setCallbackID(callbackID); + } + if (conversationID != null) { + to.getReferenceParameters().setConversationID(conversationID); + } + + // find the runtime wire and invoke it with the message + RuntimeWire wire = ((RuntimeComponentService)contract).getRuntimeWire(getBinding()); + return wire.invoke(op, msg); + } + + 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 configureSecurity() throws AxisFault { + if ( wsBinding instanceof PolicySetAttachPoint ) { + PolicySetAttachPoint policiedBinding = (PolicySetAttachPoint)wsBinding; + Parameter configParam = null; + Axis2ConfigParamPolicy axis2ConfigParamPolicy = null; + for ( PolicySet policySet : policiedBinding.getPolicySets() ) { + for ( Object policy : policySet.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)); + configContext.getAxisConfiguration().addParameter(configParam); + } + } + } + } + } + } + + private void deployRampartModule() throws DeploymentException, AxisFault { + ClassLoader tccl = (ClassLoader) org.apache.axis2.java.security.AccessController + .doPrivileged(new PrivilegedAction() { + public Object run() { + return Thread.currentThread().getContextClassLoader(); + } + }); + + + AxisModule module = new AxisModule(); + module.setParent(configContext.getAxisConfiguration()); + String moduleName = "rampart-1.2"; + URL moduleurl = TuscanyAxisConfigurator.class.getResource("/org/apache/tuscany/sca/binding/ws/axis2/engine/config/rampart-1.2.mar"); + module.setName(moduleName); + ClassLoader deploymentClassloader = Utils.createClassLoader(new URL[]{moduleurl}, + tccl, + true, + (File)configContext.getAxisConfiguration().getParameterValue(Constants.Configuration.ARTIFACTS_TEMP_DIR)); + + module.setModuleClassLoader(deploymentClassloader); + populateModule(module, moduleurl,configContext.getAxisConfiguration()); + module.setFileName(moduleurl); + TuscanyAxisConfigurator.addNewModule(module, configContext.getAxisConfiguration()); + org.apache.axis2.util.Utils.calculateDefaultModuleVersion( + configContext.getAxisConfiguration().getModules(), configContext.getAxisConfiguration()); + } + + private void populateModule(AxisModule module, URL moduleUrl, AxisConfiguration axisConfig) throws DeploymentException { + try { + ClassLoader classLoadere = module.getModuleClassLoader(); + InputStream moduleStream = classLoadere.getResourceAsStream("META-INF/module.xml"); + if (moduleStream == null) { + moduleStream = classLoadere.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); + } + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceServlet.java b/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceServlet.java new file mode 100644 index 0000000000..7096dd9e3e --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceServlet.java @@ -0,0 +1,297 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, 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.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.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 + */ +public class Axis2ServiceServlet extends AxisServlet { + + protected TuscanyListingAgent agent; + + private static final long serialVersionUID = 1L; + private static final ServletConfig DUMMY_CONFIG = createDummyServletConfig(); + +//JIRA TUSCANY-1561 Port to Axis2 1.3 + private ConfigurationContext tmpconfigContext; + + public void init(ConfigurationContext configContext) { + this.tmpconfigContext = configContext; + try { + super.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 { + } + + public void init(ServletConfig config) throws ServletException { + ServletContext servletContext = config.getServletContext(); + servletContext.setAttribute(CONFIGURATION_CONTEXT, tmpconfigContext); + super.init(config); + } + + /** + * 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(); + } 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); + } + } + + String contextPath = configContext.getServiceContextPath(); + + URI epURI = URI.create("http://" + ip + ":" + port + "/" + contextPath + "/" + serviceName).normalize(); + + return new EndpointReference[]{new EndpointReference(epURI.toString())}; + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Java2WSDLHelper.java b/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Java2WSDLHelper.java new file mode 100644 index 0000000000..718966274c --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/Java2WSDLHelper.java @@ -0,0 +1,250 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, 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.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.util.List; +import java.util.Map; + +import javax.wsdl.Definition; +import javax.wsdl.Port; +import javax.wsdl.PortType; +import javax.wsdl.Service; +import javax.wsdl.Types; +import javax.wsdl.WSDLException; +import javax.wsdl.extensions.schema.Schema; +import javax.wsdl.xml.WSDLLocator; +import javax.wsdl.xml.WSDLReader; +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.binding.ws.WebServiceBinding; +import org.apache.tuscany.sca.interfacedef.DataType; +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.DefaultWSDLFactory; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLDefinition; +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.WSDLOperationIntrospectorImpl; +import org.apache.tuscany.sca.interfacedef.wsdl.xml.XMLDocumentHelper; +import org.apache.tuscany.sca.policy.Intent; +import org.apache.tuscany.sca.policy.IntentAttachPoint; +import org.apache.ws.commons.schema.XmlSchemaCollection; +import org.apache.ws.java2wsdl.Java2WSDLBuilder; +import org.w3c.dom.Element; +import org.xml.sax.InputSource; + +/** + * Utility methods to create WSDL objects from Java interfaces + */ +public class Java2WSDLHelper { + + /** + * Create a WSDLInterfaceContract from a JavaInterfaceContract + */ + public static WSDLInterfaceContract createWSDLInterfaceContract(JavaInterfaceContract contract, WebServiceBinding wsBinding) { + JavaInterface iface = (JavaInterface)contract.getInterface(); + Definition def = Java2WSDLHelper.createDefinition(iface.getJavaClass(), wsBinding); + + DefaultWSDLFactory wsdlFactory = new DefaultWSDLFactory(); + + WSDLInterfaceContract wsdlContract = wsdlFactory.createWSDLInterfaceContract(); + WSDLInterface wsdlInterface = wsdlFactory.createWSDLInterface(); + + wsdlContract.setInterface(wsdlInterface); + WSDLDefinition wsdlDefinition = new DefaultWSDLFactory().createWSDLDefinition(); + 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); + + readInlineSchemas(def, wsdlDefinition.getInlinedSchemas()); + + try { + for (Operation op : iface.getOperations()) { + Operation clonedOp = (Operation)op.clone(); + clonedOp.setDataBinding(null); + for (DataType dt : clonedOp.getInputType().getLogical()) { + dt.setDataBinding(null); + } + + if (clonedOp.getOutputType() != null ){ + clonedOp.getOutputType().setDataBinding(null); + } + for (DataType dt : clonedOp.getFaultTypes()) { + dt.setDataBinding(null); + } + clonedOp.setWrapperStyle(true); + javax.wsdl.Operation wsdlOp = portType.getOperation(op.getName(), null, null); + WSDLOperationIntrospectorImpl opx = + new WSDLOperationIntrospectorImpl(wsdlFactory, wsdlOp, wsdlDefinition.getInlinedSchemas(), null, + null); + clonedOp.setWrapper(opx.getWrapper().getWrapperInfo()); + + wsdlInterface.getOperations().add(clonedOp); + } + } catch (CloneNotSupportedException e) { + throw new RuntimeException(e); + } catch (InvalidWSDLException e) { + throw new RuntimeException(e); + } + + return wsdlContract; + } + + protected static void readInlineSchemas(Definition definition, XmlSchemaCollection schemaCollection) { + Types types = definition.getTypes(); + if (types != null) { + for (Object ext : types.getExtensibilityElements()) { + if (ext instanceof Schema) { + Element element = ((Schema)ext).getElement(); + schemaCollection.setBaseUri(((Schema)ext).getDocumentBaseURI()); + schemaCollection.read(element, definition.getDocumentBaseURI()); + } + } + } + for (Object imports : definition.getImports().values()) { + List impList = (List)imports; + for (Object i : impList) { + javax.wsdl.Import anImport = (javax.wsdl.Import)i; + // Read inline schemas + if (anImport.getDefinition() != null) { + readInlineSchemas(anImport.getDefinition(), schemaCollection); + } + } + } + } + + /** + * Create a WSDL4J Definition object from a Java interface + */ + protected static Definition createDefinition(Class javaInterface, WebServiceBinding wsBinding) { + + String className = javaInterface.getName(); + ClassLoader cl = javaInterface.getClassLoader(); + ByteArrayOutputStream os = new ByteArrayOutputStream(); + Java2WSDLBuilder builder = new Java2WSDLBuilder(os, className, cl); + + try { + builder.generateWSDL(); + } catch (Exception e) { + throw new RuntimeException(e); + } + + try { + + WSDLReader reader = javax.wsdl.factory.WSDLFactory.newInstance().newWSDLReader(); + reader.setFeature("javax.wsdl.verbose", false); + reader.setFeature("javax.wsdl.importDocuments", true); + + WSDLLocatorImpl locator = new WSDLLocatorImpl(new ByteArrayInputStream(os.toByteArray())); + Definition definition = reader.readWSDL(locator); + + processSOAPVersion(definition, wsBinding); + + return definition; + + } catch (WSDLException e) { + throw new RuntimeException(e); + } + } + + private static void processSOAPVersion(Definition definition, WebServiceBinding wsBinding) { + if (requiresSOAP12(wsBinding)) { + removePort(definition, "SOAP11port"); + } else { + removePort(definition, "SOAP12port"); + } + } + + private static void removePort(Definition definition, String portNameSuffix) { + Service service = (Service)definition.getServices().values().iterator().next(); + Map ports = service.getPorts(); + for (Object o : ports.keySet()) { + if (((String)o).endsWith(portNameSuffix)) { + Port p = (Port) ports.remove(o); + definition.removeBinding(p.getBinding().getQName()); + break; + } + } + } + + private static final QName SOAP12_INTENT = new QName("http://www.osoa.org/xmlns/sca/1.0", "soap12"); + + private 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; + } +} + +class WSDLLocatorImpl implements WSDLLocator { + private InputStream inputStream; + private String base = "http://"; + private String latestImportURI; + + public WSDLLocatorImpl(InputStream is) { + this.inputStream = is; + } + + public void close() { + try { + inputStream.close(); + } catch (IOException e) { + // Ignore + } + } + + public InputSource getBaseInputSource() { + try { + return XMLDocumentHelper.getInputSource(new URL(base), inputStream); + } catch (IOException e) { + throw new IllegalArgumentException(e); + } + } + + public String getBaseURI() { + return base; + } + + public InputSource getImportInputSource(String parentLocation, String importLocation) { + return null; + } + + public String getLatestImportURI() { + return latestImportURI; + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/TuscanyAxisConfigurator.java b/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/TuscanyAxisConfigurator.java new file mode 100755 index 0000000000..bace251794 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/TuscanyAxisConfigurator.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.axis2; + +import org.apache.axis2.AxisFault; +import org.apache.axis2.context.ConfigurationContext; +import org.apache.axis2.context.ConfigurationContextFactory; +import org.apache.axis2.deployment.URLBasedAxisConfigurator; +import org.apache.axis2.engine.AxisConfigurator; + +/** + * Helps configure Axis2 from a resource in binding.ws.axis2 instead of Axis2.xml + *

TODO: Review: should there be a single global Axis ConfigurationContext + */ +public class TuscanyAxisConfigurator extends URLBasedAxisConfigurator implements AxisConfigurator { + + public TuscanyAxisConfigurator() 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/")); + } + + public ConfigurationContext getConfigurationContext() throws AxisFault { + if (configContext == null) { + configContext = ConfigurationContextFactory.createConfigurationContext(this); + } + return configContext; + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/TuscanyDispatcher.java b/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/TuscanyDispatcher.java new file mode 100644 index 0000000000..c761c7481e --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/TuscanyDispatcher.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.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/ + */ +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/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/TuscanyListingAgent.java b/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/TuscanyListingAgent.java new file mode 100644 index 0000000000..8ff52413e1 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/ws/axis2/TuscanyListingAgent.java @@ -0,0 +1,411 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, 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.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; + +/** + * A Tuscany specific Axis2 ListingAgent as the Axis2 one does not work + * with the Tuscany sevice names which include slash ('/') characters. + * Unfortunately it ends up having to copy a fair amount of Axis2 code to do this. + */ +public class TuscanyListingAgent extends ListingAgent { + + private static final String LIST_SINGLE_SERVICE_JSP_NAME = + "listSingleService.jsp"; + + public TuscanyListingAgent(ConfigurationContext aConfigContext) { + super(aConfigContext); + } + + protected 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; + } + + @Override + public void processListService(HttpServletRequest req, + HttpServletResponse res) + throws IOException, ServletException { + + + String filePart = req.getRequestURL().toString(); +// String serviceName = filePart.substring(filePart.lastIndexOf("/") + 1, +// filePart.length()); +// Change the Axis2 code so as to use the complete ServletPath as the service name +// this line is the only change to to Axis2 code + + String serviceName = findAxisServiceName(filePart); + setContextRoot(filePart, serviceName); + + String query = req.getQueryString(); + int wsdl2 = query.indexOf("wsdl2"); + int wsdl = query.indexOf("wsdl"); + int xsd = query.indexOf("xsd"); + int policy = query.indexOf("policy"); + + HashMap services = configContext.getAxisConfiguration().getServices(); + if ((services != null) && !services.isEmpty()) { + Object serviceObj = services.get(serviceName); + if (serviceObj != null) { + boolean isHttp = "http".equals(req.getScheme()); + if (wsdl2 >= 0) { + OutputStream out = res.getOutputStream(); + res.setContentType("text/xml"); + String ip = extractHostAndPort(filePart, isHttp); +// JIRA TUSCANY-1561 Port to Axis2 1.3 +// ((AxisService) serviceObj).printWSDL2(out, ip, configContext.getServiceContextPath()); + ((AxisService) serviceObj).printWSDL2(out, ip); + out.flush(); + out.close(); + return; + } else if (wsdl >= 0) { + OutputStream out = res.getOutputStream(); + res.setContentType("text/xml"); + String ip = extractHostAndPort(filePart, isHttp); + patchSOAP12Port((AxisService)serviceObj); +// JIRA TUSCANY-1561 Port to Axis2 1.3 +// ((AxisService) serviceObj).printWSDL(out, ip, configContext.getServicePath()); + ((AxisService) serviceObj).printWSDL(out, ip); + out.flush(); + out.close(); + return; + } else if (xsd >= 0) { + OutputStream out = res.getOutputStream(); + res.setContentType("text/xml"); + AxisService axisService = (AxisService) serviceObj; + //call the populator + axisService.populateSchemaMappings(); + Map schemaMappingtable = + axisService.getSchemaMappingTable(); + ArrayList schemas = axisService.getSchema(); + + //a name is present - try to pump the requested schema + String xsds = req.getParameter("xsd"); + if (!"".equals(xsds)) { + XmlSchema schema = + (XmlSchema) schemaMappingtable.get(xsds); + if (schema != null) { + //schema is there - pump it outs + schema.write(new OutputStreamWriter(out, "UTF8")); + out.flush(); + out.close(); + } else { + InputStream in = axisService.getClassLoader() + .getResourceAsStream(DeploymentConstants.META_INF + "/" + xsds); + if (in != null) { + out.write(IOUtils.getStreamAsByteArray(in)); + out.flush(); + out.close(); + } else { + res.sendError(HttpServletResponse.SC_NOT_FOUND); + } + } + + //multiple schemas are present and the user specified + //no name - in this case we cannot possibly pump a schema + //so redirect to the service root + } else if (schemas.size() > 1) { + res.sendRedirect(""); + //user specified no name and there is only one schema + //so pump that out + } else { + XmlSchema schema = axisService.getSchema(0); + if (schema != null) { + schema.write(new OutputStreamWriter(out, "UTF8")); + out.flush(); + out.close(); + } + } + return; + } else if (policy >= 0) { + + OutputStream out = res.getOutputStream(); + + ExternalPolicySerializer serializer = new ExternalPolicySerializer(); + serializer.setAssertionsToFilter(configContext + .getAxisConfiguration().getLocalPolicyAssertions()); + + // check whether Id is set + String idParam = req.getParameter("id"); + + if (idParam != null) { + // Id is set + + Policy targetPolicy = findPolicy(idParam, (AxisService) serviceObj); + + if (targetPolicy != null) { + XMLStreamWriter writer; + + try { + writer = XMLOutputFactory.newInstance() + .createXMLStreamWriter(out); + + res.setContentType("text/xml"); + targetPolicy.serialize(writer); + writer.flush(); + + } catch (XMLStreamException e) { + throw new ServletException( + "Error occured when serializing the Policy", + e); + + } catch (FactoryConfigurationError e) { + throw new ServletException( + "Error occured when serializing the Policy", + e); + } + + } else { + + res.setContentType("text/html"); + String outStr = "No policy found for id=" + + idParam + ""; + out.write(outStr.getBytes()); + } + + } else { + + PolicyInclude policyInclude = ((AxisService) serviceObj).getPolicyInclude(); + Policy effecPolicy = policyInclude.getEffectivePolicy(); + + if (effecPolicy != null) { + XMLStreamWriter writer; + + try { + writer = XMLOutputFactory.newInstance() + .createXMLStreamWriter(out); + + res.setContentType("text/xml"); + effecPolicy.serialize(writer); + writer.flush(); + + } catch (XMLStreamException e) { + throw new ServletException( + "Error occured when serializing the Policy", + e); + + } catch (FactoryConfigurationError e) { + throw new ServletException( + "Error occured when serializing the Policy", + e); + } + } else { + + res.setContentType("text/html"); + String outStr = "No effective policy for " + + serviceName + " servcie"; + out.write(outStr.getBytes()); + } + } + + return; + } else { + req.getSession().setAttribute(Constants.SINGLE_SERVICE, + serviceObj); + } + } else { + req.getSession().setAttribute(Constants.SINGLE_SERVICE, null); + } + } + + renderView(LIST_SINGLE_SERVICE_JSP_NAME, req, res); + } + + /** + * 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) { + configContext.setServicePath("/"); + } else { + String mapping = filePart.substring(i+1, j); + configContext.setServicePath(mapping); + } + } + configContext.setContextRoot(contextRoot); + } + } + + private String extractHostAndPort(String filePart, boolean isHttp) { + int ipindex = filePart.indexOf("//"); + String ip = null; + if (ipindex >= 0) { + ip = filePart.substring(ipindex + 2, filePart.length()); + int seperatorIndex = ip.indexOf(":"); + int slashIndex = ip.indexOf("/"); + String port; + if (seperatorIndex >= 0) { + port = ip.substring(seperatorIndex + 1, slashIndex); + ip = ip.substring(0, seperatorIndex); + } else { + ip = ip.substring(0, slashIndex); + port = "80"; + } + if (isHttp) { + configContext.setProperty(RUNNING_PORT, port); + } + } + return ip; + } + + private Policy findPolicy(String id, AxisDescription des) { + + List policyElements = des.getPolicyInclude().getPolicyElements(); + PolicyRegistry registry = des.getPolicyInclude().getPolicyRegistry(); + + Object policyComponent; + + Policy policy = registry.lookup(id); + + if (policy != null) { + return policy; + } + + for (Iterator iterator = policyElements.iterator(); iterator.hasNext();) { + policyComponent = iterator.next(); + + if (policyComponent instanceof Policy) { + // policy found for the id + + if (id.equals(((Policy) policyComponent).getId())) { + return (Policy) policyComponent; + } + } + } + + AxisDescription child; + + for (Iterator iterator = des.getChildren(); iterator.hasNext();) { + child = (AxisDescription) iterator.next(); + policy = findPolicy(id, child); + + if (policy != null) { + return policy; + } + } + + return null; + } + + /** + * Hack to get ?wsdl working with soap 1.2 + * Fixed in Axis2 1.3 + */ + private void patchSOAP12Port(AxisService as) throws AxisFault { + Parameter wsld4jdefinition = as.getParameter(WSDLConstants.WSDL_4_J_DEFINITION); + Definition definition = (Definition) wsld4jdefinition.getValue(); + setPortAddress(definition, null, as); + } + + /** + * This is a copy of the AxisService setPortAddress patched to work with SOAP 1.2 Addresses + * Fixed in Axis2 1.3 + */ + private void setPortAddress(Definition definition, String requestIP, AxisService axisService) throws AxisFault { + Iterator serviceItr = definition.getServices().values().iterator(); + while (serviceItr.hasNext()) { + Service serviceElement = (Service) serviceItr.next(); + Iterator portItr = serviceElement.getPorts().values().iterator(); + while (portItr.hasNext()) { + Port port = (Port) portItr.next(); + List list = port.getExtensibilityElements(); + for (int i = 0; i < list.size(); i++) { + Object extensibilityEle = list.get(i); + String locationURI = null; + if (requestIP == null) { + locationURI = axisService.getEPRs()[0]; + } else { +// can't do this as the method's not visible, but Tuscany doesn't use this path anyway +// locationURI = axisService.getEPRs(requestIP)[0]); + } + if (extensibilityEle instanceof SOAPAddress) { + ((SOAPAddress) extensibilityEle).setLocationURI(locationURI); + } else if (extensibilityEle instanceof SOAP12Address) { + ((SOAP12Address) extensibilityEle).setLocationURI(locationURI); + } + } + } + } + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/main/resources/org/apache/tuscany/sca/binding/ws/axis2/engine/config/axis2.xml b/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/main/resources/org/apache/tuscany/sca/binding/ws/axis2/engine/config/axis2.xml new file mode 100755 index 0000000000..08c6e05ce9 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/main/resources/org/apache/tuscany/sca/binding/ws/axis2/engine/config/axis2.xml @@ -0,0 +1,478 @@ + + + + + + + + true + false + false + false + + + + + + + + + 30000 + + + + + + true + + + + + + false + + admin + axis2 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + false + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 6060 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + > + + + + + + + + + + + + + HTTP/1.1 + chunked + + + + + + + HTTP/1.1 + chunked + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/main/resources/org/apache/tuscany/sca/binding/ws/axis2/engine/config/modules/modules.list b/tags/java/sca/1.0-RC1b/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..1641457d28 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/main/resources/org/apache/tuscany/sca/binding/ws/axis2/engine/config/modules/modules.list @@ -0,0 +1 @@ +rampart-1.3.mar \ No newline at end of file diff --git a/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/main/resources/org/apache/tuscany/sca/binding/ws/axis2/engine/config/modules/rampart-1.3.mar b/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/main/resources/org/apache/tuscany/sca/binding/ws/axis2/engine/config/modules/rampart-1.3.mar new file mode 100644 index 0000000000..af3c45aa93 Binary files /dev/null and b/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/main/resources/org/apache/tuscany/sca/binding/ws/axis2/engine/config/modules/rampart-1.3.mar differ diff --git a/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/main/resources/org/apache/tuscany/sca/binding/ws/axis2/engine/config/services/services.list b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ReferenceTestCase.java b/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ReferenceTestCase.java new file mode 100755 index 0000000000..2ce23bf2c4 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceTestCase.java b/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/Axis2ServiceTestCase.java new file mode 100755 index 0000000000..d4d20414e5 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/Greeter.java b/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/Greeter.java new file mode 100755 index 0000000000..767f59646f --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/GreetingCallback.java b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/Java2WSDLHelperTestCase.java b/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/Java2WSDLHelperTestCase.java new file mode 100644 index 0000000000..fe1411a8d3 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/Java2WSDLHelperTestCase.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; + +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.binding.ws.axis2.Java2WSDLHelper; +import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException; +import org.apache.tuscany.sca.interfacedef.java.DefaultJavaInterfaceFactory; +import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceContract; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterface; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterfaceContract; + +public class Java2WSDLHelperTestCase extends TestCase { + + public void testCreateDefinition() { + Definition definition = Java2WSDLHelper.createDefinition(HelloWorld.class, null); + assertNotNull(definition); + + Map portTypes = definition.getPortTypes(); + assertEquals(1, portTypes.size()); + + PortType portType = (PortType)portTypes.values().iterator().next(); + assertEquals("HelloWorldPortType", portType.getQName().getLocalPart()); + assertEquals("http://axis2.ws.binding.sca.tuscany.apache.org", portType.getQName().getNamespaceURI()); + + List ops = portType.getOperations(); + assertEquals(1, ops.size()); + + Operation operation = (Operation)ops.get(0); + assertEquals("sayHello", operation.getName()); + } + + + public void testCreateWSDLInterfaceContract() throws InvalidInterfaceException { + DefaultJavaInterfaceFactory factory = new DefaultJavaInterfaceFactory(); + JavaInterfaceContract javaIC = factory.createJavaInterfaceContract(); + javaIC.setInterface(factory.createJavaInterface(HelloWorld.class)); + WSDLInterfaceContract wsdlIC = Java2WSDLHelper.createWSDLInterfaceContract(javaIC, 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()); + } + +} + +interface HelloWorld { + public String sayHello(String s); +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/Bar.java b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/Echo.java b/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/Echo.java new file mode 100644 index 0000000000..e60c30790a --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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 { + + public Foo echoFoo(Foo foo); + +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/EchoComponent.java b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/EchoImpl.java b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/Foo.java b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/HelloWorld.java b/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/HelloWorld.java new file mode 100644 index 0000000000..e2f3982d99 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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 { + + public String getGreetings(String s); + +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/HelloWorldComponent.java b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/HelloWorldMultiService.java b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/HelloWorldNoWSDLTestCase.java b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/HelloWorldOM.java b/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/HelloWorldOM.java new file mode 100644 index 0000000000..f09ca4a435 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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 { + + public OMElement getGreetings(OMElement parmE); + +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/HelloWorldOM2.java b/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/HelloWorldOM2.java new file mode 100644 index 0000000000..f3a4ae4c8b --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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 { + + public OMElement getGreetings2(OMElement parmE); + +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/HelloWorldOMComponent.java b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/HelloWorldOMService.java b/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/HelloWorldOMService.java new file mode 100644 index 0000000000..69bb571144 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/HelloWorldOMService.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.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) { + 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/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/HelloWorldOMTestCase.java b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/HelloWorldService.java b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/HelloWorldTestCase.java b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/HelloWorldWSDLMergedTestCaseFIXME.java b/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/HelloWorldWSDLMergedTestCaseFIXME.java new file mode 100644 index 0000000000..d105e3d50e --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/HelloWorldWSDLMergedTestCaseFIXME.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 HelloWorldWSDLMergedTestCaseFIXME 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/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/QuestionMarkWSDLTestCase.java b/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/QuestionMarkWSDLTestCase.java new file mode 100644 index 0000000000..535ad3eeca --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/QuestionMarkWSDLTestCase.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.itests; + +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.axis2.transport.http.server.HttpUtils; +import org.apache.tuscany.sca.host.embedded.SCADomain; + +/** + * Test ?wsdl works and that the returned wsdl has the correct endpoint + */ +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 { + 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")); + Port port = service.getPort("HelloWorldSoapPort"); + + String endpoint = getEndpoint(port); + String ip = HttpUtils.getIpAddress(); + assertEquals("http://" + ip + ":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 { + 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", "HelloWorld")); + Port port = service.getPort("HelloWorldSOAP11port_http"); + + String endpoint = getEndpoint(port); + String ip = HttpUtils.getIpAddress(); + assertEquals("http://" + ip + ":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/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/endpoints/AbstractHelloWorldOMTestCase.java b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/endpoints/DefaultMultiServiceTestCase.java b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/endpoints/DefaultSingleServiceTestCase.java b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/endpoints/WSDLExplicitURITestCase.java b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/endpoints/WSDLRelativeURITestCase.java b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/epr/HelloWorldTestCase.java b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/AbstractHelloWorldOMTestCase.java b/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/AbstractHelloWorldOMTestCase.java new file mode 100644 index 0000000000..34ecf37f31 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/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; + +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/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/ClientPWCBHandler.java b/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/ClientPWCBHandler.java new file mode 100644 index 0000000000..f674d8a6ca --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/ClientPWCBHandler.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.ws.axis2.itests.policy; + +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 + */ +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/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/IntegrityPWCBHandler.java b/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/IntegrityPWCBHandler.java new file mode 100644 index 0000000000..ed955ab08b --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/IntegrityPWCBHandler.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.ws.axis2.itests.policy; + +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 + */ +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/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/ServerPWCBHandler.java b/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/ServerPWCBHandler.java new file mode 100644 index 0000000000..3c34c5e313 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/ServerPWCBHandler.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.ws.axis2.itests.policy; + +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 + */ +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/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/WSSecurityAuthenticationTestCase.java b/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/WSSecurityAuthenticationTestCase.java new file mode 100644 index 0000000000..b7716582c5 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/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; + +public class WSSecurityAuthenticationTestCase extends AbstractHelloWorldOMTestCase { + // super class does it all getting composite based on this class name +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/WSSecurityConfidentialityTestCaseFIXBouncyCastleIssue.java b/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/WSSecurityConfidentialityTestCaseFIXBouncyCastleIssue.java new file mode 100644 index 0000000000..3807642d49 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/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; + +import java.security.Provider; +import java.security.Security; + +public class WSSecurityConfidentialityTestCaseFIXBouncyCastleIssue extends AbstractHelloWorldOMTestCase { + + /** + * @see org.apache.tuscany.sca.binding.ws.axis2.itests.policy.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/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/WSSecurityIntegrityTestCase.java b/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/WSSecurityIntegrityTestCase.java new file mode 100644 index 0000000000..3d084a8627 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/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; + +public class WSSecurityIntegrityTestCase extends AbstractHelloWorldOMTestCase { + // super class does it all getting composite based on this class name +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/soap12/HelloWorldSOAP12TestCase.java b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/soap12/QuestionMarkWSDLTestCase.java b/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/soap12/QuestionMarkWSDLTestCase.java new file mode 100644 index 0000000000..9b92f6862f --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/ws/axis2/itests/soap12/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.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.axis2.transport.http.server.HttpUtils; +import org.apache.tuscany.sca.host.embedded.SCADomain; + +/** + * Test ?wsdl works and that the returned wsdl has the correct endpoint + */ +public class QuestionMarkWSDLTestCase extends TestCase { + + 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", "HelloWorld")); + Port port = service.getPort("HelloWorldSOAP11port_http"); + + String endpoint = getEndpoint(port); + String ip = HttpUtils.getIpAddress(); + assertEquals("http://" + ip + ":8085/ep1", endpoint); + } + + /** + * Tests ?wsdl returns a soap 1.1 port when binding uses requires="soap11" + */ + 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", "HelloWorld")); + Port port = service.getPort("HelloWorldSOAP11port_http"); + + String endpoint = getEndpoint(port); + String ip = HttpUtils.getIpAddress(); + assertEquals("http://" + ip + ":8085/ep2", endpoint); + } + + /** + * Tests ?wsdl returns a soap 1.2 port when binding uses requires="soap12" + */ + 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", "HelloWorld")); + Port port = service.getPort("HelloWorldSOAP12port_http"); + + String endpoint = getEndpoint(port); + String ip = HttpUtils.getIpAddress(); + assertEquals("http://" + ip + ":8085/ep3", endpoint); + } + + protected String getEndpoint(Port port) { + List wsdlPortExtensions = port.getExtensibilityElements(); + for (final Object extension : wsdlPortExtensions) { + if (extension instanceof SOAPAddress) { + return ((SOAPAddress) extension).getLocationURI(); + } else 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/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/resources/definitions.xml b/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/resources/definitions.xml new file mode 100644 index 0000000000..fb823ae989 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/resources/definitions.xml @@ -0,0 +1,152 @@ + + + + + + + Communitcation thro this binding requires SOAP + + + + + + Communitcation thro this binding requires SOAP 1.1 + + + + + + Communitcation thro this binding requires SOAP 1.2 + + + + + + Communitcation thro this binding required Authentication. + + + + + + Communitcation thro this binding required Authentication. + + + + + + Protect messages from unauthorized reading or modification + + + + + + Communitcation thro this binding must prevent + unauthorized users from reading the messages. + + + + + + + + + UsernameToken + org.apache.tuscany.sca.binding.ws.axis2.itests.policy.ServerPWCBHandler + + + + + + + + + + UsernameToken + TuscanyWsUser + org.apache.tuscany.sca.binding.ws.axis2.itests.policy.ClientPWCBHandler" + + PasswordText + + + + + + + + + + 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 + + + + + + + + + + Timestamp Signature Encrypt + org.apache.tuscany.sca.binding.ws.axis2.itests.policy.IntegrityPWCBHandler + org/apache/tuscany/sca/binding/ws/axis2/itests/policy/security.properties + + + + + Timestamp Signature Encrypt + TuscanyWsUser + TuscanyWsUser + org.apache.tuscany.sca.binding.ws.axis2.itests.policy.IntegrityPWCBHandler + org/apache/tuscany/sca/binding/ws/axis2/itests/policy/security.properties + DirectReference + SKIKeyIdentifier + + + + + + \ No newline at end of file diff --git a/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/HelloWorld.composite b/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/HelloWorld.composite new file mode 100644 index 0000000000..78163900fe --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/HelloWorld.composite @@ -0,0 +1,50 @@ + + + + + + + + + + myURI + + + + + + + + + + + + + + + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/HelloWorldNoWSDL.composite b/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/HelloWorldNoWSDL.composite new file mode 100644 index 0000000000..3ff98f9a51 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/HelloWorldNoWSDL.composite @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/endpoints/DefaultMultiService.composite b/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/endpoints/DefaultMultiService.composite new file mode 100644 index 0000000000..25815d8019 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/endpoints/DefaultSingleService.composite b/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/endpoints/DefaultSingleService.composite new file mode 100644 index 0000000000..42b99e3a99 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/endpoints/WSDLExplicitURI.composite b/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/endpoints/WSDLExplicitURI.composite new file mode 100644 index 0000000000..14ebfc837d --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/endpoints/WSDLRelativeURI.composite b/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/endpoints/WSDLRelativeURI.composite new file mode 100644 index 0000000000..79285a5324 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/endpoints/helloworld-om-relative-uri.wsdl b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/epr/HelloWorld.composite b/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/epr/HelloWorld.composite new file mode 100644 index 0000000000..9ab4250a31 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/helloworld-om-binding.wsdl b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/helloworld-om-merged.composite b/tags/java/sca/1.0-RC1b/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..48ce948354 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/helloworld-om-merged.composite @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/helloworld-om-porttype.wsdl b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/helloworld-om-uri.wsdl b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/helloworld-om.composite b/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/helloworld-om.composite new file mode 100644 index 0000000000..fcb8443f60 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/helloworld-om.composite @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/helloworld-om.wsdl b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/helloworld.wsdl b/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/helloworld.wsdl new file mode 100644 index 0000000000..4c85637f0d --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/helloworld.wsdl @@ -0,0 +1,80 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/WSSecurityAuthentication.composite b/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/WSSecurityAuthentication.composite new file mode 100644 index 0000000000..05d47fe8d1 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/WSSecurityAuthentication.composite @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/WSSecurityConfidentiality.composite b/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/WSSecurityConfidentiality.composite new file mode 100644 index 0000000000..ea0bcf7bc4 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/WSSecurityConfidentiality.composite @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/WSSecurityIntegrity.composite b/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/WSSecurityIntegrity.composite new file mode 100644 index 0000000000..27e497ce8f --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/WSSecurityIntegrity.composite @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/security.properties b/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/security.properties new file mode 100644 index 0000000000..24d1070e27 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/security.properties @@ -0,0 +1,4 @@ +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/tuscanyKeys.jks \ No newline at end of file diff --git a/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/tuscanyKeys.jks b/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/tuscanyKeys.jks new file mode 100644 index 0000000000..c1a63b7f20 Binary files /dev/null and b/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/policy/tuscanyKeys.jks differ diff --git a/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/questionmark-wsdl.composite b/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/questionmark-wsdl.composite new file mode 100644 index 0000000000..13cfdfd5d6 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/questionmark-wsdl.composite @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/soap12/HelloWorldSOAP12.composite b/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/soap12/HelloWorldSOAP12.composite new file mode 100644 index 0000000000..a2aa2cced4 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/ws/axis2/itests/soap12/questionmark-wsdl.composite b/tags/java/sca/1.0-RC1b/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..2e4c66bc89 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-ws-xml/.checkstyle b/tags/java/sca/1.0-RC1b/modules/binding-ws-xml/.checkstyle new file mode 100644 index 0000000000..e3c216986d --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-ws-xml/.checkstyle @@ -0,0 +1,24 @@ + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/binding-ws-xml/.pmd b/tags/java/sca/1.0-RC1b/modules/binding-ws-xml/.pmd new file mode 100644 index 0000000000..2db10d6a6a --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-ws-xml/.pmd @@ -0,0 +1,20 @@ + + +truefalse \ No newline at end of file diff --git a/tags/java/sca/1.0-RC1b/modules/binding-ws-xml/.ruleset b/tags/java/sca/1.0-RC1b/modules/binding-ws-xml/.ruleset new file mode 100644 index 0000000000..ba9b5ce886 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-ws-xml/.ruleset @@ -0,0 +1,190 @@ + + + + PMD Plugin preferences rule set + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/binding-ws-xml/DISCLAIMER b/tags/java/sca/1.0-RC1b/modules/binding-ws-xml/DISCLAIMER new file mode 100644 index 0000000000..d68a410903 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-ws-xml/DISCLAIMER @@ -0,0 +1,8 @@ +Apache Tuscany is an effort undergoing incubation at The Apache Software +Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is +required of all newly accepted projects until a further review indicates that +the infrastructure, communications, and decision making process have stabilized +in a manner consistent with other successful ASF projects. While incubation +status is not necessarily a reflection of the completeness or stability of the +code, it does indicate that the project has yet to be fully endorsed by the ASF. + diff --git a/tags/java/sca/1.0-RC1b/modules/binding-ws-xml/LICENSE b/tags/java/sca/1.0-RC1b/modules/binding-ws-xml/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-ws-xml/NOTICE b/tags/java/sca/1.0-RC1b/modules/binding-ws-xml/NOTICE new file mode 100644 index 0000000000..94481d6cfa --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-ws-xml/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2007 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/tags/java/sca/1.0-RC1b/modules/binding-ws-xml/pom.xml b/tags/java/sca/1.0-RC1b/modules/binding-ws-xml/pom.xml new file mode 100644 index 0000000000..1362b96fe6 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-ws-xml/pom.xml @@ -0,0 +1,75 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.0-incubating + ../pom.xml + + tuscany-binding-ws-xml + Apache Tuscany SCA WS Binding XML Model + + + + org.apache.tuscany.sca + tuscany-contribution + 1.0-incubating + + + org.apache.tuscany.sca + tuscany-contribution-impl + 1.0-incubating + test + + + + org.apache.tuscany.sca + tuscany-assembly-xml + 1.0-incubating + + + + org.apache.tuscany.sca + tuscany-binding-ws + 1.0-incubating + + + + org.apache.tuscany.sca + tuscany-interface-wsdl + 1.0-incubating + + + + org.apache.tuscany.sca + tuscany-binding-sca + 1.0-incubating + test + + + + org.apache.tuscany.sca + tuscany-interface-wsdl-xml + 1.0-incubating + + + diff --git a/tags/java/sca/1.0-RC1b/modules/binding-ws-xml/src/main/java/org/apache/tuscany/sca/binding/ws/xml/EndPointReferenceHelper.java b/tags/java/sca/1.0-RC1b/modules/binding-ws-xml/src/main/java/org/apache/tuscany/sca/binding/ws/xml/EndPointReferenceHelper.java new file mode 100644 index 0000000000..e82e93d971 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-ws-xml/src/main/java/org/apache/tuscany/sca/binding/ws/xml/EndPointReferenceHelper.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.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.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; + +/** + * 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 + */ +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 { + + Source domSource = new DOMSource(element); + StreamResult result = new StreamResult(new StringWriter()); + javax.xml.transform.Transformer transformer = TransformerFactory.newInstance().newTransformer(); + transformer.transform(domSource , result); + + } catch (TransformerException 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); + } + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-ws-xml/src/main/java/org/apache/tuscany/sca/binding/ws/xml/WebServiceBindingProcessor.java b/tags/java/sca/1.0-RC1b/modules/binding-ws-xml/src/main/java/org/apache/tuscany/sca/binding/ws/xml/WebServiceBindingProcessor.java new file mode 100644 index 0000000000..3c5ba98ea5 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-ws-xml/src/main/java/org/apache/tuscany/sca/binding/ws/xml/WebServiceBindingProcessor.java @@ -0,0 +1,312 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, 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.Map; + +import javax.wsdl.Definition; +import javax.wsdl.Port; +import javax.wsdl.PortType; +import javax.wsdl.Service; +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.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.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.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.policy.IntentAttachPointType; +import org.apache.tuscany.sca.policy.IntentAttachPointTypeFactory; +import org.apache.tuscany.sca.policy.PolicyFactory; +import org.apache.tuscany.sca.policy.PolicySetAttachPoint; + +public class WebServiceBindingProcessor implements + StAXArtifactProcessor, WebServiceConstants { + + private WSDLFactory wsdlFactory; + private WebServiceBindingFactory wsFactory; + private PolicyFactory policyFactory; + private PolicyAttachPointProcessor policyProcessor; + private IntentAttachPointTypeFactory intentAttachPointTypeFactory; + + public WebServiceBindingProcessor(ModelFactoryExtensionPoint modelFactories) { + this.policyFactory = modelFactories.getFactory(PolicyFactory.class); + this.wsFactory = new DefaultWebServiceBindingFactory(); + this.wsdlFactory = modelFactories.getFactory(WSDLFactory.class); + this.policyProcessor = new PolicyAttachPointProcessor(policyFactory); + this.intentAttachPointTypeFactory = modelFactories.getFactory(IntentAttachPointTypeFactory.class); + } + + 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); + + // 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) { + throw new ContributionReadException( + "Invalid WebService binding wsdlElement attribute: " + wsdlElement); + } + 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) { + throw new ContributionReadException( + "Invalid WebService binding wsdlElement attribute: " + wsdlElement); + } + 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) { + throw new ContributionReadException( + "Invalid WebService binding wsdlElement attribute: " + wsdlElement); + } + wsBinding.setServiceName(new QName(namespace, localName.substring(0, s))); + wsBinding.setEndpointName(localName.substring(s + 1)); + + } else if (localName.startsWith("wsdl.binding")) { + + // Read a wsdl.service + localName = localName.substring("wsdl.binding(".length(), localName.length() - 1); + wsBinding.setBindingName(new QName(namespace, localName)); + + wsdlElementIsBinding = true; + + } else { + throw new ContributionReadException( + "Invalid WebService binding wsdlElement attribute: " + wsdlElement); + } + } + + // Read wsdlLocation + wsBinding.setLocation(reader.getAttributeValue(WSDLI_NS, WSDL_LOCATION)); + + // Skip to end element + while (reader.hasNext()) { + int event = reader.next(); + if (event == START_ELEMENT && "EndpointReference".equals(reader.getName().getLocalPart())) { + if (wsdlElementIsBinding != null && wsdlElementIsBinding) { + throw new ContributionReadException(wsdlElement + " must use wsdl.binding when using wsa:EndpointReference"); + } + wsBinding.setEndPointReference(EndPointReferenceHelper.readEndPointReference(reader)); + } + 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 + policyProcessor.writePolicyPrefixes(wsBinding, writer); + 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()); + } + + if (wsBinding.getEndPointReference() != null) { + EndPointReferenceHelper.writeEndPointReference(wsBinding.getEndPointReference(), writer); + } + + writer.writeEndElement(); + } + + public void resolve(WebServiceBinding model, ModelResolver resolver) throws ContributionResolveException { + WSDLDefinition wsdlDefinition = wsdlFactory.createWSDLDefinition(); + wsdlDefinition.setUnresolved(true); + wsdlDefinition.setNamespace(model.getNamespace()); + wsdlDefinition = resolver.resolveModel(WSDLDefinition.class, wsdlDefinition); + + if (!wsdlDefinition.isUnresolved()) { + model.setDefinition(wsdlDefinition); + Definition definition = wsdlDefinition.getDefinition(); + if (model.getBindingName() != null) { + model.setBinding(definition.getBinding(model.getBindingName())); + } + if (model.getServiceName() != null) { + Service service = definition.getService(model.getServiceName()); + model.setService(service); + if (service != null && model.getPortName() != null) { + Port port = service.getPort(model.getPortName()); + model.setPort(port); + model.setBinding(port.getBinding()); + } + } + + PortType portType = getPortType(model); + if (portType != null) { + WSDLInterfaceContract interfaceContract = wsdlFactory.createWSDLInterfaceContract(); + WSDLInterface wsdlInterface; + try { + wsdlInterface = wsdlFactory.createWSDLInterface(portType, + wsdlDefinition.getInlinedSchemas(), + resolver); + } catch (InvalidInterfaceException e) { + throw new ContributionResolveException(e); + } + interfaceContract.setInterface(wsdlInterface); + model.setBindingInterfaceContract(interfaceContract); + } + } + policyProcessor.resolvePolicies(model, resolver); + } + + private PortType getPortType(WebServiceBinding model) { + PortType portType = null; + 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(); + } + } else 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(); + } + return portType; + } + + public QName getArtifactType() { + return WebServiceConstants.BINDING_WS_QNAME; + } + + public Class getModelType() { + return WebServiceBinding.class; + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-ws-xml/src/main/java/org/apache/tuscany/sca/binding/ws/xml/WebServiceConstants.java b/tags/java/sca/1.0-RC1b/modules/binding-ws-xml/src/main/java/org/apache/tuscany/sca/binding/ws/xml/WebServiceConstants.java new file mode 100644 index 0000000000..d1e4ba3205 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-ws-xml/src/main/java/org/apache/tuscany/sca/binding/ws/xml/WebServiceConstants.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.ws.xml; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.xml.Constants; + +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"; + + +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-ws-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-ws-xml/src/test/java/org/apache/tuscany/sca/binding/ws/xml/ReadTestCase.java b/tags/java/sca/1.0-RC1b/modules/binding-ws-xml/src/test/java/org/apache/tuscany/sca/binding/ws/xml/ReadTestCase.java new file mode 100644 index 0000000000..0578a1ed96 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-ws-xml/src/test/java/org/apache/tuscany/sca/binding/ws/xml/ReadTestCase.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.ws.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.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.ComponentType; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory; +import org.apache.tuscany.sca.assembly.SCABindingFactory; +import org.apache.tuscany.sca.assembly.builder.impl.CompositeBuilderImpl; +import org.apache.tuscany.sca.assembly.xml.ComponentTypeProcessor; +import org.apache.tuscany.sca.assembly.xml.CompositeProcessor; +import org.apache.tuscany.sca.binding.sca.impl.SCABindingFactoryImpl; +import org.apache.tuscany.sca.binding.ws.DefaultWebServiceBindingFactory; +import org.apache.tuscany.sca.binding.ws.WebServiceBindingFactory; +import org.apache.tuscany.sca.contribution.DefaultModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.impl.ContributionFactoryImpl; +import org.apache.tuscany.sca.contribution.processor.DefaultStAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; +import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; +import org.apache.tuscany.sca.interfacedef.impl.InterfaceContractMapperImpl; +import org.apache.tuscany.sca.interfacedef.wsdl.DefaultWSDLFactory; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLFactory; +import org.apache.tuscany.sca.policy.DefaultPolicyFactory; +import org.apache.tuscany.sca.policy.PolicyFactory; + +/** + * Test reading WSDL interfaces. + * + * @version $Rev$ $Date$ + */ +public class ReadTestCase extends TestCase { + + XMLInputFactory inputFactory; + DefaultStAXArtifactProcessorExtensionPoint staxProcessors; + ExtensibleStAXArtifactProcessor staxProcessor; + private AssemblyFactory assemblyFactory; + private SCABindingFactory scaBindingFactory; + private PolicyFactory policyFactory; + private InterfaceContractMapper mapper; + + @Override + public void setUp() throws Exception { + ModelFactoryExtensionPoint factories = new DefaultModelFactoryExtensionPoint(); + assemblyFactory = new DefaultAssemblyFactory(); + factories.addFactory(assemblyFactory); + scaBindingFactory = new SCABindingFactoryImpl(); + factories.addFactory(scaBindingFactory); + policyFactory = new DefaultPolicyFactory(); + factories.addFactory(policyFactory); + mapper = new InterfaceContractMapperImpl(); + inputFactory = XMLInputFactory.newInstance(); + staxProcessors = new DefaultStAXArtifactProcessorExtensionPoint(new DefaultModelFactoryExtensionPoint()); + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, XMLInputFactory.newInstance(), XMLOutputFactory.newInstance()); + + WebServiceBindingFactory wsFactory = new DefaultWebServiceBindingFactory(); + factories.addFactory(wsFactory); + WSDLFactory wsdlFactory = new DefaultWSDLFactory(); + factories.addFactory(wsdlFactory); + + WebServiceBindingProcessor wsdlProcessor = new WebServiceBindingProcessor(factories); + staxProcessors.addArtifactProcessor(wsdlProcessor); + } + + @Override + public void tearDown() throws Exception { + } + + public void testReadComponentType() throws Exception { + ComponentTypeProcessor componentTypeProcessor = new ComponentTypeProcessor(assemblyFactory, policyFactory, staxProcessor); + InputStream is = getClass().getResourceAsStream("CalculatorImpl.componentType"); + XMLStreamReader reader = inputFactory.createXMLStreamReader(is); + ComponentType componentType = componentTypeProcessor.read(reader); + assertNotNull(componentType); + + //new PrintUtil(System.out).print(componentType); + } + + public void testReadComposite() throws Exception { + CompositeProcessor compositeProcessor = new CompositeProcessor(new ContributionFactoryImpl(), assemblyFactory, policyFactory, mapper, staxProcessor); + InputStream is = getClass().getResourceAsStream("Calculator.composite"); + XMLStreamReader reader = inputFactory.createXMLStreamReader(is); + Composite composite = compositeProcessor.read(reader); + assertNotNull(composite); + + CompositeBuilderImpl compositeUtil = new CompositeBuilderImpl(assemblyFactory, scaBindingFactory, mapper, null, null); + compositeUtil.build(composite); + + //new PrintUtil(System.out).print(composite); + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-ws-xml/src/test/java/org/apache/tuscany/sca/binding/ws/xml/WriteTestCase.java b/tags/java/sca/1.0-RC1b/modules/binding-ws-xml/src/test/java/org/apache/tuscany/sca/binding/ws/xml/WriteTestCase.java new file mode 100644 index 0000000000..42dedc5455 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-ws-xml/src/test/java/org/apache/tuscany/sca/binding/ws/xml/WriteTestCase.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.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.AssemblyFactory; +import org.apache.tuscany.sca.assembly.ComponentType; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory; +import org.apache.tuscany.sca.assembly.xml.ComponentTypeProcessor; +import org.apache.tuscany.sca.assembly.xml.CompositeProcessor; +import org.apache.tuscany.sca.assembly.xml.ConstrainingTypeProcessor; +import org.apache.tuscany.sca.binding.ws.DefaultWebServiceBindingFactory; +import org.apache.tuscany.sca.binding.ws.WebServiceBindingFactory; +import org.apache.tuscany.sca.contribution.DefaultModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.impl.ContributionFactoryImpl; +import org.apache.tuscany.sca.contribution.processor.DefaultStAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; +import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; +import org.apache.tuscany.sca.interfacedef.impl.InterfaceContractMapperImpl; +import org.apache.tuscany.sca.interfacedef.wsdl.DefaultWSDLFactory; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLFactory; +import org.apache.tuscany.sca.policy.DefaultPolicyFactory; +import org.apache.tuscany.sca.policy.PolicyFactory; + +/** + * Test reading/write WSDL interfaces. + * + * @version $Rev$ $Date$ + */ +public class WriteTestCase extends TestCase { + + XMLInputFactory inputFactory; + DefaultStAXArtifactProcessorExtensionPoint staxProcessors; + ExtensibleStAXArtifactProcessor staxProcessor; + private AssemblyFactory factory; + private PolicyFactory policyFactory; + private InterfaceContractMapper mapper; + + @Override + public void setUp() throws Exception { + ModelFactoryExtensionPoint factories = new DefaultModelFactoryExtensionPoint(); + factory = new DefaultAssemblyFactory(); + factories.addFactory(factory); + policyFactory = new DefaultPolicyFactory(); + factories.addFactory(policyFactory); + + mapper = new InterfaceContractMapperImpl(); + inputFactory = XMLInputFactory.newInstance(); + staxProcessors = new DefaultStAXArtifactProcessorExtensionPoint(new DefaultModelFactoryExtensionPoint()); + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, XMLInputFactory.newInstance(), XMLOutputFactory.newInstance()); + + WebServiceBindingFactory wsFactory = new DefaultWebServiceBindingFactory(); + factories.addFactory(wsFactory); + WSDLFactory wsdlFactory = new DefaultWSDLFactory(); + factories.addFactory(wsdlFactory); + + staxProcessors.addArtifactProcessor(new CompositeProcessor(new ContributionFactoryImpl(), factory, policyFactory, mapper, staxProcessor)); + staxProcessors.addArtifactProcessor(new ComponentTypeProcessor(factory, policyFactory, staxProcessor)); + staxProcessors.addArtifactProcessor(new ConstrainingTypeProcessor(factory, policyFactory, staxProcessor)); + + WebServiceBindingProcessor wsdlProcessor = new WebServiceBindingProcessor(factories); + staxProcessors.addArtifactProcessor(wsdlProcessor); + } + + @Override + public void tearDown() throws Exception { + } + + public void testReadWriteComponentType() throws Exception { + InputStream is = getClass().getResourceAsStream("CalculatorImpl.componentType"); + ComponentType componentType = staxProcessor.read(is, ComponentType.class); + assertNotNull(componentType); + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + staxProcessor.write(componentType, bos); + } + + public void testReadWriteComposite() throws Exception { + InputStream is = getClass().getResourceAsStream("Calculator.composite"); + Composite composite = staxProcessor.read(is, Composite.class); + assertNotNull(composite); + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + staxProcessor.write(composite, bos); + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/Calculator.composite b/tags/java/sca/1.0-RC1b/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/Calculator.composite new file mode 100644 index 0000000000..896a901862 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/Calculator.composite @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/CalculatorImpl.componentType b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/example.wsdl b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/example.wsdl @@ -0,0 +1,26 @@ + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/invalid-stockquote.wsdl b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/ipo.xsd b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/stockquote.wsdl b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/test1.wsdl b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/test1.wsdl @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/test1.xsd b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/test1.xsd @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/test2.wsdl b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/test2.wsdl @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/unwrapped-stockquote.wsdl b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-ws/.checkstyle b/tags/java/sca/1.0-RC1b/modules/binding-ws/.checkstyle new file mode 100644 index 0000000000..e3c216986d --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-ws/.checkstyle @@ -0,0 +1,24 @@ + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/binding-ws/.pmd b/tags/java/sca/1.0-RC1b/modules/binding-ws/.pmd new file mode 100644 index 0000000000..2db10d6a6a --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-ws/.pmd @@ -0,0 +1,20 @@ + + +truefalse \ No newline at end of file diff --git a/tags/java/sca/1.0-RC1b/modules/binding-ws/.ruleset b/tags/java/sca/1.0-RC1b/modules/binding-ws/.ruleset new file mode 100644 index 0000000000..ba9b5ce886 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-ws/.ruleset @@ -0,0 +1,190 @@ + + + + PMD Plugin preferences rule set + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/binding-ws/DISCLAIMER b/tags/java/sca/1.0-RC1b/modules/binding-ws/DISCLAIMER new file mode 100644 index 0000000000..d68a410903 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-ws/DISCLAIMER @@ -0,0 +1,8 @@ +Apache Tuscany is an effort undergoing incubation at The Apache Software +Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is +required of all newly accepted projects until a further review indicates that +the infrastructure, communications, and decision making process have stabilized +in a manner consistent with other successful ASF projects. While incubation +status is not necessarily a reflection of the completeness or stability of the +code, it does indicate that the project has yet to be fully endorsed by the ASF. + diff --git a/tags/java/sca/1.0-RC1b/modules/binding-ws/LICENSE b/tags/java/sca/1.0-RC1b/modules/binding-ws/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-ws/NOTICE b/tags/java/sca/1.0-RC1b/modules/binding-ws/NOTICE new file mode 100644 index 0000000000..94481d6cfa --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-ws/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2007 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/tags/java/sca/1.0-RC1b/modules/binding-ws/pom.xml b/tags/java/sca/1.0-RC1b/modules/binding-ws/pom.xml new file mode 100644 index 0000000000..a02fbae365 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-ws/pom.xml @@ -0,0 +1,66 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.0-incubating + ../pom.xml + + tuscany-binding-ws + Apache Tuscany SCA WS Binding Model + + + + org.apache.tuscany.sca + tuscany-assembly + 1.0-incubating + + + + org.apache.tuscany.sca + tuscany-interface-wsdl + 1.0-incubating + + + + wsdl4j + wsdl4j + 1.6.2 + + + + + + + apache.ws.zone + Apache WS Zone Repository + http://ws.zones.apache.org/repository2 + + true + + + false + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/DefaultWebServiceBindingFactory.java b/tags/java/sca/1.0-RC1b/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/DefaultWebServiceBindingFactory.java new file mode 100644 index 0000000000..04f8ab0d3c --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/DefaultWebServiceBindingFactory.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; + +import org.apache.tuscany.sca.binding.ws.impl.WebServiceBindingFactoryImpl; + +/** + * A factory for the WSDL model. + * + * @version $Rev$ $Date$ + */ +public class DefaultWebServiceBindingFactory extends WebServiceBindingFactoryImpl implements WebServiceBindingFactory { + +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/WebServiceBinding.java b/tags/java/sca/1.0-RC1b/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/WebServiceBinding.java new file mode 100644 index 0000000000..4dbee3f2ae --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/WebServiceBinding.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.binding.ws; + +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.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLDefinition; +import org.w3c.dom.Document; +import org.w3c.dom.Element; + + +/** + * Represents a WebService binding. + * + * @version $Rev$ $Date$ + */ +public interface WebServiceBinding extends Binding { + + /** + * 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 className 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 className 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 className 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 className 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 port 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 binding. + * @return the WSDL binding + */ + WSDLDefinition getWSDLDefinition(); + + /** + * Sets the WSDL binding + * @param binding the WSDL binding + */ + void setDefinition(WSDLDefinition wsdlDefinition); + + /** + * Returns the WSDL namespace. + * @return the WSDL namespace + */ + String getNamespace(); + + /** + * Sets the WSDL namespace + * @param namspace the WSDL namspace + */ + 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); +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/WebServiceBindingFactory.java b/tags/java/sca/1.0-RC1b/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/WebServiceBindingFactory.java new file mode 100644 index 0000000000..1ad38c69e4 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/addressing/EndPointReference.java b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/impl/WebServiceBindingFactoryImpl.java b/tags/java/sca/1.0-RC1b/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/impl/WebServiceBindingFactoryImpl.java new file mode 100644 index 0000000000..8902dd04ee --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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 abstract class WebServiceBindingFactoryImpl implements WebServiceBindingFactory { + + public WebServiceBinding createWebServiceBinding() { + return new WebServiceBindingImpl(); + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/impl/WebServiceBindingImpl.java b/tags/java/sca/1.0-RC1b/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/impl/WebServiceBindingImpl.java new file mode 100644 index 0000000000..792a0fd577 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/impl/WebServiceBindingImpl.java @@ -0,0 +1,263 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, 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.Port; +import javax.wsdl.Service; +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.Extensible; +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, Extensible { + private String name; + private String uri; + private boolean unresolved; + private List extensions = new ArrayList(); + private List requiredIntents = new ArrayList(); + private List policySets = new ArrayList(); + private IntentAttachPointType intentAttachPointType; + + 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; + + 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; + } + + public List getExtensions() { + return extensions; + } + + public String getLocation() { + return location; + } + + public void setLocation(String location) { + this.location = location; + } + + public Binding 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; + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/contribution-impl/.checkstyle b/tags/java/sca/1.0-RC1b/modules/contribution-impl/.checkstyle new file mode 100644 index 0000000000..ace5fe6f53 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution-impl/.checkstyle @@ -0,0 +1,25 @@ + + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/contribution-impl/.pmd b/tags/java/sca/1.0-RC1b/modules/contribution-impl/.pmd new file mode 100644 index 0000000000..84af2f4d5d --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution-impl/.pmd @@ -0,0 +1,20 @@ + + +true diff --git a/tags/java/sca/1.0-RC1b/modules/contribution-impl/.ruleset b/tags/java/sca/1.0-RC1b/modules/contribution-impl/.ruleset new file mode 100644 index 0000000000..ac8671859d --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution-impl/.ruleset @@ -0,0 +1,190 @@ + + + + PMD Plugin preferences rule set + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/contribution-impl/DISCLAIMER b/tags/java/sca/1.0-RC1b/modules/contribution-impl/DISCLAIMER new file mode 100644 index 0000000000..d68a410903 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution-impl/DISCLAIMER @@ -0,0 +1,8 @@ +Apache Tuscany is an effort undergoing incubation at The Apache Software +Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is +required of all newly accepted projects until a further review indicates that +the infrastructure, communications, and decision making process have stabilized +in a manner consistent with other successful ASF projects. While incubation +status is not necessarily a reflection of the completeness or stability of the +code, it does indicate that the project has yet to be fully endorsed by the ASF. + diff --git a/tags/java/sca/1.0-RC1b/modules/contribution-impl/LICENSE b/tags/java/sca/1.0-RC1b/modules/contribution-impl/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/contribution-impl/NOTICE b/tags/java/sca/1.0-RC1b/modules/contribution-impl/NOTICE new file mode 100644 index 0000000000..94481d6cfa --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution-impl/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2007 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/tags/java/sca/1.0-RC1b/modules/contribution-impl/pom.xml b/tags/java/sca/1.0-RC1b/modules/contribution-impl/pom.xml new file mode 100644 index 0000000000..c4df54a714 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution-impl/pom.xml @@ -0,0 +1,57 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.0-incubating + ../pom.xml + + tuscany-contribution-impl + Apache Tuscany SCA Contribution Model Implementation + + + + org.apache.tuscany.sca + tuscany-contribution + 1.0-incubating + + + + org.apache.tuscany.sca + tuscany-contribution-java + 1.0-incubating + + + + org.apache.tuscany.sca + tuscany-contribution-namespace + 1.0-incubating + + + + org.codehaus.woodstox + wstx-asl + 3.2.1 + runtime + + + diff --git a/tags/java/sca/1.0-RC1b/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/impl/ArtifactImpl.java b/tags/java/sca/1.0-RC1b/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/impl/ArtifactImpl.java new file mode 100644 index 0000000000..f7600e5a83 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/impl/ArtifactImpl.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.contribution.impl; + +import org.apache.tuscany.sca.contribution.Artifact; + + +/** + * Base Artifact interface to accomodate common properties between Contribution and Deployed Artifact + * + * @version $Rev$ $Date$ + */ +public abstract class ArtifactImpl implements Artifact { + private String uri; + private String location; + + protected ArtifactImpl() { + } + + public String getLocation() { + return this.location; + } + + public void setLocation(String location) { + this.location = location; + } + + public String getURI() { + return this.uri; + } + + public void setURI(String uri) { + this.uri = uri; + } + + @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; + } + } + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/impl/ContributionFactoryImpl.java b/tags/java/sca/1.0-RC1b/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/impl/ContributionFactoryImpl.java new file mode 100644 index 0000000000..1ef7a98f9e --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/impl/ContributionFactoryImpl.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.impl; + +import org.apache.tuscany.sca.contribution.Contribution; +import org.apache.tuscany.sca.contribution.ContributionFactory; +import org.apache.tuscany.sca.contribution.DeployedArtifact; + + +/** + * Contribution model object factory + * + * @version $Rev$ $Date$ + */ +public class ContributionFactoryImpl implements ContributionFactory { + + public Contribution createContribution() { + return new ContributionImpl(); + } + + public DeployedArtifact createDeployedArtifact() { + return new DeployedArtifactImpl(); + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/impl/ContributionImpl.java b/tags/java/sca/1.0-RC1b/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/impl/ContributionImpl.java new file mode 100644 index 0000000000..1e4688584b --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/impl/ContributionImpl.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.impl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.sca.assembly.Composite; +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.DeployedArtifact; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; + +/** + * The representation of a deployed contribution + * + * @version $Rev$ $Date$ + */ +public class ContributionImpl extends ArtifactImpl implements Contribution { + private List exports = new ArrayList(); + private List imports = new ArrayList(); + private List deployables = new ArrayList(); + private ModelResolver modelResolver; + + /** + * A list of artifacts in the contribution + */ + private List artifacts = new ArrayList(); + + protected ContributionImpl() { + } + + public List getExports() { + return exports; + } + + public List getImports() { + return imports; + } + + public List getDeployables() { + return deployables; + } + + public List getArtifacts() { + return artifacts; + } + + public ModelResolver getModelResolver() { + return modelResolver; + } + + public void setModelResolver(ModelResolver modelResolver) { + this.modelResolver = modelResolver; + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/impl/DeployedArtifactImpl.java b/tags/java/sca/1.0-RC1b/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/impl/DeployedArtifactImpl.java new file mode 100644 index 0000000000..f3a688140c --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/impl/DeployedArtifactImpl.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.impl; + +import org.apache.tuscany.sca.contribution.DeployedArtifact; + +/** + * Representation of a deployed artifact + * + * @version $Rev$ $Date$ + */ +public class DeployedArtifactImpl extends ArtifactImpl implements DeployedArtifact { + private Object modelObject; + + protected DeployedArtifactImpl() { + super(); + } + + public Object getModel() { + return modelObject; + } + + public void setModel(Object modelObject) { + this.modelObject = modelObject; + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/FolderContributionProcessor.java b/tags/java/sca/1.0-RC1b/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/FolderContributionProcessor.java new file mode 100644 index 0000000000..8d2d91c375 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/FolderContributionProcessor.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.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.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.sca.contribution.ContentType; +import org.apache.tuscany.sca.contribution.processor.PackageProcessor; +import org.apache.tuscany.sca.contribution.service.ContributionException; +import org.apache.tuscany.sca.contribution.service.util.FileHelper; + +/** + * Folder contribution package processor + * + * @version $Rev$ $Date$ + */ +public class FolderContributionProcessor implements PackageProcessor { + /** + * Package-type that this package processor can handle + */ + public static final String PACKAGE_TYPE = ContentType.FOLDER; + + public FolderContributionProcessor() { + } + + public String getPackageType() { + return PACKAGE_TYPE; + } + + /** + * Recursively traverse a root directory + * + * @param fileList + * @param file + * @throws IOException + */ + private void traverse(List fileList, File file, File root) throws IOException { + if (file.isFile()) { + fileList.add(root.toURI().relativize(file.toURI())); + + } else if (file.isDirectory()) { + // FIXME: Maybe we should externalize it as a property + // Regular expression to exclude .xxx files + + String uri = root.toURI().relativize(file.toURI()).toString(); + if (uri.endsWith("/")) { + uri = uri.substring(0, uri.length() - 1); + } + fileList.add(URI.create(uri)); + + //FIXME Do we really need to use a regexp here to filter out + // file names that start one or two dots? + File[] files = file.listFiles(FileHelper.getFileFilter("[^\u002e].*", true)); + for (int i = 0; i < files.length; i++) { + traverse(fileList, files[i], root); + } + } + } + + public URL getArtifactURL(URL sourceURL, URI artifact) throws MalformedURLException { + return new URL(sourceURL, artifact.toString()); + } + + /** + * Get a list of artifact URI from the folder + * + * @return The list of artifact URI for the folder + * @throws IOException + */ + 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(); + + // Assume the root is a jar file + File rootFolder; + + try { + rootFolder = new File(packageSourceURL.toURI()); + if (rootFolder.isDirectory()) { + if (!rootFolder.exists()) { + throw new InvalidFolderContributionException(rootFolder.getAbsolutePath()); + } + + this.traverse(artifacts, rootFolder, rootFolder); + } + + } catch (URISyntaxException e) { + throw new InvalidFolderContributionURIException(packageSourceURL.toExternalForm(), e); + } + + return artifacts; + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/InvalidFolderContributionException.java b/tags/java/sca/1.0-RC1b/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/InvalidFolderContributionException.java new file mode 100644 index 0000000000..268ba401c1 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/InvalidFolderContributionException.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.processor.impl; + +import org.apache.tuscany.sca.contribution.service.ContributionException; + +/** + * Exception that indicates that the supplied XML Document invalid. + * + */ +public class InvalidFolderContributionException extends ContributionException { + + private static final long serialVersionUID = 1564255850052593282L; + + protected InvalidFolderContributionException(String componentDefinitionLocatoin) { + super(componentDefinitionLocatoin); + } + + protected InvalidFolderContributionException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/InvalidFolderContributionURIException.java b/tags/java/sca/1.0-RC1b/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/InvalidFolderContributionURIException.java new file mode 100644 index 0000000000..e018f90b06 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/InvalidFolderContributionURIException.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.processor.impl; + +import org.apache.tuscany.sca.contribution.service.ContributionException; + +/** + * Exception that indicates that the supplied XML Document invalid. + * + */ +public class InvalidFolderContributionURIException extends ContributionException { + + private static final long serialVersionUID = 1564255850052593282L; + + protected InvalidFolderContributionURIException(String componentDefinitionLocatoin) { + super(componentDefinitionLocatoin); + } + + protected InvalidFolderContributionURIException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/JarContributionProcessor.java b/tags/java/sca/1.0-RC1b/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/JarContributionProcessor.java new file mode 100644 index 0000000000..9015dc5f7f --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/JarContributionProcessor.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.contribution.processor.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.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.ContentType; +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 { + /** + * Package-type that this package processor can handle + */ + public static final String PACKAGE_TYPE = ContentType.JAR; + + public JarContributionProcessor() { + } + + public String getPackageType() { + return PACKAGE_TYPE; + } + + public URL getArtifactURL(URL sourceURL, URI artifact) throws MalformedURLException { + if (sourceURL.toString().startsWith("jar:")) { + return new URL(sourceURL, artifact.toString()); + } else { + return new URL("jar:" + sourceURL.toExternalForm() + "!/" + artifact); + } + } + + 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) { + artifacts.add(URI.create(name)); + } + return artifacts; + + } finally { + jar.close(); + } + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/resolver/impl/ModelResolverImpl.java b/tags/java/sca/1.0-RC1b/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/resolver/impl/ModelResolverImpl.java new file mode 100644 index 0000000000..6c2257803a --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/resolver/impl/ModelResolverImpl.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.contribution.resolver.impl; + +import java.lang.ref.WeakReference; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.tuscany.sca.contribution.resolver.ClassReference; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; + +/** + * A default implementation of an artifact resolver, based on a map. + * + * @version $Rev$ $Date$ + */ +public class ModelResolverImpl implements ModelResolver { + private static final long serialVersionUID = -7826976465762296634L; + + private Map map = new HashMap(); + + private WeakReference classLoader; + + public ModelResolverImpl(ClassLoader classLoader) { + this.classLoader = new WeakReference(classLoader); + } + + 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; + try { + clazz = Class.forName(classReference.getClassName(), true, classLoader.get()); + } catch (ClassNotFoundException e) { + + // Return the unresolved object + return unresolved; + } + + // Store a new ClassReference wrappering the loaded class + resolved = new ClassReference(clazz); + map.put(resolved, resolved); + + // Return the resolved ClassReference + 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); + } + + public Collection getModels() { + return map.values(); + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/ArtifactTypeDescriberImpl.java b/tags/java/sca/1.0-RC1b/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/ArtifactTypeDescriberImpl.java new file mode 100644 index 0000000000..76318c6021 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/ArtifactTypeDescriberImpl.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.service.impl; + +import java.io.IOException; +import java.net.URL; +import java.net.URLConnection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.tuscany.sca.contribution.ContentType; +import org.apache.tuscany.sca.contribution.Contribution; +import org.apache.tuscany.sca.contribution.service.TypeDescriber; +import org.apache.tuscany.sca.contribution.service.util.FileHelper; + +/** + * Implementation of the content describer for files + * + * @version $Rev$ $Date$ + */ +public class ArtifactTypeDescriberImpl implements TypeDescriber { + private final Map contentTypeRegistry = new HashMap(); + + public ArtifactTypeDescriberImpl() { + super(); + init(); + } + + /** + * Initialize contentType registry with know types based on known file extensions + */ + private void init() { + contentTypeRegistry.put("COMPOSITE", ContentType.COMPOSITE); + contentTypeRegistry.put("SCDL", ContentType.COMPOSITE); + contentTypeRegistry.put("WSDL", ContentType.WSDL); + contentTypeRegistry.put("JAR", ContentType.JAR); + } + + 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 correc one + * @return The content type + */ + public String getType(URL resourceURL, String defaultContentType) { + URLConnection connection = null; + String contentType = defaultContentType; + + if (resourceURL.getProtocol().equals("file") && FileHelper.toFile(resourceURL).isDirectory()) { + // Special case : contribution is a folder + contentType = ContentType.FOLDER; + } else if (resourceURL.toExternalForm().endsWith(Contribution.SCA_CONTRIBUTION_META) + || resourceURL.toExternalForm().endsWith(Contribution.SCA_CONTRIBUTION_GENERATED_META)) { + // Special case : contribution metadata + contentType = ContentType.CONTRIBUTION_METADATA; + } else { + contentType = resolveContentyTypeByExtension(resourceURL); + if (contentType == null) { + try { + connection = resourceURL.openConnection(); + 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/tags/java/sca/1.0-RC1b/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/ContributionMetadataDocumentProcessor.java b/tags/java/sca/1.0-RC1b/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/ContributionMetadataDocumentProcessor.java new file mode 100644 index 0000000000..8189914ffb --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/ContributionMetadataDocumentProcessor.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.contribution.service.impl; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.contribution.Contribution; +import org.apache.tuscany.sca.contribution.ContributionFactory; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; + +/** + * MetadataDocumentProcessor that handles contribution metadata files + * + * @version $Rev$ $Date$ + */ +public class ContributionMetadataDocumentProcessor { + protected final URLClassLoader classLoader; + protected final StAXArtifactProcessor staxProcessor; + protected final AssemblyFactory assemblyFactory; + protected final ContributionFactory contributionFactory; + protected final XMLInputFactory inputFactory; + + public ContributionMetadataDocumentProcessor(URLClassLoader classLoader, StAXArtifactProcessor staxProcessor, AssemblyFactory assemblyFactory, ContributionFactory contributionFactory, XMLInputFactory inputFactory) { + super(); + this.classLoader = classLoader; + this.staxProcessor = staxProcessor; + this.assemblyFactory = assemblyFactory; + this.contributionFactory = contributionFactory; + this.inputFactory = inputFactory; + } + + private Contribution mergeContributionMetadata(Contribution contrib1, Contribution contrib2 ) { + contrib1.getDeployables().addAll(contrib2.getDeployables()); + contrib1.getImports().addAll(contrib2.getImports()); + contrib1.getExports().addAll(contrib2.getExports()); + + return contrib1; + } + + public void read(Contribution contribution) throws XMLStreamException, ContributionReadException { + List artifactList = new ArrayList(2); + //set generated first, as the user created one ovverrides generated information + artifactList.add(this.classLoader.getResource(Contribution.SCA_CONTRIBUTION_GENERATED_META)); + artifactList.add(this.classLoader.getResource(Contribution.SCA_CONTRIBUTION_META)); + + URL artifactURL = null; + InputStream artifactStream = null; + Iterator artifactIterator = artifactList.iterator(); + while( artifactIterator.hasNext() ){ + + try { + artifactURL = (URL) artifactIterator.next(); + if( artifactURL != null) { + artifactStream = artifactURL.openStream(); + XMLStreamReader reader = inputFactory.createXMLStreamReader(artifactStream); + reader.nextTag(); + + Contribution contributionMetadata = (Contribution) staxProcessor.read(reader); + if (contributionMetadata != null) { + this.mergeContributionMetadata(contribution, contributionMetadata); + } + } + + } catch (XMLStreamException e) { + throw new ContributionReadException(e); + } catch (IOException e) { + throw new ContributionReadException(e); + } finally { + try { + if (artifactStream != null) { + artifactStream.close(); + artifactStream = null; + } + } catch (IOException ioe) { + //ignore + } + } + } + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/ContributionMetadataProcessor.java b/tags/java/sca/1.0-RC1b/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/ContributionMetadataProcessor.java new file mode 100644 index 0000000000..de38db1945 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/ContributionMetadataProcessor.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.service.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.AssemblyFactory; +import org.apache.tuscany.sca.assembly.Composite; +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.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; + +/** + * Processor responsible for loading particular elements from contribution metadata file + * + * @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 = new QName(SCA10_NS, "contribution"); + private static final QName DEPLOYABLE = new QName(SCA10_NS, "deployable"); + + private final AssemblyFactory assemblyFactory; + private final ContributionFactory contributionFactory; + + private final StAXArtifactProcessor extensionProcessor; + + public ContributionMetadataProcessor(AssemblyFactory assemblyFactory, ContributionFactory contributionFactory, StAXArtifactProcessor extensionProcessor) { + super(); + this.assemblyFactory = assemblyFactory; + this.contributionFactory = contributionFactory; + this.extensionProcessor = extensionProcessor; + } + + + public QName getArtifactType() { + return CONTRIBUTION; + } + + public Class getModelType() { + return Contribution.class; + } + + public Contribution read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + Contribution contribution = null; + + QName element = null; + while (reader.hasNext()) { + int event = reader.getEventType(); + switch (event) { + case START_ELEMENT: + element = reader.getName(); + + if (CONTRIBUTION.equals(element)) { + + // Read + contribution = this.contributionFactory.createContribution(); + + } else if (DEPLOYABLE.equals(element)) { + + + // Read + QName compositeName = getQName(reader, "composite"); + if (compositeName == null) { + throw new ContributionReadException("Attribute 'composite' is missing"); + } + + 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); + } + } + } + break; + + case XMLStreamConstants.END_ELEMENT: + if (CONTRIBUTION.equals(reader.getName())) { + return contribution; + } + break; + } + + //Read the next element + if (reader.hasNext()) { + reader.next(); + } + } + + return contribution; + } + + public void write(Contribution contribution, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException { + + // Write + writeStartDocument(writer, CONTRIBUTION.getNamespaceURI(), CONTRIBUTION.getLocalPart()); + + // Write imports + for (Import imp: contribution.getImports()) { + extensionProcessor.write(imp, writer); + } + + // Write exports + for (Export export: contribution.getExports()) { + extensionProcessor.write(export, writer); + } + + // Write elements + for (Composite deployable: contribution.getDeployables()) { + writeStart(writer, DEPLOYABLE.getNamespaceURI(), DEPLOYABLE.getLocalPart(), + new XAttr("composite", deployable.getName())); + writeEnd(writer); + } + + writeEndDocument(writer); + } + + public void resolve(Contribution model, ModelResolver resolver) throws ContributionResolveException { + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/ContributionRepositoryImpl.java b/tags/java/sca/1.0-RC1b/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/ContributionRepositoryImpl.java new file mode 100644 index 0000000000..d53693d875 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/ContributionRepositoryImpl.java @@ -0,0 +1,297 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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.security.AccessController; +import java.security.PrivilegedAction; +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; + +/** + * 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 final File rootFile; + private Map contributionLocations = new HashMap(); + + private Map contributionMap = new HashMap(); + private List contributions = new ArrayList(); + + private URI domain; + private XMLInputFactory factory; + + /** + * Constructor with repository root + * + * @param repository + * @param factory + */ + public ContributionRepositoryImpl(final String repository, XMLInputFactory factory) throws IOException { + String root = repository; + if (repository == 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; + } + }); + } + this.rootFile = new File(root); + this.domain = rootFile.toURI(); + FileHelper.forceMkdir(rootFile); + if (!rootFile.exists() || !rootFile.isDirectory() || !rootFile.canRead()) { + throw new IOException("The root is not a directory: " + repository); + } + this.factory = factory; + } + + public URI getDomain() { + return domain; + } + + /** + * 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); + } + + /** + * 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 + */ + public 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); + } + } + + public URL store(String contribution, URL sourceURL, InputStream contributionStream) throws IOException { + // where the file should be stored in the repository + File location = mapToFile(sourceURL); + FileHelper.forceMkdir(location.getParentFile()); + + copy(contributionStream, location); + + // add contribution to repositoryContent + URL contributionURL = location.toURL(); + URI relative = rootFile.toURI().relativize(location.toURI()); + contributionLocations.put(contribution, relative.toString()); + saveMap(); + + return contributionURL; + } + + public URL store(String contribution, URL sourceURL) throws IOException { + // where the file should be stored in the repository + File location = mapToFile(sourceURL); + File source = FileHelper.toFile(sourceURL); + if (source == null || source.isFile()) { + InputStream is = sourceURL.openStream(); + 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 (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 + throw new AssertionError(e); + } + } + + public void remove(String contribution) { + 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()); + } + + public void init() { + File domainFile = new File(rootFile, "sca-domain.xml"); + if (!domainFile.isFile()) { + return; + } + FileInputStream is; + try { + is = new FileInputStream(domainFile); + } catch (FileNotFoundException e) { + 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); + } + } + + 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) { + throw new IllegalArgumentException(e); + } finally { + IOHelper.closeQuietly(os); + } + } + + public void destroy() { + } + + 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); + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/ContributionServiceImpl.java b/tags/java/sca/1.0-RC1b/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/ContributionServiceImpl.java new file mode 100644 index 0000000000..5621a678d9 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/ContributionServiceImpl.java @@ -0,0 +1,411 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URL; +import java.net.URLClassLoader; +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.Contribution; +import org.apache.tuscany.sca.contribution.ContributionFactory; +import org.apache.tuscany.sca.contribution.DeployedArtifact; +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.util.IOHelper; + +/** + * Service interface that manages artifacts contributed to a Tuscany runtime. + * + * @version $Rev$ $Date$ + */ +/** + * + */ +public class ContributionServiceImpl implements ContributionService { + + /** + * 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 facotry + */ + private ContributionFactory contributionFactory; + + private ModelResolver domainResolver; + + + public ContributionServiceImpl(ContributionRepository repository, + PackageProcessor packageProcessor, + URLArtifactProcessor documentProcessor, + StAXArtifactProcessor staxProcessor, + ExtensibleContributionListener contributionListener, + ModelResolver domainResolver, + ModelResolverExtensionPoint modelResolvers, + ModelFactoryExtensionPoint modelFactories, + AssemblyFactory assemblyFactory, + ContributionFactory contributionFactory, + XMLInputFactory xmlFactory) { + super(); + 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.domainResolver = domainResolver; + } + + public Contribution contribute(String contributionURI, URL sourceURL, boolean storeInRepository) + throws ContributionException, IOException { + if (contributionURI == null) { + throw new IllegalArgumentException("URI for the contribution is null"); + } + if (sourceURL == null) { + 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) { + throw new IllegalArgumentException("URI for the contribution is null"); + } + if (sourceURL == null) { + 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 { + DeployedArtifact artifact = this.contributionFactory.createDeployedArtifact(); + 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 metada 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 = null; + + URL[] clUrls = {sourceURL}; + URLClassLoader cl = new URLClassLoader(clUrls, null); + + ContributionMetadataDocumentProcessor metadataDocumentProcessor = + new ContributionMetadataDocumentProcessor(cl, staxProcessor, assemblyFactory, contributionFactory, xmlFactory); + contributionMetadata = contributionFactory.createContribution(); + try { + metadataDocumentProcessor.read(contributionMetadata); + } catch (XMLStreamException e) { + throw new InvalidContributionMetadataException("Invalid contribution metadata for contribution."); + } + + // 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; + } + + /** + * 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) { + 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); + } + } + + //initialize contribution based on it's metadata if available + Contribution contribution = readContributionMetadata(locationURL); + + // Create contribution model resolver + if (modelResolver == null) { + modelResolver = new ExtensibleModelResolver(contribution, modelResolvers, modelFactories); + } + + if ( modelResolver instanceof ExtensibleModelResolver ) { + ((ExtensibleModelResolver)modelResolver).setDomainResolver(domainResolver); + } + + //set contribution initial information + contribution.setURI(contributionURI.toString()); + contribution.setLocation(locationURL.toString()); + contribution.setModelResolver(modelResolver); + + List contributionArtifacts = null; + + //NOTE: if a contribution is stored on the repository + //the stream would be consumed at this point + if (storeInRepository || contributionStream == null) { + contributionStream = sourceURL.openStream(); + 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 + processReadPhase(contribution, contributionArtifacts); + + // + 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 (DeployedArtifact 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); + } + } + } + } + + // store the contribution on the registry + this.contributionRepository.addContribution(contribution); + + return contribution; + } + + /** + * 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 { + + ModelResolver modelResolver = contribution.getModelResolver(); + URL contributionURL = new URL(contribution.getLocation()); + for (URI a : artifacts) { + URL artifactURL = packageProcessor.getArtifactURL(new URL(contribution.getLocation()), a); + + // Add the deployed artifact model to the resolver + DeployedArtifact artifact = this.contributionFactory.createDeployedArtifact(); + artifact.setURI(a.toString()); + artifact.setLocation(artifactURL.toString()); + contribution.getArtifacts().add(artifact); + modelResolver.addModel(artifact); + + // Let the artifact processor read the artifact into a model + Object model = this.artifactProcessor.read(contributionURL, a, 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 { + // for each artifact that was processed on the contribution + for (DeployedArtifact artifact : contribution.getArtifacts()) { + // 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/tags/java/sca/1.0-RC1b/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/InvalidContributionMetadataException.java b/tags/java/sca/1.0-RC1b/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/InvalidContributionMetadataException.java new file mode 100644 index 0000000000..6fbf46a5b4 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/InvalidContributionMetadataException.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.service.impl; + +import org.apache.tuscany.sca.contribution.service.ContributionException; + +/** + * Exception that indicates that the supplied XML Document invalid. + * + * @version $Rev$ $Date$ + */ +public class InvalidContributionMetadataException extends ContributionException { + + private static final long serialVersionUID = -3184477070625689942L; + + protected InvalidContributionMetadataException() { + } + + protected InvalidContributionMetadataException(String message) { + super(message); + } + + protected InvalidContributionMetadataException(String message, String identifier) { + super(message, identifier); + } + + protected InvalidContributionMetadataException(String message, Throwable cause) { + super(message, cause); + } + + protected InvalidContributionMetadataException(String message, String identifier, Throwable cause) { + super(message, identifier, cause); + } + + protected InvalidContributionMetadataException(Throwable cause) { + super(cause); + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/InvalidContributionURIException.java b/tags/java/sca/1.0-RC1b/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/InvalidContributionURIException.java new file mode 100644 index 0000000000..e243294bd0 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/InvalidContributionURIException.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.service.impl; + +import org.apache.tuscany.sca.contribution.service.ContributionException; + +/** + * Exception that indicates that the supplied contribution URI is invalid or inexistent. + * + * @version $Rev$ $Date$ + */ +public class InvalidContributionURIException extends ContributionException { + + private static final long serialVersionUID = -3184477070625689942L; + + protected InvalidContributionURIException() { + } + + protected InvalidContributionURIException(String message) { + super(message); + } + + protected InvalidContributionURIException(String message, String identifier) { + super(message, identifier); + } + + protected InvalidContributionURIException(String message, Throwable cause) { + super(message, cause); + } + + protected InvalidContributionURIException(String message, String identifier, Throwable cause) { + super(message, identifier, cause); + } + + protected InvalidContributionURIException(Throwable cause) { + super(cause); + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/PackageTypeDescriberImpl.java b/tags/java/sca/1.0-RC1b/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/PackageTypeDescriberImpl.java new file mode 100644 index 0000000000..165c9d0616 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/PackageTypeDescriberImpl.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.service.impl; + +import java.io.IOException; +import java.net.URL; +import java.net.URLConnection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.tuscany.sca.contribution.ContentType; +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("JAR", ContentType.JAR); + } + + 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 correc one + * @return The content type + */ + public String getType(URL resourceURL, String defaultContentType) { + URLConnection connection = null; + String contentType = defaultContentType; + + if (resourceURL.getProtocol().equals("file") && FileHelper.toFile(resourceURL).isDirectory()) { + // Special case : contribution is a folder + contentType = ContentType.FOLDER; + } else { + contentType = resolveContentyTypeByExtension(resourceURL); + if (contentType == null) { + try { + connection = resourceURL.openConnection(); + 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/tags/java/sca/1.0-RC1b/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/util/FileHelper.java b/tags/java/sca/1.0-RC1b/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/util/FileHelper.java new file mode 100644 index 0000000000..bc63dca4a8 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/util/FileHelper.java @@ -0,0 +1,704 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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 = '\\'; + + protected FileHelper() { + } + + /** + * 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/tags/java/sca/1.0-RC1b/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/util/IOHelper.java b/tags/java/sca/1.0-RC1b/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/util/IOHelper.java new file mode 100644 index 0000000000..c8cc056b8f --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/util/IOHelper.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.service.util; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.JarURLConnection; +import java.net.URL; +import java.util.jar.JarFile; + +public class IOHelper { + /** + * The default buffer size to use. + */ + private static final int DEFAULT_BUFFER_SIZE = 1024 * 4; + + protected IOHelper() { + + } + + /** + * 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 { + is = url.openStream(); + } + } + + 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/tags/java/sca/1.0-RC1b/modules/contribution-impl/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.ContributionFactory b/tags/java/sca/1.0-RC1b/modules/contribution-impl/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.ContributionFactory new file mode 100644 index 0000000000..e935f6eb63 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution-impl/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.impl.ContributionFactoryImpl \ No newline at end of file diff --git a/tags/java/sca/1.0-RC1b/modules/contribution-impl/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.PackageProcessor b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/processor/FolderContributionPackageProcessorTestCase.java b/tags/java/sca/1.0-RC1b/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/processor/FolderContributionPackageProcessorTestCase.java new file mode 100644 index 0000000000..7daf302487 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/processor/FolderContributionPackageProcessorTestCase.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.io.File; +import java.net.URI; +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 = "."; + + private File contributionRoot; + + @Override + protected void setUp() throws Exception { + this.contributionRoot = new File(FOLDER_CONTRIBUTION); + } + + public final void testProcessPackageArtifacts() throws Exception { + FolderContributionProcessor folderProcessor = new FolderContributionProcessor(); + + List artifacts = folderProcessor.getArtifacts(contributionRoot.toURL(), null); + assertNotNull(artifacts); + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/processor/JarContributionPackageProcessorTestCase.java b/tags/java/sca/1.0-RC1b/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/processor/JarContributionPackageProcessorTestCase.java new file mode 100644 index 0000000000..6ed735292f --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/processor/JarContributionPackageProcessorTestCase.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.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"; + + @Override + protected void setUp() throws Exception { + } + + 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/tags/java/sca/1.0-RC1b/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/processor/URLartifactProcessorExtensionPointTestCase.java b/tags/java/sca/1.0-RC1b/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/processor/URLartifactProcessorExtensionPointTestCase.java new file mode 100644 index 0000000000..d3dd49ca5f --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/processor/URLartifactProcessorExtensionPointTestCase.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.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; + + +/** + * 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 { + URLArtifactProcessorExtensionPoint artifactProcessors; + + @Override + protected void setUp() throws Exception { + artifactProcessors = new DefaultURLArtifactProcessorExtensionPoint(null); + artifactProcessors.addArtifactProcessor(new FileTypeArtifactProcessor()); + artifactProcessors.addArtifactProcessor(new FileNameArtifactProcessor()); + } + + + public final void testFileTypeProcessor() { + URLArtifactProcessor processor = null; + + processor = artifactProcessors.getProcessor(".m1"); + assertNotNull(processor); + } + + + public final void testFileNameProcessor() { + URLArtifactProcessor processor = null; + + processor = artifactProcessors.getProcessor("file.m2"); + assertNotNull(processor); + + } + + @Override + protected void tearDown() throws Exception { + } + + /** + * Internal mock classes + * + */ + + class M1 { + + } + + class M2 { + + } + + 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 { + //stub + } + + public String getArtifactType() { + return ".m1"; + } + + public Class getModelType() { + return M1.class; + } + } + + 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 { + //stub + } + + public String getArtifactType() { + return "file.m2"; + } + + public Class getModelType() { + return M2.class; + } + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/resolver/ArtifactResolverTestCase.java b/tags/java/sca/1.0-RC1b/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/resolver/ArtifactResolverTestCase.java new file mode 100644 index 0000000000..510febf07a --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/resolver/ArtifactResolverTestCase.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.resolver; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.contribution.ContributionFactory; +import org.apache.tuscany.sca.contribution.DeployedArtifact; +import org.apache.tuscany.sca.contribution.impl.ContributionFactoryImpl; +import org.apache.tuscany.sca.contribution.resolver.impl.ModelResolverImpl; + +/** + * Test DefaultArtifactResolver. + * + * @version $Rev$ $Date$ + */ +public class ArtifactResolverTestCase extends TestCase { + + private ModelResolver resolver; + private ContributionFactory factory; + + @Override + protected void setUp() throws Exception { + resolver = new ModelResolverImpl(getClass().getClassLoader()); + factory = new ContributionFactoryImpl(); + } + + @Override + protected void tearDown() throws Exception { + } + + 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 testResolveClass() { + ClassReference ref = new ClassReference(getClass().getName()); + ClassReference clazz = resolver.resolveModel(ClassReference.class, ref); + assertTrue(clazz.getJavaClass() == getClass()); + } + + public void testUnresolvedClass() { + ClassReference ref = new ClassReference("NonExistentClass"); + ClassReference clazz = resolver.resolveModel(ClassReference.class, ref); + assertTrue(clazz.isUnresolved()); + assertTrue(clazz.getJavaClass() == null); + } + + public void testResolvedArtifact() { + DeployedArtifact artifact = factory.createDeployedArtifact(); + artifact.setURI("foo/bar"); + resolver.addModel(artifact); + DeployedArtifact x = factory.createDeployedArtifact(); + x.setURI("foo/bar"); + x = resolver.resolveModel(DeployedArtifact.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/tags/java/sca/1.0-RC1b/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/resolver/ExtensibleArtifactResolverTestCase.java b/tags/java/sca/1.0-RC1b/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/resolver/ExtensibleArtifactResolverTestCase.java new file mode 100644 index 0000000000..c76c859a25 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/resolver/ExtensibleArtifactResolverTestCase.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.resolver; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.contribution.ContributionFactory; +import org.apache.tuscany.sca.contribution.DefaultModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.DeployedArtifact; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.impl.ContributionFactoryImpl; + +/** + * Test DefaultArtifactResolver. + * + * @version $Rev$ $Date$ + */ +public class ExtensibleArtifactResolverTestCase extends TestCase { + private ExtensibleModelResolver resolver; + + private ContributionFactory factory; + + @Override + protected void setUp() throws Exception { + + ModelResolverExtensionPoint resolvers = new DefaultModelResolverExtensionPoint(); + resolvers.addResolver(Model.class, TestModelResolver.class); + + ModelFactoryExtensionPoint factories = new DefaultModelFactoryExtensionPoint(); + + resolver = new ExtensibleModelResolver(null, resolvers, factories); + + factory = new ContributionFactoryImpl(); + } + + @Override + protected void tearDown() throws Exception { + } + + 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() { + DeployedArtifact artifact = factory.createDeployedArtifact(); + artifact.setURI("foo/bar"); + resolver.addModel(artifact); + DeployedArtifact x = factory.createDeployedArtifact(); + x.setURI("foo/bar"); + x = resolver.resolveModel(DeployedArtifact.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); + } + } + + 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/tags/java/sca/1.0-RC1b/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/resolver/TestModelResolver.java b/tags/java/sca/1.0-RC1b/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/resolver/TestModelResolver.java new file mode 100644 index 0000000000..d0db01fc09 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/resolver/TestModelResolver.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.resolver; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.tuscany.sca.contribution.Contribution; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; + +/** + * 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(); + + protected Contribution contribution; + + public TestModelResolver(Contribution contribution, ModelFactoryExtensionPoint modelFactories) { + this.contribution = contribution; + } + + 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/tags/java/sca/1.0-RC1b/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/services/ContentTypeDescriberImplTestCase.java b/tags/java/sca/1.0-RC1b/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/services/ContentTypeDescriberImplTestCase.java new file mode 100644 index 0000000000..e5e84afe7d --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/services/ContentTypeDescriberImplTestCase.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.services; + +import java.net.URL; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.contribution.ContentType; +import org.apache.tuscany.sca.contribution.service.impl.ArtifactTypeDescriberImpl; + +public class ContentTypeDescriberImplTestCase extends TestCase { + private ArtifactTypeDescriberImpl contentTypeDescriber; + + public void testResolveContentType() throws Exception { + URL artifactURL = getClass().getResource("/test.composite"); + assertEquals(ContentType.COMPOSITE, contentTypeDescriber.getType(artifactURL, null)); + } + + + public void testResolveUnknownContentType() throws Exception { + URL artifactURL = getClass().getResource("/test.ext"); + assertNull(contentTypeDescriber.getType(artifactURL, null)); + } + + public void testDefaultContentType() throws Exception { + URL artifactURL = getClass().getResource("/test.ext"); + assertEquals("application/vnd.tuscany.ext", + contentTypeDescriber.getType(artifactURL, "application/vnd.tuscany.ext")); + } + + @Override + protected void setUp() throws Exception { + contentTypeDescriber = new ArtifactTypeDescriberImpl(); + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/services/ContributionMetadataDocumentProcessorTestCase.java b/tags/java/sca/1.0-RC1b/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/services/ContributionMetadataDocumentProcessorTestCase.java new file mode 100644 index 0000000000..a86552fa42 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/services/ContributionMetadataDocumentProcessorTestCase.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.services; + +import java.io.StringReader; + +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.DefaultAssemblyFactory; +import org.apache.tuscany.sca.contribution.Contribution; +import org.apache.tuscany.sca.contribution.ContributionFactory; +import org.apache.tuscany.sca.contribution.impl.ContributionFactoryImpl; +import org.apache.tuscany.sca.contribution.resolver.impl.ModelResolverImpl; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.contribution.service.impl.ContributionMetadataProcessor; + +/** + * @version $Rev$ $Date$ + */ + +public class ContributionMetadataDocumentProcessorTestCase extends TestCase { + + private static final String VALID_XML = + "" + + "" + + "" + + "" + + ""; + + private static final String INVALID_XML = + "" + + "" + + "" + + "" + + ""; + private XMLInputFactory xmlFactory; + + @Override + protected void setUp() throws Exception { + xmlFactory = XMLInputFactory.newInstance(); + } + + public void testLoad() throws Exception { + XMLStreamReader reader = xmlFactory.createXMLStreamReader(new StringReader(VALID_XML)); + + AssemblyFactory assemblyFactory = new DefaultAssemblyFactory(); + ContributionFactory contributionFactory = new ContributionFactoryImpl(); + ContributionMetadataProcessor loader = + new ContributionMetadataProcessor(assemblyFactory, contributionFactory, null); + Contribution contribution = contributionFactory.createContribution(); + contribution.setModelResolver(new ModelResolverImpl(getClass().getClassLoader())); + contribution = loader.read(reader); + assertNotNull(contribution); + assertEquals(2, contribution.getDeployables().size()); + } + + public void testLoadInvalid() throws Exception { + XMLStreamReader reader = xmlFactory.createXMLStreamReader(new StringReader(INVALID_XML)); + AssemblyFactory assemblyFactory = new DefaultAssemblyFactory(); + ContributionFactory contributionFactory = new ContributionFactoryImpl(); + ContributionMetadataProcessor loader = + new ContributionMetadataProcessor(assemblyFactory, contributionFactory, null); + Contribution contribution = contributionFactory.createContribution(); + contribution.setModelResolver(new ModelResolverImpl(getClass().getClassLoader())); + try { + loader.read(reader); + fail("InvalidException should have been thrown"); + } catch (ContributionReadException e) { + assertTrue(true); + } + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/services/ContributionRepositoryTestCase.java b/tags/java/sca/1.0-RC1b/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/services/ContributionRepositoryTestCase.java new file mode 100644 index 0000000000..f96771095b --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/services/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.services; + +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()); + 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/tags/java/sca/1.0-RC1b/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/services/PackageTypeDescriberImplTestCase.java b/tags/java/sca/1.0-RC1b/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/services/PackageTypeDescriberImplTestCase.java new file mode 100644 index 0000000000..13d3e45d66 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/services/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.services; + +import java.net.URL; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.contribution.ContentType; +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(ContentType.JAR, this.packageTypeDescriber.getType(artifactURL, null)); + } + + public void testResolveFolderPackageType() throws Exception { + URL artifactURL = getClass().getResource("/deployables/"); + assertEquals(ContentType.FOLDER, this.packageTypeDescriber.getType(artifactURL, null)); + } + + public void testResolveFolder2PackageType() throws Exception { + URL artifactURL = getClass().getResource("/deployables"); + assertEquals(ContentType.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/tags/java/sca/1.0-RC1b/modules/contribution-impl/src/test/resources/deployables/sample-calculator.jar b/tags/java/sca/1.0-RC1b/modules/contribution-impl/src/test/resources/deployables/sample-calculator.jar new file mode 100644 index 0000000000..0ca3a1b781 Binary files /dev/null and b/tags/java/sca/1.0-RC1b/modules/contribution-impl/src/test/resources/deployables/sample-calculator.jar differ diff --git a/tags/java/sca/1.0-RC1b/modules/contribution-impl/src/test/resources/repository/sample-calculator.jar b/tags/java/sca/1.0-RC1b/modules/contribution-impl/src/test/resources/repository/sample-calculator.jar new file mode 100644 index 0000000000..9c46c679d2 Binary files /dev/null and b/tags/java/sca/1.0-RC1b/modules/contribution-impl/src/test/resources/repository/sample-calculator.jar differ diff --git a/tags/java/sca/1.0-RC1b/modules/contribution-impl/src/test/resources/test.composite b/tags/java/sca/1.0-RC1b/modules/contribution-impl/src/test/resources/test.composite new file mode 100644 index 0000000000..1e09549194 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/contribution-impl/src/test/resources/test.ext b/tags/java/sca/1.0-RC1b/modules/contribution-impl/src/test/resources/test.ext new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tags/java/sca/1.0-RC1b/modules/contribution-java/.checkstyle b/tags/java/sca/1.0-RC1b/modules/contribution-java/.checkstyle new file mode 100644 index 0000000000..ace5fe6f53 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution-java/.checkstyle @@ -0,0 +1,25 @@ + + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/contribution-java/.pmd b/tags/java/sca/1.0-RC1b/modules/contribution-java/.pmd new file mode 100644 index 0000000000..84af2f4d5d --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution-java/.pmd @@ -0,0 +1,20 @@ + + +true diff --git a/tags/java/sca/1.0-RC1b/modules/contribution-java/.ruleset b/tags/java/sca/1.0-RC1b/modules/contribution-java/.ruleset new file mode 100644 index 0000000000..ac8671859d --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution-java/.ruleset @@ -0,0 +1,190 @@ + + + + PMD Plugin preferences rule set + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/contribution-java/pom.xml b/tags/java/sca/1.0-RC1b/modules/contribution-java/pom.xml new file mode 100644 index 0000000000..21b02e1895 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution-java/pom.xml @@ -0,0 +1,51 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.0-incubating + ../pom.xml + + tuscany-contribution-java + Apache Tuscany SCA Java Import/Export Model + + + + org.apache.tuscany.sca + tuscany-contribution + 1.0-incubating + + + + org.apache.tuscany.sca + tuscany-core-spi + 1.0-incubating + + + + org.codehaus.woodstox + wstx-asl + 3.2.1 + runtime + + + diff --git a/tags/java/sca/1.0-RC1b/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/JavaExport.java b/tags/java/sca/1.0-RC1b/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/JavaExport.java new file mode 100644 index 0000000000..41e93ec148 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/JavaImport.java b/tags/java/sca/1.0-RC1b/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/JavaImport.java new file mode 100644 index 0000000000..d3568f6283 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/JavaImportExportFactory.java b/tags/java/sca/1.0-RC1b/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/JavaImportExportFactory.java new file mode 100644 index 0000000000..af2ca9cd57 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/ClassReferenceModelResolver.java b/tags/java/sca/1.0-RC1b/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/ClassReferenceModelResolver.java new file mode 100644 index 0000000000..1a3978d352 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/ClassReferenceModelResolver.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.impl; + +import java.lang.ref.WeakReference; +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.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.ModelResolver; + +/** + * 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 Contribution contribution; + protected WeakReference classLoader; + private Map map = new HashMap(); + + private ModelResolver osgiResolver; + + public ClassReferenceModelResolver(Contribution contribution, ModelFactoryExtensionPoint modelFactories) { + this.contribution = contribution; + //FIXME The classloader should be passed in + this.classLoader = new WeakReference(Thread.currentThread().getContextClassLoader()); + + try { + Class osgiResolverClass = Class.forName("org.apache.tuscany.sca.contribution.osgi.impl.OSGiClassReferenceModelResolver"); + if (osgiResolverClass != null) { + Constructor constructor = osgiResolverClass.getConstructor(Contribution.class, ModelFactoryExtensionPoint.class); + this.osgiResolver = (ModelResolver)constructor.newInstance(contribution, modelFactories); + } + } catch (Exception e) { + } + } + + 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 (import_ instanceof JavaImport) { + JavaImport javaImport = (JavaImport) import_; + String packageName = javaImport.getPackage(); + if (javaImport.getPackage().equals(packageName)) { + // Delegate the resolution to the import resolver + resolved = import_.getModelResolver().resolveModel(ClassReference.class, unresolved); + } + } + } + + } + return resolved; + } + + + public T resolveModel(Class modelClass, T unresolved) { + Object resolved = map.get(unresolved); + + if (resolved != null ){ + return modelClass.cast(resolved); + } + + //Load a class on demand + Class clazz = null; + + if (osgiResolver != null) + resolved = osgiResolver.resolveModel(modelClass, unresolved); + + if (unresolved == resolved || resolved == null) { + try { + clazz = Class.forName(((ClassReference)unresolved).getClassName(), true, classLoader.get()); + } catch (ClassNotFoundException e) { + //we will later try to delegate to imported model resolvers + } + } + else + clazz = ((ClassReference)resolved).getJavaClass(); + + + if (clazz != null) { + //if we load the class + // Store a new ClassReference wrappering 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 ); + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportImpl.java b/tags/java/sca/1.0-RC1b/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportImpl.java new file mode 100644 index 0000000000..3139dbcaec --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportImpl.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.java.impl; + +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 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/tags/java/sca/1.0-RC1b/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportProcessor.java b/tags/java/sca/1.0-RC1b/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportProcessor.java new file mode 100644 index 0000000000..840c4e2f02 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportProcessor.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.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; + +/** + * 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; + + public JavaExportProcessor(ModelFactoryExtensionPoint modelFactories) { + super(); + this.factory = modelFactories.getFactory(JavaImportExportFactory.class); + } + + public QName getArtifactType() { + return EXPORT_JAVA; + } + + public Class getModelType() { + return JavaExport.class; + } + + /** + * Process + */ + public JavaExport read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + JavaExport javaExport = this.factory.createJavaExport(); + QName element = null; + + 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) { + throw new ContributionReadException("Attribute 'package' is missing"); + } + + 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(); + } + } + + 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 model, ModelResolver resolver) throws ContributionResolveException { + + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportExportFactoryImpl.java b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportExportListener.java b/tags/java/sca/1.0-RC1b/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportExportListener.java new file mode 100644 index 0000000000..8f12bf994c --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportExportListener.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.java.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.java.JavaExport; +import org.apache.tuscany.sca.contribution.java.JavaImport; +import org.apache.tuscany.sca.contribution.resolver.DefaultImportAllModelResolver; +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 { + + /** + * 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 agains all the other contributions + */ + 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 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())) { + javaImport.setModelResolver(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 DefaultImportAllModelResolver(import_, repository.getContributions())); + } + } + } + } + + public void contributionRemoved(ContributionRepository repository, Contribution contribution) { + + } + + public void contributionUpdated(ContributionRepository repository, Contribution oldContribution, Contribution contribution) { + + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportImpl.java b/tags/java/sca/1.0-RC1b/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportImpl.java new file mode 100644 index 0000000000..d461574b2b --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportImpl.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.java.impl; + +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 implements JavaImport { + private ModelResolver modelResolver; + /** + * 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; + } + + /** + * 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) { + if(this.getLocation() == null || this.getLocation().length() == 0) { + if (this.getPackage().equals(((JavaExport)export).getPackage())) { + return true; + } + } + } + + return false; + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportProcessor.java b/tags/java/sca/1.0-RC1b/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportProcessor.java new file mode 100644 index 0000000000..24612b0450 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportProcessor.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.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; + +/** + * 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; + + public JavaImportProcessor(ModelFactoryExtensionPoint modelFactories) { + super(); + this.factory = modelFactories.getFactory(JavaImportExportFactory.class); + } + + public QName getArtifactType() { + return IMPORT_JAVA; + } + + public Class getModelType() { + return JavaImport.class; + } + + /** + * Process + */ + public JavaImport read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + JavaImport javaImport = this.factory.createJavaImport(); + QName element = null; + + 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) { + throw new ContributionReadException("Attribute 'package' is missing"); + } + + String location = reader.getAttributeValue(null, LOCATION); + javaImport.setPackage(packageName); + 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(); + } + } + + 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/tags/java/sca/1.0-RC1b/modules/contribution-java/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.java.JavaImportExportFactory b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/contribution-java/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/contribution-java/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/contribution-java/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.service.ContributionListener b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/contribution-java/src/test/java/org/apache/tuscany/sca/contribution/java/impl/ClassReferenceArtifactResolverTestCase.java b/tags/java/sca/1.0-RC1b/modules/contribution-java/src/test/java/org/apache/tuscany/sca/contribution/java/impl/ClassReferenceArtifactResolverTestCase.java new file mode 100644 index 0000000000..f0e74b363a --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution-java/src/test/java/org/apache/tuscany/sca/contribution/java/impl/ClassReferenceArtifactResolverTestCase.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.contribution.java.impl; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.contribution.DefaultModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.resolver.ClassReference; +import org.apache.tuscany.sca.contribution.resolver.DefaultModelResolverExtensionPoint; +import org.apache.tuscany.sca.contribution.resolver.ExtensibleModelResolver; +import org.apache.tuscany.sca.contribution.resolver.ModelResolverExtensionPoint; + +/** + * 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 { + + ModelResolverExtensionPoint resolvers = new DefaultModelResolverExtensionPoint(); + resolvers.addResolver(ClassReference.class, ClassReferenceModelResolver.class); + + ModelFactoryExtensionPoint factories = new DefaultModelFactoryExtensionPoint(); + + resolver = new ExtensibleModelResolver(null, resolvers, factories); + } + + @Override + protected void tearDown() throws Exception { + } + + /** + * 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/tags/java/sca/1.0-RC1b/modules/contribution-java/src/test/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportProcessorTestCase.java b/tags/java/sca/1.0-RC1b/modules/contribution-java/src/test/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportProcessorTestCase.java new file mode 100644 index 0000000000..81c7ee525a --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution-java/src/test/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportProcessorTestCase.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.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.DefaultModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.java.JavaExport; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; + +/** + * Test JavaExportProcessorTestCase + * + * @version $Rev$ $Date$ + */ +public class JavaExportProcessorTestCase extends TestCase { + + private static final String VALID_XML = + "" + + "" + + "" + + ""; + + private static final String INVALID_XML = + "" + + "" + + "" + + ""; + + private XMLInputFactory xmlFactory; + + @Override + protected void setUp() throws Exception { + xmlFactory = XMLInputFactory.newInstance(); + } + + /** + * Test loading a valid export element from a contribution metadata stream + * @throws Exception + */ + public void testLoad() throws Exception { + XMLStreamReader reader = xmlFactory.createXMLStreamReader(new StringReader(VALID_XML)); + + ModelFactoryExtensionPoint factories = new DefaultModelFactoryExtensionPoint(); + factories.addFactory(new JavaImportExportFactoryImpl()); + JavaExportProcessor exportProcessor = new JavaExportProcessor(factories); + JavaExport javaExport = exportProcessor.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 = xmlFactory.createXMLStreamReader(new StringReader(INVALID_XML)); + + ModelFactoryExtensionPoint factories = new DefaultModelFactoryExtensionPoint(); + factories.addFactory(new JavaImportExportFactoryImpl()); + JavaExportProcessor exportProcessor = new JavaExportProcessor(factories); + try { + exportProcessor.read(reader); + fail("readerException should have been thrown"); + } catch (ContributionReadException e) { + assertTrue(true); + } + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/contribution-java/src/test/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportProcessorTestCase.java b/tags/java/sca/1.0-RC1b/modules/contribution-java/src/test/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportProcessorTestCase.java new file mode 100644 index 0000000000..7f342c2278 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution-java/src/test/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportProcessorTestCase.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.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.DefaultModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.java.JavaImport; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; + +/** + * Test JavaImportProcessorTestCase + * + * @version $Rev$ $Date$ + */ +public class JavaImportProcessorTestCase extends TestCase { + + private static final String VALID_XML = + "" + + "" + + "" + + ""; + + private static final String INVALID_XML = + "" + + "" + + "" + + ""; + + private XMLInputFactory xmlFactory; + + @Override + protected void setUp() throws Exception { + xmlFactory = XMLInputFactory.newInstance(); + } + + /** + * Test loading a valid import element from a contribution metadata stream + * @throws Exception + */ + public void testLoad() throws Exception { + XMLStreamReader reader = xmlFactory.createXMLStreamReader(new StringReader(VALID_XML)); + + ModelFactoryExtensionPoint factories = new DefaultModelFactoryExtensionPoint(); + factories.addFactory(new JavaImportExportFactoryImpl()); + JavaImportProcessor importProcessor = new JavaImportProcessor(factories); + JavaImport javaImport = importProcessor.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 = xmlFactory.createXMLStreamReader(new StringReader(INVALID_XML)); + + ModelFactoryExtensionPoint factories = new DefaultModelFactoryExtensionPoint(); + factories.addFactory(new JavaImportExportFactoryImpl()); + JavaImportProcessor importProcessor = new JavaImportProcessor(factories); + try { + importProcessor.read(reader); + fail("readerException should have been thrown"); + } catch (ContributionReadException e) { + assertTrue(true); + } + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/contribution-namespace/.checkstyle b/tags/java/sca/1.0-RC1b/modules/contribution-namespace/.checkstyle new file mode 100644 index 0000000000..ace5fe6f53 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution-namespace/.checkstyle @@ -0,0 +1,25 @@ + + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/contribution-namespace/.pmd b/tags/java/sca/1.0-RC1b/modules/contribution-namespace/.pmd new file mode 100644 index 0000000000..84af2f4d5d --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution-namespace/.pmd @@ -0,0 +1,20 @@ + + +true diff --git a/tags/java/sca/1.0-RC1b/modules/contribution-namespace/.ruleset b/tags/java/sca/1.0-RC1b/modules/contribution-namespace/.ruleset new file mode 100644 index 0000000000..ac8671859d --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution-namespace/.ruleset @@ -0,0 +1,190 @@ + + + + PMD Plugin preferences rule set + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/contribution-namespace/pom.xml b/tags/java/sca/1.0-RC1b/modules/contribution-namespace/pom.xml new file mode 100644 index 0000000000..4db8094e90 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution-namespace/pom.xml @@ -0,0 +1,51 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.0-incubating + ../pom.xml + + tuscany-contribution-namespace + Apache Tuscany SCA Namespace Import/Export Model + + + + org.apache.tuscany.sca + tuscany-contribution + 1.0-incubating + + + + org.apache.tuscany.sca + tuscany-core-spi + 1.0-incubating + + + + org.codehaus.woodstox + wstx-asl + 3.2.1 + runtime + + + diff --git a/tags/java/sca/1.0-RC1b/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/NamespaceExport.java b/tags/java/sca/1.0-RC1b/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/NamespaceExport.java new file mode 100644 index 0000000000..c68aee8521 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/NamespaceImport.java b/tags/java/sca/1.0-RC1b/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/NamespaceImport.java new file mode 100644 index 0000000000..8af36d7da0 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/NamespaceImportExportFactory.java b/tags/java/sca/1.0-RC1b/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/NamespaceImportExportFactory.java new file mode 100644 index 0000000000..cfbac8bb1f --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportImpl.java b/tags/java/sca/1.0-RC1b/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportImpl.java new file mode 100644 index 0000000000..080a6bab2b --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportImpl.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.namespace.impl; + +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 implements NamespaceExport { + /** + * The namespace to be exported + */ + 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/tags/java/sca/1.0-RC1b/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportProcessor.java b/tags/java/sca/1.0-RC1b/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportProcessor.java new file mode 100644 index 0000000000..bf5d636044 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportProcessor.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.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.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.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; + +/** + * Artifact processor for Namespace export + * + * @version $Rev$ $Date$ + */ +public class NamespaceExportProcessor 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; + + public NamespaceExportProcessor(ModelFactoryExtensionPoint modelFactories) { + this.factory = modelFactories.getFactory(NamespaceImportExportFactory.class); + } + + public QName getArtifactType() { + return EXPORT; + } + + public Class getModelType() { + return NamespaceExport.class; + } + + /** + * Process + */ + public NamespaceExport read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + NamespaceExport namespaceExport = this.factory.createNamespaceExport(); + QName element = null; + + 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) { + throw new ContributionReadException("Attribute 'namespace' is missing"); + } + namespaceExport.setNamespace(ns); + } + + break; + case XMLStreamConstants.END_ELEMENT: + if (EXPORT.equals(reader.getName())) { + return namespaceExport; + } + break; + } + + // Read the next element + if (reader.hasNext()) { + reader.next(); + } + } + + 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()); + } + + writer.writeEndElement(); + } + + public void resolve(NamespaceExport model, ModelResolver resolver) throws ContributionResolveException { + + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportExportFactoryImpl.java b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportExportListener.java b/tags/java/sca/1.0-RC1b/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportExportListener.java new file mode 100644 index 0000000000..f235f9f9f1 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportExportListener.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.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 agains all the other contributions + */ + 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/tags/java/sca/1.0-RC1b/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportImpl.java b/tags/java/sca/1.0-RC1b/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportImpl.java new file mode 100644 index 0000000000..468b18fc05 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportImpl.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.contribution.namespace.impl; + +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 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.getLocation() == null || this.getLocation().length() == 0) { + if (this.getNamespace().equals(((NamespaceExport)export).getNamespace())) { + return true; + } + } + + } + return false; + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportProcessor.java b/tags/java/sca/1.0-RC1b/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportProcessor.java new file mode 100644 index 0000000000..9a4475ef23 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution-namespace/src/main/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportProcessor.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.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.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.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; + +/** + * Artifact processor for Namespace import + * + * @version $Rev$ $Date$ + */ +public class NamespaceImportProcessor 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; + + public NamespaceImportProcessor(ModelFactoryExtensionPoint modelFactories) { + this.factory = modelFactories.getFactory(NamespaceImportExportFactory.class); + } + + public QName getArtifactType() { + return IMPORT; + } + + public Class getModelType() { + return NamespaceImport.class; + } + + /** + * Process + */ + public NamespaceImport read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + NamespaceImport namespaceImport = this.factory.createNamespaceImport(); + QName element; + + 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) { + throw new ContributionReadException("Attribute 'namespace' is missing"); + } + namespaceImport.setNamespace(ns); + + String location = reader.getAttributeValue(null, LOCATION); + if (location != null) { + namespaceImport.setLocation(location); + } + } + break; + case XMLStreamConstants.END_ELEMENT: + if (IMPORT.equals(reader.getName())) { + return namespaceImport; + } + break; + } + + // Read the next element + if (reader.hasNext()) { + reader.next(); + } + } + + 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()); + } + + writer.writeEndElement(); + } + + + public void resolve(NamespaceImport model, ModelResolver resolver) throws ContributionResolveException { + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/contribution-namespace/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.namespace.NamespaceImportExportFactory b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/contribution-namespace/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/contribution-namespace/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver b/tags/java/sca/1.0-RC1b/modules/contribution-namespace/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver new file mode 100644 index 0000000000..c69eb40636 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution-namespace/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/tags/java/sca/1.0-RC1b/modules/contribution-namespace/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.service.ContributionListener b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/contribution-namespace/src/test/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportProcessorTestCase.java b/tags/java/sca/1.0-RC1b/modules/contribution-namespace/src/test/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportProcessorTestCase.java new file mode 100644 index 0000000000..75219227c2 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution-namespace/src/test/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceExportProcessorTestCase.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.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.DefaultModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.namespace.NamespaceExport; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; + +/** + * Test NamespaceExportProcessorTestCase + * + * @version $Rev$ $Date$ + */ +public class NamespaceExportProcessorTestCase extends TestCase { + + private static final String VALID_XML = + "" + + "" + + "" + + ""; + + private static final String INVALID_XML = + "" + + "" + + "" + + ""; + + private XMLInputFactory xmlFactory; + + @Override + protected void setUp() throws Exception { + xmlFactory = XMLInputFactory.newInstance(); + } + + /** + * Test loading a valid export element from a contribution metadata stream + * @throws Exception + */ + public void testLoad() throws Exception { + XMLStreamReader reader = xmlFactory.createXMLStreamReader(new StringReader(VALID_XML)); + + ModelFactoryExtensionPoint factories = new DefaultModelFactoryExtensionPoint(); + factories.addFactory(new NamespaceImportExportFactoryImpl()); + NamespaceExportProcessor exportProcessor = new NamespaceExportProcessor(factories); + NamespaceExport namespaceExport = exportProcessor.read(reader); + + assertEquals("http://foo", namespaceExport.getNamespace()); + } + + /** + * Test loading an INVALID export element from a contribution metadata stream + * @throws Exception + */ + public void testLoadInvalid() throws Exception { + XMLStreamReader reader = xmlFactory.createXMLStreamReader(new StringReader(INVALID_XML)); + + ModelFactoryExtensionPoint factories = new DefaultModelFactoryExtensionPoint(); + factories.addFactory(new NamespaceImportExportFactoryImpl()); + NamespaceExportProcessor exportProcessor = new NamespaceExportProcessor(factories); + try { + exportProcessor.read(reader); + fail("readerException should have been thrown"); + } catch (ContributionReadException e) { + assertTrue(true); + } + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/contribution-namespace/src/test/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportProcessorTestCase.java b/tags/java/sca/1.0-RC1b/modules/contribution-namespace/src/test/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportProcessorTestCase.java new file mode 100644 index 0000000000..9a05e43d7a --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution-namespace/src/test/java/org/apache/tuscany/sca/contribution/namespace/impl/NamespaceImportProcessorTestCase.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.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.DefaultModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.namespace.NamespaceImport; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; + +/** + * Test NamespaceImportProcessorTestCase + * + * @version $Rev$ $Date$ + */ +public class NamespaceImportProcessorTestCase extends TestCase { + + private static final String VALID_XML = + "" + + "" + + "" + + ""; + + private static final String INVALID_XML = + "" + + "" + + "" + + ""; + + private XMLInputFactory xmlFactory; + + @Override + protected void setUp() throws Exception { + xmlFactory = XMLInputFactory.newInstance(); + } + + /** + * Test loading a valid import element from a contribution metadata stream + * @throws Exception + */ + public void testLoad() throws Exception { + XMLStreamReader reader = xmlFactory.createXMLStreamReader(new StringReader(VALID_XML)); + + ModelFactoryExtensionPoint factories = new DefaultModelFactoryExtensionPoint(); + factories.addFactory(new NamespaceImportExportFactoryImpl()); + NamespaceImportProcessor importProcessor = new NamespaceImportProcessor(factories); + NamespaceImport namespaceImport = importProcessor.read(reader); + + assertEquals("http://foo", namespaceImport.getNamespace()); + 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 = xmlFactory.createXMLStreamReader(new StringReader(INVALID_XML)); + + ModelFactoryExtensionPoint factories = new DefaultModelFactoryExtensionPoint(); + factories.addFactory(new NamespaceImportExportFactoryImpl()); + NamespaceImportProcessor importProcessor = new NamespaceImportProcessor(factories); + try { + importProcessor.read(reader); + fail("readerException should have been thrown"); + } catch (ContributionReadException e) { + assertTrue(true); + } + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/contribution-osgi/.checkstyle b/tags/java/sca/1.0-RC1b/modules/contribution-osgi/.checkstyle new file mode 100644 index 0000000000..ace5fe6f53 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution-osgi/.checkstyle @@ -0,0 +1,25 @@ + + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/contribution-osgi/.pmd b/tags/java/sca/1.0-RC1b/modules/contribution-osgi/.pmd new file mode 100644 index 0000000000..84af2f4d5d --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution-osgi/.pmd @@ -0,0 +1,20 @@ + + +true diff --git a/tags/java/sca/1.0-RC1b/modules/contribution-osgi/.ruleset b/tags/java/sca/1.0-RC1b/modules/contribution-osgi/.ruleset new file mode 100644 index 0000000000..ac8671859d --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution-osgi/.ruleset @@ -0,0 +1,190 @@ + + + + PMD Plugin preferences rule set + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/contribution-osgi/pom.xml b/tags/java/sca/1.0-RC1b/modules/contribution-osgi/pom.xml new file mode 100644 index 0000000000..461d7425e5 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution-osgi/pom.xml @@ -0,0 +1,65 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.0-incubating + ../pom.xml + + tuscany-contribution-osgi + Apache Tuscany SCA Contribution Service OSGi + + + + org.apache.tuscany.sca + tuscany-contribution + 1.0-incubating + + + + org.apache.tuscany.sca + tuscany-osgi-runtime + 1.0-incubating + + + + org.apache.tuscany.sca + tuscany-core-spi + 1.0-incubating + + + + org.apache.felix + org.apache.felix.main + 1.0.0 + + + + + + org.codehaus.woodstox + wstx-asl + 3.2.1 + runtime + + + diff --git a/tags/java/sca/1.0-RC1b/modules/contribution-osgi/src/main/java/org/apache/tuscany/sca/contribution/osgi/BundleReference.java b/tags/java/sca/1.0-RC1b/modules/contribution-osgi/src/main/java/org/apache/tuscany/sca/contribution/osgi/BundleReference.java new file mode 100644 index 0000000000..1e52a20d16 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution-osgi/src/main/java/org/apache/tuscany/sca/contribution/osgi/BundleReference.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.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 { + + private Object bundle; + private String bundleName; + private String bundleVersion; + private String bundleUniqueName; + private String bundleRelativePath; + + /** + * Constructs a new BundleReference. + * + * @param bundle The bundle reference + */ + 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 className The class name + */ + 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/tags/java/sca/1.0-RC1b/modules/contribution-osgi/src/main/java/org/apache/tuscany/sca/contribution/osgi/impl/OSGiBundleProcessor.java b/tags/java/sca/1.0-RC1b/modules/contribution-osgi/src/main/java/org/apache/tuscany/sca/contribution/osgi/impl/OSGiBundleProcessor.java new file mode 100644 index 0000000000..ec5f669995 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution-osgi/src/main/java/org/apache/tuscany/sca/contribution/osgi/impl/OSGiBundleProcessor.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.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.Contribution; +import org.apache.tuscany.sca.contribution.DeployedArtifact; +import org.apache.tuscany.sca.contribution.osgi.BundleReference; +import org.apache.tuscany.sca.osgi.runtime.OSGiRuntime; + +/** + * OSGi bundle processor + * + */ +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 (DeployedArtifact 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/tags/java/sca/1.0-RC1b/modules/contribution-osgi/src/main/java/org/apache/tuscany/sca/contribution/osgi/impl/OSGiBundleReferenceModelResolver.java b/tags/java/sca/1.0-RC1b/modules/contribution-osgi/src/main/java/org/apache/tuscany/sca/contribution/osgi/impl/OSGiBundleReferenceModelResolver.java new file mode 100644 index 0000000000..b8095d2529 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution-osgi/src/main/java/org/apache/tuscany/sca/contribution/osgi/impl/OSGiBundleReferenceModelResolver.java @@ -0,0 +1,152 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.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.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/tags/java/sca/1.0-RC1b/modules/contribution-osgi/src/main/java/org/apache/tuscany/sca/contribution/osgi/impl/OSGiClassReferenceModelResolver.java b/tags/java/sca/1.0-RC1b/modules/contribution-osgi/src/main/java/org/apache/tuscany/sca/contribution/osgi/impl/OSGiClassReferenceModelResolver.java new file mode 100644 index 0000000000..c8cc857aef --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution-osgi/src/main/java/org/apache/tuscany/sca/contribution/osgi/impl/OSGiClassReferenceModelResolver.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.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.resolver.ClassReference; +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 ClassReferences. + * + * @version $Rev$ $Date$ + */ +public class OSGiClassReferenceModelResolver implements ModelResolver { + private Contribution contribution; + private Map map = new HashMap(); + private Bundle bundle; + private boolean initialized; + + + public OSGiClassReferenceModelResolver(Contribution contribution, ModelFactoryExtensionPoint modelFactories) { + 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(); + + //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 wrappering 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.getRuntime().findBundle(contribution.getLocation()); + } catch (Exception e) { + } + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/contribution-osgi/src/main/java/org/apache/tuscany/sca/contribution/osgi/impl/OSGiImportExportListener.java b/tags/java/sca/1.0-RC1b/modules/contribution-osgi/src/main/java/org/apache/tuscany/sca/contribution/osgi/impl/OSGiImportExportListener.java new file mode 100644 index 0000000000..ca349bb902 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution-osgi/src/main/java/org/apache/tuscany/sca/contribution/osgi/impl/OSGiImportExportListener.java @@ -0,0 +1,203 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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 agains all the other contributions + */ + public void contributionAdded(ContributionRepository repository, Contribution contribution) { + + OSGiRuntime osgiRuntime; + + try { + osgiRuntime = OSGiRuntime.getRuntime(); + + if (bundleProcessor.installContributionBundle(contribution) == null) + return; + } 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(); + String uri = contribution.getURI(); + + 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: .," + uri + 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(uri); + jarOut.putNextEntry(ze); + URL url = new URL(contribution.getLocation()); + InputStream stream = url.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/tags/java/sca/1.0-RC1b/modules/contribution-osgi/src/main/java/org/apache/tuscany/sca/contribution/osgi/impl/OSGiModelResolverImpl.java b/tags/java/sca/1.0-RC1b/modules/contribution-osgi/src/main/java/org/apache/tuscany/sca/contribution/osgi/impl/OSGiModelResolverImpl.java new file mode 100644 index 0000000000..9f1fcfb606 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution-osgi/src/main/java/org/apache/tuscany/sca/contribution/osgi/impl/OSGiModelResolverImpl.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.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. + * + */ +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 wrappering 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/tags/java/sca/1.0-RC1b/modules/contribution-osgi/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/contribution-osgi/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.service.ContributionListener b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/contribution/.checkstyle b/tags/java/sca/1.0-RC1b/modules/contribution/.checkstyle new file mode 100644 index 0000000000..e3c216986d --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution/.checkstyle @@ -0,0 +1,24 @@ + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/contribution/.pmd b/tags/java/sca/1.0-RC1b/modules/contribution/.pmd new file mode 100644 index 0000000000..84af2f4d5d --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution/.pmd @@ -0,0 +1,20 @@ + + +true diff --git a/tags/java/sca/1.0-RC1b/modules/contribution/.ruleset b/tags/java/sca/1.0-RC1b/modules/contribution/.ruleset new file mode 100644 index 0000000000..ac8671859d --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution/.ruleset @@ -0,0 +1,190 @@ + + + + PMD Plugin preferences rule set + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/contribution/DISCLAIMER b/tags/java/sca/1.0-RC1b/modules/contribution/DISCLAIMER new file mode 100644 index 0000000000..d68a410903 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution/DISCLAIMER @@ -0,0 +1,8 @@ +Apache Tuscany is an effort undergoing incubation at The Apache Software +Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is +required of all newly accepted projects until a further review indicates that +the infrastructure, communications, and decision making process have stabilized +in a manner consistent with other successful ASF projects. While incubation +status is not necessarily a reflection of the completeness or stability of the +code, it does indicate that the project has yet to be fully endorsed by the ASF. + diff --git a/tags/java/sca/1.0-RC1b/modules/contribution/LICENSE b/tags/java/sca/1.0-RC1b/modules/contribution/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/contribution/NOTICE b/tags/java/sca/1.0-RC1b/modules/contribution/NOTICE new file mode 100644 index 0000000000..94481d6cfa --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2007 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/tags/java/sca/1.0-RC1b/modules/contribution/pom.xml b/tags/java/sca/1.0-RC1b/modules/contribution/pom.xml new file mode 100644 index 0000000000..01d6763f6b --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution/pom.xml @@ -0,0 +1,44 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.0-incubating + ../pom.xml + + tuscany-contribution + Apache Tuscany SCA Contribution Model + + + + org.apache.tuscany.sca + tuscany-assembly + 1.0-incubating + + + + stax + stax-api + 1.0.1 + + + diff --git a/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/Artifact.java b/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/Artifact.java new file mode 100644 index 0000000000..1b4a61234b --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/Artifact.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; + + +/** + * Base Artifact interface to accomodate common properties between Contribution and Deployed Artifact + * + * @version $Rev$ $Date$ + */ +public interface Artifact { + /** + * Get the URI that unique identifies the artifact + * + * @return The artifact uri + */ + String getURI(); + + /** + * Set the URI that unique identifies the artifact + * + * @param uri The artifact uri + */ + void setURI(String uri); + + /** + * Get the URL location for the artifact + * + * @return The artifact location + */ + String getLocation(); + + /** + * Set the URL location for the artifact + * + * @param location The artifact location + */ + void setLocation(String location); + +} diff --git a/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/ContentType.java b/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/ContentType.java new file mode 100644 index 0000000000..51e5b586be --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/ContentType.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; + +/** + * Identifies internal content types for contribution package and artifacts + * + * @version $Rev$ $Date$ + */ +public interface ContentType { + /** + * Java compressed contribution package + */ + String JAR = "application/x-compressed"; + /** + * Filesystem folder contribution package + */ + String FOLDER = "application/vnd.tuscany.folder"; + /** + * Contribution metadata file + */ + String CONTRIBUTION_METADATA = "application/vnd.tuscany.contribution.metadata"; + /** + * SCA Composite description file + */ + String COMPOSITE = "application/vnd.tuscany.composite"; + /** + * WSDL file + */ + String WSDL = "application/vnd.tuscany.wsdl"; + /** + * Java source/binary file + */ + String JAVA = "application/java-vm"; + /** + * Unkown contentType + */ + String UNKNOWN = "content/unknown"; +} diff --git a/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/Contribution.java b/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/Contribution.java new file mode 100644 index 0000000000..e31805bf9a --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/Contribution.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.contribution; + +import java.util.List; + +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; + +/** + * The representation of a deployed contribution + * + * @version $Rev$ $Date$ + */ +public interface Contribution extends Artifact { + /** + * Default location of contribution metadata in a contribution package + */ + String SCA_CONTRIBUTION_META = "META-INF/sca-contribution.xml"; + /** + * default location of a generated contribution metadata in a contribution package + */ + String SCA_CONTRIBUTION_GENERATED_META = "META-INF/sca-contribution-generated.xml"; + /** + * Default location of deployables in a contribution + */ + String SCA_CONTRIBUTION_DEPLOYABLES = "META-INF/sca-deployables/"; + + + /** + * Get a list of exports based on the Contribution metadata sidefile + * + * @return The list of exported artifacts from this contribution + */ + List getExports(); + + /** + * Get a list of imports based on the Contribution metadata sidefile + * + * @return The list of imported artifacts on this contribution + */ + List getImports(); + + /** + * Get a list of deployables for the contribution based on the contribution metadata sidefile + * + * @return The list of deployable composites + */ + List getDeployables(); + + /** + * Get a list of artifacts from the contribution + * + * @return The list of deployed artifacts for 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); + +} \ No newline at end of file diff --git a/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/ContributionFactory.java b/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/ContributionFactory.java new file mode 100644 index 0000000000..e21ae3999b --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/ContributionFactory.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; + + +/** + * Contribution model object factory + * + * @version $Rev$ $Date$ + */ +public interface ContributionFactory { + /** + * Create a contribution model object + * + * @return The new contribution model object + */ + Contribution createContribution(); + + /** + * Create a deployedArtifact model object + * + * @return The new deployedArtifact model object + */ + DeployedArtifact createDeployedArtifact(); +} \ No newline at end of file diff --git a/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/DefaultModelFactoryExtensionPoint.java b/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/DefaultModelFactoryExtensionPoint.java new file mode 100644 index 0000000000..ac3cd010d1 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/DefaultModelFactoryExtensionPoint.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.contribution; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Method; +import java.util.HashMap; +import java.util.List; + +import org.apache.tuscany.sca.contribution.util.ServiceConfigurationUtil; + + +/** + * Default implementation of a model factory extension point. + * + * @version $Rev$ $Date$ + */ +public class DefaultModelFactoryExtensionPoint implements ModelFactoryExtensionPoint { + + private HashMap, Object> factories = new HashMap, Object>(); + + 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 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 + ClassLoader classLoader = factoryInterface.getClassLoader(); + if (classLoader == null) + classLoader = ClassLoader.getSystemClassLoader(); + try { + List classNames = ServiceConfigurationUtil.getServiceClassNames(classLoader, factoryInterface.getName()); + if (!classNames.isEmpty()) { + Class factoryClass = Class.forName(classNames.iterator().next(), true, classLoader); + + 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 { + Method newInstanceMethod = factoryInterface.getMethod("newInstance"); + factory = newInstanceMethod.invoke(null); + } catch (Exception e) { + throw new IllegalArgumentException(e); + } + + // Cache the factory + addFactory(factory); + } + } + return factoryInterface.cast(factory); + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/DeployedArtifact.java b/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/DeployedArtifact.java new file mode 100644 index 0000000000..4b0fb1cc08 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/DeployedArtifact.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; + +/** + * Representation of a deployed artifact + * + * @version $Rev$ $Date$ + */ +public interface DeployedArtifact extends Artifact { + + /** + * Get the assembly model associated with this artifact + * + * @return The assembly model + */ + Object getModel(); + + /** + * Set the assembly model associated with this artifact + * + * @param modelObject The assembly model + */ + void setModel(Object modelObject); + +} diff --git a/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/Export.java b/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/Export.java new file mode 100644 index 0000000000..bfa16b1ce3 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/Export.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; + +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; + +/** + * The representation of an export. + * + * @version $Rev$ $Date$ + */ +public interface Export { + + /** + * 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/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/Import.java b/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/Import.java new file mode 100644 index 0000000000..4a4b63805b --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/Import.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; + +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; + + +/** + * The representation of an import. + * + * @version $Rev$ $Date$ + */ +public interface Import { + + /** + * 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 is a specific export is provider of 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/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/ModelFactoryExtensionPoint.java b/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/ModelFactoryExtensionPoint.java new file mode 100644 index 0000000000..0ada4ebec3 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ArtifactProcessor.java b/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ArtifactProcessor.java new file mode 100644 index 0000000000..014c187733 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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; + +/** + * Interface for extensions that can process contributions. + * + * @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/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ArtifactProcessorExtensionPoint.java b/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ArtifactProcessorExtensionPoint.java new file mode 100644 index 0000000000..029df61f0f --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/BaseStAXArtifactProcessor.java b/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/BaseStAXArtifactProcessor.java new file mode 100644 index 0000000000..ed41b9ae6e --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/BaseStAXArtifactProcessor.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; + +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; + + +/** + * 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 void writeElementPrefix(XMLStreamWriter writer, String uri) throws XMLStreamException { + if (uri == null) { + return; + } + String 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); + } + + } + + /** + * Start an element. + * @param uri + * @param name + * @param attrs + * @throws XMLStreamException + */ + protected void writeStart(XMLStreamWriter writer, String uri, String name, XAttr... attrs) throws XMLStreamException { + writeElementPrefix(writer, uri); + writeAttributePrefixes(writer, attrs); + writer.writeStartElement(uri, name); + writeAttributes(writer, 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); + } + + /** + * 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); + } + } + + /** + * 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, 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 && prefix.length() > 0) { + + // Use the prefix already bound to the given uri + return prefix + ":" + 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); + } + } + } + + /** + * 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/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultArtifactProcessorExtensionPoint.java b/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultArtifactProcessorExtensionPoint.java new file mode 100644 index 0000000000..1c2faf9503 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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 registry. + * + * @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. + */ + public 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/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultPackageProcessorExtensionPoint.java b/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultPackageProcessorExtensionPoint.java new file mode 100644 index 0000000000..5a794498d9 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultPackageProcessorExtensionPoint.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; + +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 org.apache.tuscany.sca.contribution.service.ContributionException; +import org.apache.tuscany.sca.contribution.util.ServiceConfigurationUtil; + +/** + * Default implementation of ContributionProcessorRegistry + * + * @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 void loadProcessors() { + if (loaded) + return; + + // Get the processor service declarations + ClassLoader classLoader = PackageProcessor.class.getClassLoader(); + List processorDeclarations; + try { + processorDeclarations = ServiceConfigurationUtil.getServiceClassNames(classLoader, PackageProcessor.class.getName()); + } catch (IOException e) { + throw new IllegalStateException(e); + } + + for (String processorDeclaration: processorDeclarations) { + Map attributes = ServiceConfigurationUtil.parseServiceDeclaration(processorDeclaration); + String className = attributes.get("class"); + + // Load a URL artifact processor + String packageType = attributes.get("type"); + + // Create a processor wrapper and register it + PackageProcessor processor = new LazyPackageProcessor(packageType, className); + addPackageProcessor(processor); + } + + loaded = true; + } + + /** + * A facade for package processors. + */ + private static class LazyPackageProcessor implements PackageProcessor { + + private String className; + private String packageType; + private PackageProcessor processor; + + private LazyPackageProcessor(String packageType, String className) { + this.className = className; + 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 { + ClassLoader classLoader = PackageProcessor.class.getClassLoader(); + Class processorClass = (Class)Class.forName(className, true, classLoader); + Constructor constructor = processorClass.getConstructor(); + processor = constructor.newInstance(); + } catch (Exception e) { + throw new IllegalStateException(e); + } + } + return processor; + } + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultStAXArtifactProcessorExtensionPoint.java b/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultStAXArtifactProcessorExtensionPoint.java new file mode 100644 index 0000000000..9ebf49554c --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultStAXArtifactProcessorExtensionPoint.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.processor; + +import java.io.IOException; +import java.lang.reflect.Constructor; +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.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.contribution.util.ServiceConfigurationUtil; +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 ModelFactoryExtensionPoint modelFactories; + private boolean loaded; + + /** + * Constructs a new extension point. + */ + public DefaultStAXArtifactProcessorExtensionPoint(ModelFactoryExtensionPoint modelFactories) { + this.modelFactories = modelFactories; + } + + public void addArtifactProcessor(StAXArtifactProcessor artifactProcessor) { + processorsByArtifactType.put((Object)artifactProcessor.getArtifactType(), artifactProcessor); + processorsByModelType.put(artifactProcessor.getModelType(), artifactProcessor); + } + + public void removeArtifactProcessor(StAXArtifactProcessor artifactProcessor) { + processorsByArtifactType.remove((Object)artifactProcessor.getArtifactType()); + 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); + } + + private void loadArtifactProcessors() { + if (loaded) + return; + + // Get the processor service declarations + ClassLoader classLoader = StAXArtifactProcessor.class.getClassLoader(); + List processorDeclarations; + try { + processorDeclarations = ServiceConfigurationUtil.getServiceClassNames(classLoader, StAXArtifactProcessor.class.getName()); + } catch (IOException e) { + throw new IllegalStateException(e); + } + + for (String processorDeclaration: processorDeclarations) { + Map attributes = ServiceConfigurationUtil.parseServiceDeclaration(processorDeclaration); + String className = attributes.get("class"); + + // Load a StAX artifact processor + + // Get the model qname + QName artifactType = null; + String qname = attributes.get("qname"); + if (qname != null) { + int h = qname.indexOf('#'); + artifactType = new QName(qname.substring(0, h), qname.substring(h+1)); + } + + // 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(modelFactories, artifactType, modelTypeName, factoryName, className); + 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 ModelFactoryExtensionPoint modelFactories; + private QName artifactType; + private String modelTypeName; + private String factoryName; + private String className; + private StAXArtifactProcessor processor; + private Class modelType; + + LazyStAXArtifactProcessor(ModelFactoryExtensionPoint modelFactories, QName artifactType, String modelTypeName, String factoryName, String className) { + this.modelFactories = modelFactories; + this.artifactType = artifactType; + this.modelTypeName = modelTypeName; + this.factoryName = factoryName; + this.className = className; + } + + public QName getArtifactType() { + return artifactType; + } + + @SuppressWarnings("unchecked") + private StAXArtifactProcessor getProcessor() { + if (processor == null) { + + if (className.equals("org.apache.tuscany.sca.assembly.xml.DefaultBeanModelProcessor")) { + + // Specific initialization for the DefaultBeanModelProcessor + AssemblyFactory assemblyFactory = modelFactories.getFactory(AssemblyFactory.class); + PolicyFactory policyFactory = modelFactories.getFactory(PolicyFactory.class); + try { + ClassLoader classLoader = URLArtifactProcessor.class.getClassLoader(); + Class processorClass = (Class)Class.forName(className, true, classLoader); + Object modelFactory; + if (factoryName != null) { + Class factoryClass = (Class)Class.forName(factoryName, true, classLoader); + modelFactory = modelFactories.getFactory(factoryClass); + } else { + modelFactory = null; + } + Constructor constructor = processorClass.getConstructor(AssemblyFactory.class, PolicyFactory.class, QName.class, Class.class, Object.class); + processor = constructor.newInstance(assemblyFactory, policyFactory, artifactType, getModelType(), modelFactory); + } catch (Exception e) { + throw new IllegalStateException(e); + } + } else { + + // Load and instanciate the processor class + try { + ClassLoader classLoader = URLArtifactProcessor.class.getClassLoader(); + Class processorClass = (Class)Class.forName(className, true, classLoader); + Constructor constructor = processorClass.getConstructor(ModelFactoryExtensionPoint.class); + processor = constructor.newInstance(modelFactories); + } catch (Exception e) { + throw new IllegalStateException(e); + } + } + } + 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 (modelType == null) { + try { + ClassLoader classLoader = URLArtifactProcessor.class.getClassLoader(); + modelType = Class.forName(modelTypeName, true, classLoader); + } catch (Exception e) { + throw new IllegalStateException(e); + } + } + return modelType; + } + + @SuppressWarnings("unchecked") + public void resolve(Object model, ModelResolver resolver) throws ContributionResolveException { + getProcessor().resolve(model, resolver); + } + + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultURLArtifactProcessorExtensionPoint.java b/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultURLArtifactProcessorExtensionPoint.java new file mode 100644 index 0000000000..acc611c101 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultURLArtifactProcessorExtensionPoint.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.processor; + +import java.io.IOException; +import java.lang.reflect.Constructor; +import java.net.URI; +import java.net.URL; +import java.util.List; +import java.util.Map; + +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.util.ServiceConfigurationUtil; + +/** + * The default implementation of a StAX artifact processor registry. + * + * @version $Rev$ $Date$ + */ +public class DefaultURLArtifactProcessorExtensionPoint + extends DefaultArtifactProcessorExtensionPoint + implements URLArtifactProcessorExtensionPoint { + + private ModelFactoryExtensionPoint modelFactories; + private boolean loaded; + + /** + * Constructs a new extension point. + */ + public DefaultURLArtifactProcessorExtensionPoint(ModelFactoryExtensionPoint modelFactories) { + this.modelFactories = modelFactories; + } + + public void addArtifactProcessor(URLArtifactProcessor artifactProcessor) { + processorsByArtifactType.put((Object)artifactProcessor.getArtifactType(), artifactProcessor); + processorsByModelType.put(artifactProcessor.getModelType(), artifactProcessor); + } + + public void removeArtifactProcessor(URLArtifactProcessor artifactProcessor) { + processorsByArtifactType.remove((Object)artifactProcessor.getArtifactType()); + 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); + } + + private void loadProcessors() { + if (loaded) + return; + + // Get the processor service declarations + ClassLoader classLoader = URLArtifactProcessor.class.getClassLoader(); + List processorDeclarations; + try { + processorDeclarations = ServiceConfigurationUtil.getServiceClassNames(classLoader, URLArtifactProcessor.class.getName()); + } catch (IOException e) { + throw new IllegalStateException(e); + } + + for (String processorDeclaration: processorDeclarations) { + Map attributes = ServiceConfigurationUtil.parseServiceDeclaration(processorDeclaration); + String className = attributes.get("class"); + + // 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(modelFactories, artifactType, modelTypeName, className); + 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 ModelFactoryExtensionPoint modelFactories; + private String artifactType; + private String modelTypeName; + private String className; + private URLArtifactProcessor processor; + private Class modelType; + + LazyURLArtifactProcessor(ModelFactoryExtensionPoint modelFactories, String artifactType, String modelTypeName, String className) { + this.modelFactories = modelFactories; + this.artifactType = artifactType; + this.modelTypeName = modelTypeName; + this.className = className; + } + + public String getArtifactType() { + return artifactType; + } + + @SuppressWarnings("unchecked") + private URLArtifactProcessor getProcessor() { + if (processor == null) { + try { + ClassLoader classLoader = URLArtifactProcessor.class.getClassLoader(); + Class processorClass = (Class)Class.forName(className, true, classLoader); + Constructor constructor = processorClass.getConstructor(ModelFactoryExtensionPoint.class); + processor = constructor.newInstance(modelFactories); + } catch (Exception e) { + throw new IllegalStateException(e); + } + } + return processor; + } + + public Object read(URL contributionURL, URI artifactURI, URL artifactURL) throws ContributionReadException { + return getProcessor().read(contributionURL, artifactURI, artifactURL); + } + + public Class getModelType() { + if (modelType == null) { + try { + ClassLoader classLoader = URLArtifactProcessor.class.getClassLoader(); + modelType = Class.forName(modelTypeName, true, classLoader); + } catch (Exception e) { + throw new IllegalStateException(e); + } + } + return modelType; + } + + @SuppressWarnings("unchecked") + public void resolve(Object model, ModelResolver resolver) throws ContributionResolveException { + getProcessor().resolve(model, resolver); + } + + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensiblePackageProcessor.java b/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensiblePackageProcessor.java new file mode 100644 index 0000000000..fb6e1b29ce --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensiblePackageProcessor.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.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.UnsupportedContentTypeException; + +/** + * Default implementation of PackageProcessor. + * + * This implementation has a packageProcessorExtensionPoint + * and it delegates to the proper package processor based on content type + * + * @version $Rev$ $Date$ + */ +public class ExtensiblePackageProcessor implements PackageProcessor { + + private PackageProcessorExtensionPoint processors; + + /** + * Helper method to describe contentType for each artifact + */ + private TypeDescriber packageTypeDescriber; + + public ExtensiblePackageProcessor(PackageProcessorExtensionPoint processors, TypeDescriber packageTypeDescriber) { + this.processors = processors; + this.packageTypeDescriber = packageTypeDescriber; + } + + public List getArtifacts(URL packageSourceURL, InputStream inputStream) + throws ContributionException, IOException { + String contentType = this.packageTypeDescriber.getType(packageSourceURL, null); + if (contentType == null) { + throw new UnsupportedContentTypeException("Unsupported contribution package", packageSourceURL.toString()); + } + + PackageProcessor packageProcessor = this.processors.getPackageProcessor(contentType); + if (packageProcessor == null) { + throw new UnsupportedContentTypeException(contentType, packageSourceURL.getPath()); + } + + 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/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleStAXArtifactProcessor.java b/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleStAXArtifactProcessor.java new file mode 100644 index 0000000000..8034a45d79 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleStAXArtifactProcessor.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.contribution.processor; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; + +import javax.xml.namespace.QName; +import javax.xml.stream.Location; +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.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; + +/** + * The default implementation of a StAX artifact processor registry. + * + * This implementation has a StAXArtifactProcessorExtensionPoint and + * it delegates to the proper StAXArtifactProcessor by element QName + * + * @version $Rev$ $Date$ + */ +public class ExtensibleStAXArtifactProcessor + implements StAXArtifactProcessor { + + private XMLInputFactory inputFactory; + private XMLOutputFactory outputFactory; + private StAXArtifactProcessorExtensionPoint processors; + + /** + * Constructs a new loader registry. + * @param inputFactory + * @param outputFactory + */ + public ExtensibleStAXArtifactProcessor(StAXArtifactProcessorExtensionPoint processors, XMLInputFactory inputFactory, XMLOutputFactory outputFactory) { + super(); + this.processors = processors; + this.inputFactory = inputFactory; + this.outputFactory = outputFactory; + this.outputFactory.setProperty("javax.xml.stream.isRepairingNamespaces", Boolean.TRUE); + } + + public Object read(XMLStreamReader source) throws ContributionReadException, XMLStreamException { + + // Delegate to the processor associated with the element qname + QName name = source.getName(); + StAXArtifactProcessor processor = (StAXArtifactProcessor)processors.getProcessor(name); + if (processor == null) { + 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); + } + } + } + + @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 input stream. + * @param is The artifact inputstream + * @param type Model type + * @return The model + * @throws ContributionReadException + */ + public MO 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 { + UnrecognizedElementException e = new UnrecognizedElementException(name); + throw e; + } + } catch (ContributionReadException e) { + Location location = reader.getLocation(); + e.setLine(location.getLineNumber()); + e.setColumn(location.getColumnNumber()); + 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); + throw ce; + } + } + + /** + * Write a model to an ouput stream. + * @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) { + throw new ContributionWriteException(e); + } + } + + public QName getArtifactType() { + return null; + } + + public Class getModelType() { + return null; + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleURLArtifactProcessor.java b/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleURLArtifactProcessor.java new file mode 100644 index 0000000000..3c7c886d80 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleURLArtifactProcessor.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.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; + +/** + * The default implementation of a URL artifact processor. + * + * This implementation has a URLArtifactProcessorExtensionPoint and + * it delegate to the proper URLArtifactProcessor by either fileName or fileExtention + * + * @version $Rev$ $Date$ + */ +public class ExtensibleURLArtifactProcessor + implements URLArtifactProcessor { + + private URLArtifactProcessorExtensionPoint processors; + + /** + * Constructs a new URL artifact processor. + * + * @param processors + */ + public ExtensibleURLArtifactProcessor(URLArtifactProcessorExtensionPoint processors) { + this.processors = processors; + } + + @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 MO 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()); + throw e; + } + } + + public String getArtifactType() { + return null; + } + + public Class getModelType() { + return null; + } + + /** + * Utility functions + */ + + private String getFileName(URL url){ + String fileName = url.getPath(); + int pos = fileName.lastIndexOf("/"); + + return fileName.substring(pos +1); + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/PackageProcessor.java b/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/PackageProcessor.java new file mode 100644 index 0000000000..28b268301f --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/PackageProcessor.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.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; + +/** + * Contribution package processors + * These processors understand the internal format of the contribution and how to process the artifacts + * + * @version $Rev$ $Date$ + */ +public interface PackageProcessor { + + /** + * Returns the type of package supported by this package processor. + * + * @return the package type + */ + String getPackageType(); + + /** + * Retrieve a list of artifacts for the specific package type + * + * @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 in the case of special archives such as jar files that have special + * URL structure for internal artifacts + * + * @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/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/PackageProcessorExtensionPoint.java b/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/PackageProcessorExtensionPoint.java new file mode 100644 index 0000000000..27499b5847 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/StAXArtifactProcessor.java b/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/StAXArtifactProcessor.java new file mode 100644 index 0000000000..fcf9347564 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/StAXArtifactProcessorExtensionPoint.java b/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/StAXArtifactProcessorExtensionPoint.java new file mode 100644 index 0000000000..fb272d05bc --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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; + +/** + * A registry for StAX artifact processors. + * + * @version $Rev$ $Date$ + */ +public interface StAXArtifactProcessorExtensionPoint extends + ArtifactProcessorExtensionPoint { + +} diff --git a/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/URLArtifactProcessor.java b/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/URLArtifactProcessor.java new file mode 100644 index 0000000000..eb6201c856 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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 an InputStream. + * + * @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/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/URLArtifactProcessorExtensionPoint.java b/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/URLArtifactProcessorExtensionPoint.java new file mode 100644 index 0000000000..0b02c12830 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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; + +/** + * A registry for Document artifact processors. + * + * @version $Rev$ $Date$ + */ +public interface URLArtifactProcessorExtensionPoint extends + ArtifactProcessorExtensionPoint { + +} diff --git a/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ValidatingXMLStreamReader.java b/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ValidatingXMLStreamReader.java new file mode 100644 index 0000000000..bd1687fafd --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ValidatingXMLStreamReader.java @@ -0,0 +1,319 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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.QName; +import javax.xml.stream.Location; +import javax.xml.stream.XMLStreamConstants; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.util.StreamReaderDelegate; +import javax.xml.validation.Schema; +import javax.xml.validation.ValidatorHandler; + +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$ + */ +public class ValidatingXMLStreamReader extends StreamReaderDelegate implements XMLStreamReader { + private static final Logger logger = Logger.getLogger(ValidatingXMLStreamReader.class.getName()); + + private int level; + private ValidatorHandler handler; + + public ValidatingXMLStreamReader(XMLStreamReader reader, Schema schema) throws XMLStreamException { + super(reader); + if (schema == null) { + return; + } + + handler = schema.newValidatorHandler(); + handler.setDocumentLocator(new LocatorAdaptor()); + try { + handler.setFeature("http://xml.org/sax/features/namespace-prefixes", true); + } catch (SAXException e) { + throw new XMLStreamException(e); + } + + // 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 { + logger.warning(getMessage(exception)); + } + + public void fatalError(SAXParseException exception) throws SAXException { + logger.warning(getMessage(exception)); + } + + public void warning(SAXParseException exception) throws SAXException { + logger.warning(getMessage(exception)); + } + }); + } + + @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) { + throw new XMLStreamException(e.getMessage(), e); + } + 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(); + 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--; + return event; + case XMLStreamConstants.END_DOCUMENT: + handler.endDocument(); + return event; + } + } catch (SAXException e) { + throw new XMLStreamException(e); + } + 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; + } + } + } + + 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); + } + + 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; + } + + /** + * Adaptor for mapping Locator information. + */ + private final class LocatorAdaptor implements Locator { + + private LocatorAdaptor() { + } + + 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/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/ClassReference.java b/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/ClassReference.java new file mode 100644 index 0000000000..6715341ca9 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/ClassReference.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.lang.ref.WeakReference; + +/** + * 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 ClassReference { + + 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; + } + + /** + * Returns true if the class reference is unresolved. + * + * @return Wether or not the class has been resolved + */ + public boolean isUnresolved() { + return clazz == null; + } + + @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/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultImportAllModelResolver.java b/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultImportAllModelResolver.java new file mode 100644 index 0000000000..ce6305814a --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultImportAllModelResolver.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.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 any available contribution + * + * @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 our namespace, try to the 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); + } + } + else if (resolved instanceof org.apache.tuscany.sca.assembly.Base) { + if (!((org.apache.tuscany.sca.assembly.Base)resolved).isUnresolved()) { + return modelClass.cast(resolved); + } + } + } + } + } + + // Model object was not resolved + return unresolved; + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultModelResolverExtensionPoint.java b/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultModelResolverExtensionPoint.java new file mode 100644 index 0000000000..bde0f24341 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultModelResolverExtensionPoint.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.contribution.resolver; + +import java.io.IOException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.tuscany.sca.contribution.util.ServiceConfigurationUtil; + +/** + * The default implementation of a model resolver Class registry. + * + * @version $Rev$ $Date$ + */ +public class DefaultModelResolverExtensionPoint implements ModelResolverExtensionPoint { + + private final Map, Class> resolvers = new HashMap, Class>(); + private Map loadedResolvers; + + /** + * Constructs a new model resolver registry. + */ + public DefaultModelResolverExtensionPoint() { + } + + public void addResolver(Class modelType, Class resolver) { + resolvers.put(modelType, resolver); + } + + public void removeResolver(Class modelType) { + resolvers.remove(modelType); + } + + public Class getResolver(Class modelType) { + loadModelResolvers(); + + Class[] classes = modelType.getInterfaces(); + for (Class c : classes) { + Class resolver = resolvers.get(c); + if (resolver == null) { + String className = loadedResolvers.get(c.getName()); + if (className != null) { + try { + return (Class)Class.forName(className, true, modelType.getClassLoader()); + } catch (ClassNotFoundException e) { + throw new IllegalArgumentException(e); + } + } + } else { + return resolver; + } + } + + Class resolver = resolvers.get(modelType); + if (resolver == null) { + String className = loadedResolvers.get(modelType.getName()); + if (className != null) { + try { + return (Class)Class.forName(className, true, modelType.getClassLoader()); + } catch (ClassNotFoundException e) { + throw new IllegalArgumentException(e); + } + } + } + return resolver; + } + + /** + * Dynamically load model resolvers declared under META-INF/services + */ + private void loadModelResolvers() { + if (loadedResolvers != null) + return; + loadedResolvers = new HashMap(); + + // Get the model resolver service declarations + ClassLoader classLoader = ModelResolver.class.getClassLoader(); + List modelResolverDeclarations; + try { + modelResolverDeclarations = ServiceConfigurationUtil.getServiceClassNames(classLoader, ModelResolver.class.getName()); + } catch (IOException e) { + throw new IllegalStateException(e); + } + + // Load model resolvers + for (String dataBindingDeclaration: modelResolverDeclarations) { + Map attributes = ServiceConfigurationUtil.parseServiceDeclaration(dataBindingDeclaration); + String className = attributes.get("class"); + String model = attributes.get("model"); + + loadedResolvers.put(model, className); + } + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/ExtensibleModelResolver.java b/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/ExtensibleModelResolver.java new file mode 100644 index 0000000000..e6899e3174 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/ExtensibleModelResolver.java @@ -0,0 +1,152 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.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; + +/** + * 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 final ModelResolverExtensionPoint resolvers; + private final ModelFactoryExtensionPoint factories; + private final Contribution contribution; + private final Map, ModelResolver> resolverInstances = new HashMap, ModelResolver>(); + private Map map = new HashMap(); + private ModelResolver domainResolver = null; + + /** + * Constructs an extensible model resolver + * + * @param resolvers + * @param contribution + */ + public ExtensibleModelResolver(Contribution contribution, + ModelResolverExtensionPoint resolvers, + ModelFactoryExtensionPoint factories) { + this.contribution = contribution; + this.resolvers = resolvers; + this.factories = factories; + } + + /** + * 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 = resolverInstances.get(c); + if (resolverInstance != null) { + return resolverInstance; + } + + // We don't have an instance, lookup a model resolver class + // and instantiate it + Class resolverClass = resolvers.getResolver(c); + if (resolverClass != null) { + try { + Constructor constructor = + resolverClass + .getConstructor(new Class[] {Contribution.class, ModelFactoryExtensionPoint.class}); + if (constructor != null) { + + // Construct the model resolver instance and cache it + resolverInstance = constructor.newInstance(contribution, factories); + resolverInstances.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) { + ModelResolver resolver = getModelResolverInstance(unresolved.getClass()); + if (resolver != null) { + return resolver.resolveModel(modelClass, unresolved); + } else { + if (domainResolver != null) { + Object resolved = domainResolver.resolveModel(modelClass, unresolved); + if (resolved != null && resolved != unresolved) { + return modelClass.cast(resolved); + } + } + Object resolved = map.get(unresolved); + if (resolved != null) { + // Return the resolved object + return modelClass.cast(resolved); + } + } + + return unresolved; + } + + public ModelResolver getDomainResolver() { + return domainResolver; + } + + public void setDomainResolver(ModelResolver domainResolver) { + this.domainResolver = domainResolver; + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/ModelResolver.java b/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/ModelResolver.java new file mode 100644 index 0000000000..850f79fdea --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/ModelResolver.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; + +/** + * SCA Assemblies reference many 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 URIs that do not point to a specific entity. Resolution of these + * references to concrete artifacts is necessary as part of the operation of the + * SCA domain. + * + * @version $Rev$ $Date$ + */ +public interface 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/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/ModelResolverExtensionPoint.java b/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/ModelResolverExtensionPoint.java new file mode 100644 index 0000000000..0b14b7f3c3 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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 Artifact Type as the key + * + * @param modelType The model artifact type + * @param resolver The model resolver Class + */ + void addResolver(Class modelType, Class resolver); + + /** + * Remove the Model Resolver Class for a specific Artifact Type + * + * @param modelType The model artifact type + */ + void removeResolver(Class modelType); + + /** + * Retrieve a Model Resolver Class for a specific Artifact Type + * + * @param modelType The model artifact type + * @return The model resolver Class + */ + Class getResolver(Class modelType); +} diff --git a/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/AbstractContributionException.java b/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/AbstractContributionException.java new file mode 100644 index 0000000000..e5b18b4738 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/AbstractContributionException.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.contribution.service; + +import java.io.PrintWriter; + +/** + * The root checked exception for the Contribution Service. + * + * @version $Rev$ $Date$ + */ +public abstract class AbstractContributionException extends Exception { + private static final long serialVersionUID = -7847121698339635268L; + private final String identifier; + + /** + * Override constructor from Exception. + * + * @see Exception + */ + public AbstractContributionException() { + super(); + this.identifier = null; + } + + /** + * Override constructor from Exception. + * + * @param message passed to Exception + * @see Exception + */ + public AbstractContributionException(String message) { + super(message); + this.identifier = null; + } + + /** + * Override constructor from Exception. + * + * @param message passed to Exception + * @param identifier additional error information referred to in the error message + * @see Exception + */ + public AbstractContributionException(String message, String identifier) { + super(message); + this.identifier = identifier; + } + + /** + * Override constructor from Exception. + * + * @param message passed to Exception + * @param cause passed to Exception + * @see Exception + */ + public AbstractContributionException(String message, Throwable cause) { + super(message, cause); + this.identifier = null; + } + + /** + * Override constructor from Exception. + * + * @param message passed to Exception + * @param identifier additional error information referred to in the error message + * @param cause passed to Exception + * @see Exception + */ + public AbstractContributionException(String message, String identifier, Throwable cause) { + super(message, cause); + this.identifier = identifier; + } + + /** + * Override constructor from Exception. + * + * @param cause passed to Exception + * @see Exception + */ + public AbstractContributionException(Throwable cause) { + super(cause); + this.identifier = null; + } + + /** + * Returns a string representing additional error information referred to in the error message. + * + * @return additional error information + */ + public String getIdentifier() { + return identifier; + } + + public PrintWriter appendBaseMessage(PrintWriter writer) { + if (identifier == null) { + if (super.getMessage() == null) { + return writer; + } + return writer.append(super.getMessage()); + } + if (super.getMessage() != null) { + writer.append(super.getMessage()); + } + writer.append(" [").append(identifier).append(']'); + return writer; + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionException.java b/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionException.java new file mode 100644 index 0000000000..484200286b --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionException.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.service; + +/** + * Base class for exceptions raised by contribution services. + * + * @version $Rev$ $Date$ + */ +public class ContributionException extends AbstractContributionException { + + private static final long serialVersionUID = 4432880414927652578L; + + protected ContributionException() { + super(); + } + + protected ContributionException(String message) { + super(message); + } + + protected ContributionException(String message, String identifier) { + super(message, identifier); + } + + protected ContributionException(String message, Throwable cause) { + super(message, cause); + } + + protected ContributionException(String message, String identifier, Throwable cause) { + super(message, identifier, cause); + } + + public ContributionException(Throwable cause) { + super(cause); + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionListener.java b/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionListener.java new file mode 100644 index 0000000000..5158eaf85c --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionListenerExtensionPoint.java b/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionListenerExtensionPoint.java new file mode 100644 index 0000000000..ce2b4b13c3 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionReadException.java b/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionReadException.java new file mode 100644 index 0000000000..33399dcc2f --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionRepository.java b/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionRepository.java new file mode 100644 index 0000000000..838359be5f --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionResolveException.java b/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionResolveException.java new file mode 100644 index 0000000000..ecb774ac0c --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionRuntimeException.java b/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionRuntimeException.java new file mode 100644 index 0000000000..4bf29a3993 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionService.java b/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionService.java new file mode 100644 index 0000000000..d82f89b79e --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionService.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.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 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 DeploymentException 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 DeploymentException 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 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 DeploymentException 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 DeploymentException 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/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionWireException.java b/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionWireException.java new file mode 100644 index 0000000000..f67b2a1e51 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionWireException.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; + + +/** + * Denotes a problem while wiring models inside an SCA contribution. + * + * @version $Rev$ $Date$ + */ +public class ContributionWireException extends ContributionException { + private static final long serialVersionUID = -7459051598906813461L; + + public ContributionWireException(String message) { + super(message); + } + + public ContributionWireException(String message, Throwable cause) { + super(message, cause); + } + + public ContributionWireException(Throwable cause) { + super(cause); + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionWriteException.java b/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionWriteException.java new file mode 100644 index 0000000000..8bfdedf180 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/DefaultContributionListenerExtensionPoint.java b/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/DefaultContributionListenerExtensionPoint.java new file mode 100644 index 0000000000..9e77705ed3 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/DefaultContributionListenerExtensionPoint.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.service; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.sca.contribution.util.ServiceConfigurationUtil; + +/** + * Default implementation of a contribution listener extension point. + * + * @version $Rev$ $Date$ + */ +public class DefaultContributionListenerExtensionPoint implements ContributionListenerExtensionPoint { + + private List listeners = new ArrayList(); + private boolean loadedListeners; + + 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 + */ + private void loadListeners() { + if (loadedListeners) + return; + + // Get the databinding service declarations + ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); + List listenerDeclarations; + try { + listenerDeclarations = ServiceConfigurationUtil.getServiceClassNames(classLoader, ContributionListener.class.getName()); + } catch (IOException e) { + throw new IllegalStateException(e); + } + + // Load data bindings + for (String listenerDeclaration: listenerDeclarations) { + ContributionListener listener; + try { + Class listenerClass = (Class)Class.forName(listenerDeclaration, true, classLoader); + 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/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ExtensibleContributionListener.java b/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ExtensibleContributionListener.java new file mode 100644 index 0000000000..0b9aca70cf --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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 resigtered listeners + */ + public void contributionAdded(ContributionRepository repository, Contribution contribution) { + for (ContributionListener listener : listeners.getContributionListeners()) { + try { + listener.contributionAdded(repository, contribution); + } catch (Exception e) { + // ignore, contiue 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, contiue 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, contiue to the next listener + } + + } + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/TypeDescriber.java b/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/TypeDescriber.java new file mode 100644 index 0000000000..b0e02f06fa --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/UnrecognizedElementException.java b/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/UnrecognizedElementException.java new file mode 100644 index 0000000000..5079db4904 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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.toString()); + 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/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/UnsupportedContentTypeException.java b/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/UnsupportedContentTypeException.java new file mode 100644 index 0000000000..764fe251f2 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/UnsupportedContentTypeException.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.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 UnsupportedContentTypeException extends ContributionException { + private static final long serialVersionUID = -1831797280021355672L; + + /** + * Constructor specifying the Content-Type value that is not supported. + * + * @param contentType the type that is not supported + */ + public UnsupportedContentTypeException(String contentType) { + super(contentType); + } + + /** + * Constructor specifying the Content-Type value that is not supported + * and an identifier to use with this exception (typically the resource being processed). + * + * @param contentType the type that is not supported + * @param identifier an identifier for this exception + */ + public UnsupportedContentTypeException(String contentType, String identifier) { + super(contentType, identifier); + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/util/ServiceConfigurationUtil.java b/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/util/ServiceConfigurationUtil.java new file mode 100644 index 0000000000..88d960994c --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/util/ServiceConfigurationUtil.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.util; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.URL; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.StringTokenizer; + +public class ServiceConfigurationUtil { + + /** + * Read the service name from a configuration file + * + * @param classLoader + * @param name The name of the service class + * @return A class name which extends/implements the service class + * @throws IOException + */ + public static List getServiceClassNames(ClassLoader classLoader, String name) throws IOException { + List classNames = new ArrayList(); + for (URL url: Collections.list(classLoader.getResources("META-INF/services/" + name))) { + InputStream is = url.openStream(); + BufferedReader reader = null; + try { + reader = new BufferedReader(new InputStreamReader(is)); + while (true) { + String line = reader.readLine(); + if (line == null) + break; + line = line.trim(); + if (!line.startsWith("#") && !"".equals(line)) { + classNames.add(line.trim()); + } + } + } finally { + if (reader != null) + reader.close(); + if (is != null) { + try { + is.close(); + } catch (IOException ioe) {} + } + } + } + return classNames; + } + + /** + * Parse a service declaration in the form class;attr=value,attr=value and + * return a map of attributes + * + * @param declaration + * @return a map of attributes + */ + public static Map parseServiceDeclaration(String declaration) { + Map attributes = new HashMap(); + StringTokenizer tokens = new StringTokenizer(declaration); + String className = tokens.nextToken(";"); + if (className != null) + attributes.put("class", className); + for (; tokens.hasMoreTokens(); ) { + String key = tokens.nextToken("=").substring(1); + if (key == null) + break; + String value = tokens.nextToken(",").substring(1); + if (value == null) + break; + attributes.put(key, value); + } + return attributes; + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint b/tags/java/sca/1.0-RC1b/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint new file mode 100644 index 0000000000..6b4d2ebdeb --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.ContributionPostProcessorExtensionPoint b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.PackageProcessorExtensionPoint b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.URLArtifactProcessorExtensionPoint b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolverExtensionPoint b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.service.ContributionListenerExtensionPoint b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/core-databinding/.checkstyle b/tags/java/sca/1.0-RC1b/modules/core-databinding/.checkstyle new file mode 100644 index 0000000000..c7b30ffd5e --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core-databinding/.checkstyle @@ -0,0 +1,25 @@ + + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/core-databinding/.pmd b/tags/java/sca/1.0-RC1b/modules/core-databinding/.pmd new file mode 100644 index 0000000000..2db10d6a6a --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core-databinding/.pmd @@ -0,0 +1,20 @@ + + +truefalse \ No newline at end of file diff --git a/tags/java/sca/1.0-RC1b/modules/core-databinding/.ruleset b/tags/java/sca/1.0-RC1b/modules/core-databinding/.ruleset new file mode 100644 index 0000000000..ba9b5ce886 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core-databinding/.ruleset @@ -0,0 +1,190 @@ + + + + PMD Plugin preferences rule set + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/core-databinding/DISCLAIMER b/tags/java/sca/1.0-RC1b/modules/core-databinding/DISCLAIMER new file mode 100644 index 0000000000..d68a410903 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core-databinding/DISCLAIMER @@ -0,0 +1,8 @@ +Apache Tuscany is an effort undergoing incubation at The Apache Software +Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is +required of all newly accepted projects until a further review indicates that +the infrastructure, communications, and decision making process have stabilized +in a manner consistent with other successful ASF projects. While incubation +status is not necessarily a reflection of the completeness or stability of the +code, it does indicate that the project has yet to be fully endorsed by the ASF. + diff --git a/tags/java/sca/1.0-RC1b/modules/core-databinding/LICENSE b/tags/java/sca/1.0-RC1b/modules/core-databinding/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/core-databinding/NOTICE b/tags/java/sca/1.0-RC1b/modules/core-databinding/NOTICE new file mode 100644 index 0000000000..94481d6cfa --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core-databinding/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2007 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/tags/java/sca/1.0-RC1b/modules/core-databinding/pom.xml b/tags/java/sca/1.0-RC1b/modules/core-databinding/pom.xml new file mode 100644 index 0000000000..992c968c4c --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core-databinding/pom.xml @@ -0,0 +1,69 @@ + + + + + org.apache.tuscany.sca + tuscany-modules + 1.0-incubating + ../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-core-spi + ${project.version} + compile + + + + org.apache.tuscany.sca + tuscany-interface-java-xml + ${project.version} + compile + + + + org.codehaus.woodstox + wstx-asl + runtime + 3.2.1 + + + + stax + stax-api + 1.0.1 + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/module/DataBindingModuleActivator.java b/tags/java/sca/1.0-RC1b/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/module/DataBindingModuleActivator.java new file mode 100644 index 0000000000..aaa333c336 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/module/DataBindingModuleActivator.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.core.databinding.module; + +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.databinding.processor.DataBindingJavaInterfaceProcessor; +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.Output2OutputTransformer; +import org.apache.tuscany.sca.core.databinding.wire.DataBindingRuntimeWireProcessor; +import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint; +import org.apache.tuscany.sca.databinding.TransformerExtensionPoint; +import org.apache.tuscany.sca.databinding.impl.Group2GroupTransformer; +import org.apache.tuscany.sca.databinding.impl.MediatorImpl; +import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory; +import org.apache.tuscany.sca.runtime.RuntimeWireProcessorExtensionPoint; + +/** + * @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); + + MediatorImpl mediator = new MediatorImpl(dataBindings, transformers); + Input2InputTransformer input2InputTransformer = new Input2InputTransformer(); + input2InputTransformer.setMediator(mediator); + transformers.addTransformer(input2InputTransformer); + + Output2OutputTransformer output2OutputTransformer = new Output2OutputTransformer(); + output2OutputTransformer.setMediator(mediator); + transformers.addTransformer(output2OutputTransformer); + + Exception2ExceptionTransformer exception2ExceptionTransformer = new Exception2ExceptionTransformer(); + exception2ExceptionTransformer.setMediator(mediator); + transformers.addTransformer(exception2ExceptionTransformer); + + Group2GroupTransformer group2GroupTransformer = new Group2GroupTransformer(); + group2GroupTransformer.setMediator(mediator); + transformers.addTransformer(group2GroupTransformer); + + ModelFactoryExtensionPoint modelFactories = registry.getExtensionPoint(ModelFactoryExtensionPoint.class); + JavaInterfaceFactory javaFactory = modelFactories.getFactory(JavaInterfaceFactory.class); + javaFactory.addInterfaceVisitor(new DataBindingJavaInterfaceProcessor(dataBindings)); + + RuntimeWireProcessorExtensionPoint wireProcessorExtensionPoint = registry.getExtensionPoint(RuntimeWireProcessorExtensionPoint.class); + if (wireProcessorExtensionPoint != null) { + wireProcessorExtensionPoint.addWireProcessor(new DataBindingRuntimeWireProcessor(mediator, dataBindings)); + } + + } + + public void stop(ExtensionPointRegistry registry) { + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/processor/DataBindingJavaInterfaceProcessor.java b/tags/java/sca/1.0-RC1b/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/processor/DataBindingJavaInterfaceProcessor.java new file mode 100644 index 0000000000..5004471d29 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/processor/DataBindingJavaInterfaceProcessor.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.databinding.processor; + +import java.lang.annotation.Annotation; +import java.lang.reflect.Method; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +import org.apache.tuscany.sca.databinding.javabeans.JavaBeansDataBinding; +import org.apache.tuscany.sca.databinding.javabeans.SimpleJavaDataBinding; +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.introspect.JavaInterfaceVisitor; +import org.osoa.sca.annotations.Reference; + +/** + * The databinding annotation processor for java interfaces + * + * @version $Rev$ $Date$ + */ +public class DataBindingJavaInterfaceProcessor implements JavaInterfaceVisitor { + private DataBindingExtensionPoint dataBindingRegistry; + + public DataBindingJavaInterfaceProcessor(@Reference + 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.wrapperStyle(); + } + + Map opMap = new HashMap(); + for (Operation op : javaInterface.getOperations()) { + opMap.put(op.getName(), op); + if (dataBindingId != null) { + op.setDataBinding(dataBindingId); + op.setWrapperStyle(wrapperStyle); + } + } + for (Method method : clazz.getMethods()) { + Operation operation = opMap.get(method.getName()); + DataBinding methodDataBinding = clazz.getAnnotation(DataBinding.class); + if (methodDataBinding == null) { + methodDataBinding = dataBinding; + } + dataBindingId = null; + wrapperStyle = false; + if (dataBinding != null) { + dataBindingId = dataBinding.value(); + wrapperStyle = dataBinding.wrapperStyle(); + operation.setDataBinding(dataBindingId); + operation.setWrapperStyle(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, method.getParameterAnnotations()[i]); + 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, method.getAnnotations()); + } + for (org.apache.tuscany.sca.interfacedef.DataType d : operation.getFaultTypes()) { + if (d.getDataBinding() == null) { + d.setDataBinding(dataBindingId); + } + // TODO: Handle exceptions + dataBindingRegistry.introspectType(d, method.getAnnotations(), true); + } + + // JIRA: TUSCANY-842 + if (operation.getDataBinding() == null) { + assignOperationDataBinding(operation); + } + + // FIXME: Do we want to heuristically check the wrapper style? + // introspectWrapperStyle(operation); + } + } + + /* + * 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 void assignOperationDataBinding(Operation operation) { + + String nonDefaultDataBindingName = null; + + // Can't use DataType since operation.getInputType() returns: DataType> + List opDataTypes = new LinkedList(); + + opDataTypes.addAll(operation.getInputType().getLogical()); + opDataTypes.add(operation.getOutputType()); + opDataTypes.addAll(operation.getFaultTypes()); + + for (DataType d : opDataTypes) { + if (d != null) { + String dataBinding = d.getDataBinding(); + // Assumes JavaBeans DB is default + if (dataBinding != null && !dataBinding.equals(JavaBeansDataBinding.NAME) + && !dataBinding.equals(SimpleJavaDataBinding.NAME)) { + if (nonDefaultDataBindingName != null) { + if (!nonDefaultDataBindingName.equals(dataBinding)) { + // We've seen two different non-default DBs, e.g. SDO and JAXB + // so unset the string and break out of the loop + nonDefaultDataBindingName = null; + break; + } else { + continue; + } + } else { + nonDefaultDataBindingName = dataBinding; + } + } + } + } + + // We have a DB worthy of promoting to operation level. + if (nonDefaultDataBindingName != null) { + operation.setDataBinding(nonDefaultDataBindingName); + } + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Exception2ExceptionTransformer.java b/tags/java/sca/1.0-RC1b/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Exception2ExceptionTransformer.java new file mode 100644 index 0000000000..cd71869154 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Exception2ExceptionTransformer.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.core.databinding.transformers; + +import org.apache.tuscany.sca.databinding.DataBinding; +import org.apache.tuscany.sca.databinding.ExceptionHandler; +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.Transformer; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.osoa.sca.annotations.Reference; +import org.osoa.sca.annotations.Service; + +/** + * This is a special transformer to transform the exception from one IDL to the + * other one + */ +@Service(Transformer.class) +public class Exception2ExceptionTransformer extends BaseTransformer implements + PullTransformer { + + protected Mediator mediator; + + 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 + */ + @Reference + public void setMediator(Mediator mediator) { + this.mediator = mediator; + } + + /** + * @see org.apache.tuscany.sca.databinding.impl.BaseTransformer#getSourceType() + */ + @Override + protected Class getSourceType() { + return Exception.class; + } + + /** + * @see org.apache.tuscany.sca.databinding.impl.BaseTransformer#getTargetType() + */ + @Override + protected Class getTargetType() { + return Exception.class; + } + + /** + * @see org.apache.tuscany.sca.databinding.Transformer#getWeight() + */ + @Override + public int getWeight() { + return 10000; + } + + @SuppressWarnings("unchecked") + public Exception transform(Exception source, TransformationContext context) { + DataType sourceType = context.getSourceDataType(); + + DataType targetType = context.getTargetDataType(); + + ExceptionHandler exceptionHandler = getExceptionHandler(sourceType); + if (exceptionHandler == null) { + return source; + } + + Object sourceFaultInfo = exceptionHandler.getFaultInfo(source); + Object targetFaultInfo = + mediator.mediate(sourceFaultInfo, sourceType.getLogical(), targetType.getLogical(), context.getMetadata()); + + ExceptionHandler targetHandler = getExceptionHandler(targetType); + + if (targetHandler != null) { + Exception targetException = + targetHandler.createException(targetType, source.getMessage(), targetFaultInfo, source.getCause()); + return targetException; + } + + // FIXME + return source; + + } + + private ExceptionHandler getExceptionHandler(DataType targetType) { + DataType targetFaultType = (DataType)targetType.getLogical(); + DataBinding targetDataBinding = + mediator.getDataBindings().getDataBinding(targetFaultType.getDataBinding()); + if (targetDataBinding == null) { + return null; + } + ExceptionHandler targetHandler = targetDataBinding.getExceptionHandler(); + return targetHandler; + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Input2InputTransformer.java b/tags/java/sca/1.0-RC1b/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Input2InputTransformer.java new file mode 100644 index 0000000000..e71c504ff5 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Input2InputTransformer.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.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.Transformer; +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; +import org.osoa.sca.annotations.Service; + +/** + * This is a special transformer to transform the input from one IDL to the + * other one + */ +@Service(Transformer.class) +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; + } + + @SuppressWarnings("unchecked") + public Object[] transform(Object[] source, TransformationContext context) { + DataType> sourceType = context.getSourceDataType(); + Operation sourceOp = context.getSourceOperation(); + boolean sourceWrapped = sourceOp != null && sourceOp.isWrapperStyle(); + + 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.isWrapperStyle(); + WrapperHandler targetWrapperHandler = null; + String targetDataBinding = getDataBinding(targetOp); + targetWrapperHandler = getWrapperHandler(targetDataBinding, targetWrapped); + + if ((!sourceWrapped) && targetWrapped) { + // Unwrapped --> Wrapped + WrapperInfo wrapper = targetOp.getWrapper(); + ElementInfo wrapperElement = wrapper.getInputWrapperElement(); + + // If the source can be wrapped, wrapped it first + if (sourceWrapperHandler != null) { + DataType sourceWrapperType = + sourceWrapperHandler.getWrapperType(wrapperElement, wrapper.getInputChildElements(), context); + if (sourceWrapperType != null) { + Object sourceWrapper = sourceWrapperHandler.create(wrapperElement, context); + if (sourceWrapper != null) { + for (int i = 0; i < source.length; i++) { + ElementInfo argElement = wrapper.getInputChildElements().get(i); + sourceWrapperHandler.setChild(sourceWrapper, i, argElement, source[i]); + } + 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(wrapperElement, context); + if (source == null) { + return new Object[] {targetWrapper}; + } + List argTypes = wrapper.getUnwrappedInputType().getLogical(); + + for (int i = 0; i < source.length; i++) { + ElementInfo argElement = wrapper.getInputChildElements().get(i); + DataType argType = argTypes.get(i); + Object child = source[i]; + child = mediator.mediate(source[i], sourceType.getLogical().get(i), argType, context.getMetadata()); + targetWrapperHandler.setChild(targetWrapper, i, argElement, child); + } + return new Object[] {targetWrapper}; + + } else if (sourceWrapped && (!targetWrapped)) { + // 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, wrapperElement, childElements, context)) { + DataType targetWrapperType = + targetWrapperHandler.getWrapperType(wrapperElement, childElements, context); + if (targetWrapperType != null) { + Object targetWrapper = + mediator.mediate(sourceWrapper, sourceType.getLogical().get(0), targetWrapperType, context + .getMetadata()); + target = targetWrapperHandler.getChildren(targetWrapper, childElements, context).toArray(); + return target; + } + } + } + Object[] sourceChildren = sourceWrapperHandler.getChildren(sourceWrapper, childElements, context).toArray(); + target = new Object[sourceChildren.length]; + for (int i = 0; i < sourceChildren.length; i++) { + DataType childType = sourceOp.getWrapper().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) { + return operation.getDataBinding(); + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Output2OutputTransformer.java b/tags/java/sca/1.0-RC1b/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Output2OutputTransformer.java new file mode 100644 index 0000000000..43439b1385 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Output2OutputTransformer.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.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.Transformer; +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; +import org.osoa.sca.annotations.Service; + +/** + * This is a special transformer to transform the output from one IDL to the + * other one + */ +@Service(Transformer.class) +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) { + return operation.getDataBinding(); + } + + 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; + } + + @SuppressWarnings("unchecked") + public Object transform(Object response, TransformationContext context) { + try { + DataType sourceType = context.getSourceDataType(); + Operation sourceOp = context.getSourceOperation(); + boolean sourceWrapped = sourceOp != null && sourceOp.isWrapperStyle(); + + 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.isWrapperStyle(); + WrapperHandler targetWrapperHandler = null; + String targetDataBinding = getDataBinding(targetOp); + targetWrapperHandler = getWrapperHandler(targetDataBinding, targetWrapped); + + if ((!sourceWrapped) && targetWrapped) { + // Unwrapped --> Wrapped + WrapperInfo wrapper = targetOp.getWrapper(); + ElementInfo wrapperElement = wrapper.getOutputWrapperElement(); + List childElements = wrapper.getOutputChildElements(); + + // If the source can be wrapped, wrapped it first + if (sourceWrapperHandler != null) { + DataType sourceWrapperType = + sourceWrapperHandler.getWrapperType(wrapperElement, childElements, context); + if (sourceWrapperType != null) { + Object sourceWrapper = sourceWrapperHandler.create(wrapperElement, context); + if (sourceWrapper != null) { + if (!childElements.isEmpty()) { + // Set the return value + ElementInfo returnElement = wrapper.getOutputChildElements().get(0); + sourceWrapperHandler.setChild(sourceWrapper, 0, returnElement, response); + } + Object targetWrapper = + mediator.mediate(sourceWrapper, sourceWrapperType, targetType.getLogical(), context + .getMetadata()); + return targetWrapper; + } + } + } + Object targetWrapper = targetWrapperHandler.create(wrapper.getOutputWrapperElement(), context); + + if (childElements.isEmpty()) { + // void output + return targetWrapper; + } + ElementInfo argElement = childElements.get(0); + DataType argType = wrapper.getUnwrappedOutputType(); + Object child = response; + child = mediator.mediate(response, sourceType.getLogical(), argType, context.getMetadata()); + targetWrapperHandler.setChild(targetWrapper, 0, argElement, child); + return targetWrapper; + } else if (sourceWrapped && (!targetWrapped)) { + // Wrapped to Unwrapped + Object sourceWrapper = response; + List childElements = sourceOp.getWrapper().getOutputChildElements(); + if (childElements.isEmpty()) { + // The void output + return null; + } + if (targetWrapperHandler != null) { + ElementInfo wrapperElement = sourceOp.getWrapper().getOutputWrapperElement(); + + // 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, wrapperElement, childElements, context)) { + DataType targetWrapperType = + targetWrapperHandler.getWrapperType(wrapperElement, childElements, context); + if (targetWrapperType != null) { + Object targetWrapper = + mediator.mediate(sourceWrapper, sourceType.getLogical(), targetWrapperType, context + .getMetadata()); + return targetWrapperHandler.getChildren(targetWrapper, childElements, context).get(0); + } + } + } + Object child = sourceWrapperHandler.getChildren(sourceWrapper, childElements, context).get(0); + DataType childType = sourceOp.getWrapper().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/tags/java/sca/1.0-RC1b/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/DataBindingRuntimeWireProcessor.java b/tags/java/sca/1.0-RC1b/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/DataBindingRuntimeWireProcessor.java new file mode 100644 index 0000000000..a3f9c4ed0b --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/DataBindingRuntimeWireProcessor.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.core.databinding.wire; + +import java.lang.reflect.Method; +import java.util.List; + +import org.apache.tuscany.sca.assembly.Implementation; +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.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.runtime.RuntimeComponent; +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; + + public DataBindingRuntimeWireProcessor(Mediator mediator, DataBindingExtensionPoint dataBindings) { + super(); + this.mediator = mediator; + this.dataBindings = dataBindings; + } + + 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.isWrapperStyle() != target.isWrapperStyle()) { + 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 DataTransformationInteceptor(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 (requiresCopy(wire, sourceOperation, targetOperation)) { + interceptor = new PassByValueInteceptor(dataBindings, targetOperation); + } + } + if (interceptor != null) { + chain.addInterceptor(0, interceptor); + } + } + + } + + /** + * Pass-by-value copies are required if the interfaces are remotable unless the + * implementation uses the @AllowsPassByReference annotation. + */ + protected boolean requiresCopy(RuntimeWire wire, Operation sourceOperation, Operation targetOperation) { + if (!sourceOperation.getInterface().isRemotable()) { + return false; + } + if (!targetOperation.getInterface().isRemotable()) { + return false; + } + + if (allowsPassByReference(wire.getSource().getComponent(), sourceOperation)) { + return false; + } + + if (allowsPassByReference(wire.getTarget().getComponent(), sourceOperation)) { + return false; + } + + return true; + } + + /** + * Does the implementation use the @AllowsPassByReference annotation for the operation. + * Uses reflection to avoid a dependency on JavaImplementation because the isAllowsPassByReference + * and getAllowsPassByReference methods are not on the Implementation interface. + * TODO: move isAllowsPassByReference/getAllowsPassByReference to Implementation interface + */ + protected boolean allowsPassByReference(RuntimeComponent component, Operation operation) { + if (component == null || component.getImplementation() == null) { + return true; // err on the side of no copies + } + Implementation impl = component.getImplementation(); + try { + + Method m = impl.getClass().getMethod("isAllowsPassByReference", new Class[] {}); + if ((Boolean)m.invoke(impl, new Object[]{})) { + return true; + } + + m = impl.getClass().getMethod("getAllowsPassByReferenceMethods", new Class[] {}); + List ms = (List)m.invoke(impl, new Object[]{}); + if (ms != null) { + for (Method m2 : ms) { + // simple name matching is ok as its a remote operation so no overloading + if (operation.getName().equals(m2.getName())) + return true; + } + } + + } catch (Exception e) { + // ignore, assume the impl has no isAllowsPassByReference method + } + + return false; + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/DataTransformationInteceptor.java b/tags/java/sca/1.0-RC1b/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/DataTransformationInteceptor.java new file mode 100644 index 0000000000..bbe588c4bb --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/DataTransformationInteceptor.java @@ -0,0 +1,261 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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.lang.reflect.InvocationTargetException; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.HashMap; +import java.util.Map; + +import org.apache.tuscany.sca.databinding.DataBinding; +import org.apache.tuscany.sca.databinding.ExceptionHandler; +import org.apache.tuscany.sca.databinding.Mediator; +import org.apache.tuscany.sca.databinding.TransformationException; +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.FaultException; +import org.apache.tuscany.sca.interfacedef.util.XMLType; +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 accross databindings on the wire + * + * @version $Rev$ $Date$ + */ +public class DataTransformationInteceptor implements Interceptor { + private Invoker next; + + private Operation sourceOperation; + + private Operation targetOperation; + + private Mediator mediator; + + public DataTransformationInteceptor(RuntimeWire wire, + Operation sourceOperation, + Operation targetOperation, + Mediator mediator) { + super(); + this.sourceOperation = sourceOperation; + this.targetOperation = targetOperation; + this.mediator = mediator; + } + + public Invoker getNext() { + return next; + } + + public Message invoke(Message msg) { + Object input = transform(msg.getBody(), sourceOperation.getInputType(), targetOperation.getInputType(), false); + msg.setBody(input); + Message resultMsg = next.invoke(msg); + Object result = resultMsg.getBody(); + if (sourceOperation.isNonBlocking()) { + // Not to reset the message body + return resultMsg; + } + + // FIXME: Should we fix the Operation model so that getOutputType + // returns DataType>? + DataType targetType = + new DataTypeImpl(DataBinding.IDL_OUTPUT, Object.class, targetOperation.getOutputType()); + + DataType sourceType = + new DataTypeImpl(DataBinding.IDL_OUTPUT, Object.class, sourceOperation.getOutputType()); + + if (resultMsg.isFault()) { + + // FIXME: We need to figure out what fault type it is and then + // transform it + // back the source fault type + // throw new InvocationRuntimeException((Throwable) result); + + if ((result instanceof Exception) && !(result instanceof RuntimeException)) { + // 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) { + if (((FaultException)result).isMatchingType(exType.getLogical())) { + targetDataType = exType; + break; + } + } else { + targetDataType = exType; + break; + } + } + } + + if (targetDataType == null) { + // Not a business exception + return resultMsg; + } + + DataType targetFaultType = getFaultType(targetDataType); + if (targetFaultType == null) { + throw new TransformationException("Target fault type cannot be resolved"); + } + + // 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) { + throw new TransformationException("No matching source fault type is found"); + } + + Object newResult = + transformException(result, targetDataType, sourceDataType, targetFaultType, sourceFaultType); + if (newResult != result) { + resultMsg.setFaultBody(newResult); + } + } + + } else { + assert !(result instanceof Throwable) : "Expected messages that are not throwable " + result; + + Object newResult = transform(result, targetType, sourceType, true); + if (newResult != result) { + resultMsg.setBody(newResult); + } + } + + return resultMsg; + } + + private Object transform(Object source, DataType sourceType, DataType targetType, boolean isResponse) { + if (sourceType == targetType || (sourceType != null && sourceType.equals(targetType))) { + return source; + } + Map metadata = new HashMap(); + metadata.put("source.operation", isResponse? targetOperation: sourceOperation); + metadata.put("target.operation", isResponse? sourceOperation: targetOperation); + return mediator.mediate(source, sourceType, targetType, metadata); + } + + private DataType getFaultType(DataType exceptionType) { + // FIXME: We cannot assume the exception will have a databinding set + DataBinding targetDataBinding = + mediator.getDataBindings().getDataBinding(exceptionType.getDataBinding()); + if (targetDataBinding == null) { + return null; + } + ExceptionHandler targetHandler = targetDataBinding.getExceptionHandler(); + if (targetHandler == null) { + return null; + } + return targetHandler.getFaultType(exceptionType); + } + + private boolean typesMatch(Object first, Object second) { + if (first.equals(second)) { + return true; + } + if (first instanceof XMLType && second instanceof Class) { + if (toJavaClassName((XMLType)first).equals(((Class)second).getName())) { + return true; + } + } + if (first instanceof Class && second instanceof XMLType) { + if (((Class)first).getName().equals(toJavaClassName((XMLType)second))) { + return true; + } + } + return false; + } + + private String toJavaClassName(XMLType type) { + String result = type.getElementName().getLocalPart(); + String authority = ""; + try { + URI uri = new URI(type.getElementName().getNamespaceURI()); + authority = uri.getAuthority(); + } catch (URISyntaxException e) { + } + for (int i = 0; i < authority.length(); ) { + int j = authority.indexOf(".", i); + if (j == -1) { + j = authority.length(); + } + result = authority.substring(i, j) + "." + result; + if (j < authority.length()) { + j += 1; + } + i = j; + } + return result; + } + + /** + * @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) { + if (sourceType == targetType || (sourceType != null && sourceType.equals(targetType))) { + return source; + } + Map metadata = new HashMap(); + metadata.put("source.operation", targetOperation); + metadata.put("target.operation", sourceOperation); + + DataType eSourceDataType = + new DataTypeImpl("idl:fault", sourceExType.getPhysical(), sourceType); + DataType eTargetDataType = + new DataTypeImpl("idl:fault", targetExType.getPhysical(), targetType); + + return mediator.mediate(source, eSourceDataType, eTargetDataType, metadata); + } + + public void setNext(Invoker next) { + this.next = next; + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/PassByValueInteceptor.java b/tags/java/sca/1.0-RC1b/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/PassByValueInteceptor.java new file mode 100644 index 0000000000..fbd0d0b86a --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/PassByValueInteceptor.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.databinding.wire; + +import java.util.IdentityHashMap; +import java.util.Map; + +import org.apache.tuscany.sca.databinding.DataBinding; +import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint; +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; + +public class PassByValueInteceptor implements Interceptor { + + private DataBindingExtensionPoint dataBindings; + private Operation operation; + + private Invoker nextInvoker; + + public PassByValueInteceptor(DataBindingExtensionPoint dataBindings, Operation operation) { + this.dataBindings = dataBindings; + this.operation = operation; + } + + public Message invoke(Message msg) { + Object obj = msg.getBody(); + msg.setBody(copy((Object[])obj)); + + Message resultMsg = nextInvoker.invoke(msg); + + if (!msg.isFault() && operation.getOutputType() != null) { + String dataBindingId = operation.getOutputType().getDataBinding(); + DataBinding dataBinding = dataBindings.getDataBinding(dataBindingId); + resultMsg.setBody(copy(resultMsg.getBody(), dataBinding)); + } + return resultMsg; + } + + public Object[] copy(Object[] args) { + if (args == null) { + return null; + } + Object[] copiedArgs = new Object[args.length]; + Map map = new IdentityHashMap(); + for (int i = 0; i < args.length; i++) { + if (args[i] == null) { + copiedArgs[i] = null; + } else { + Object copiedArg = map.get(args[i]); + if (copiedArg != null) { + copiedArgs[i] = copiedArg; + } else { + String dataBindingId = operation.getInputType().getLogical().get(i).getDataBinding(); + DataBinding dataBinding = dataBindings.getDataBinding(dataBindingId); + copiedArg = copy(args[i], dataBinding); + map.put(args[i], copiedArg); + copiedArgs[i] = copiedArg; + } + } + } + return copiedArgs; + } + + public Object copy(Object arg, DataBinding argDataBinding) { + if (arg == null) { + return null; + } + Object copiedArg; + if (argDataBinding != null) { + copiedArg = argDataBinding.copy(arg); + } else { + copiedArg = arg; + DataType dataType = dataBindings.introspectType(arg); + if (dataType != null) { + DataBinding binding = dataBindings.getDataBinding(dataType.getDataBinding()); + if (binding != null) { + copiedArg = binding.copy(arg); + } + } + // FIXME: What to do if it's not recognized? + } + return copiedArg; + } + + public Invoker getNext() { + return nextInvoker; + } + + public void setNext(Invoker next) { + this.nextInvoker = next; + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/core-databinding/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/core-databinding/src/test/java/org/apache/tuscany/sca/core/databinding/processor/DataBindingJavaInterfaceProcessorTestCase.java b/tags/java/sca/1.0-RC1b/modules/core-databinding/src/test/java/org/apache/tuscany/sca/core/databinding/processor/DataBindingJavaInterfaceProcessorTestCase.java new file mode 100644 index 0000000000..c5ab064716 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core-databinding/src/test/java/org/apache/tuscany/sca/core/databinding/processor/DataBindingJavaInterfaceProcessorTestCase.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.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; + +/** + * + */ +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 = new OperationImpl("call"); + Operation operation1 = new OperationImpl("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); + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/core-databinding/src/test/java/org/apache/tuscany/sca/core/databinding/transformers/IDLTransformerTestCase.java.fixme b/tags/java/sca/1.0-RC1b/modules/core-databinding/src/test/java/org/apache/tuscany/sca/core/databinding/transformers/IDLTransformerTestCase.java.fixme new file mode 100644 index 0000000000..ecae54188c --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core-databinding/src/test/java/org/apache/tuscany/sca/core/databinding/transformers/IDLTransformerTestCase.java.fixme @@ -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.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 IDLTransformerTestCase 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/tags/java/sca/1.0-RC1b/modules/core-spi/.checkstyle b/tags/java/sca/1.0-RC1b/modules/core-spi/.checkstyle new file mode 100644 index 0000000000..3e57539570 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core-spi/.checkstyle @@ -0,0 +1,24 @@ + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/core-spi/.pmd b/tags/java/sca/1.0-RC1b/modules/core-spi/.pmd new file mode 100644 index 0000000000..4abfdec2b5 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core-spi/.pmd @@ -0,0 +1,20 @@ + + +truefalse \ No newline at end of file diff --git a/tags/java/sca/1.0-RC1b/modules/core-spi/.ruleset b/tags/java/sca/1.0-RC1b/modules/core-spi/.ruleset new file mode 100644 index 0000000000..3886f07f2d --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core-spi/.ruleset @@ -0,0 +1,190 @@ + + + + PMD Plugin preferences rule set + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/core-spi/DISCLAIMER b/tags/java/sca/1.0-RC1b/modules/core-spi/DISCLAIMER new file mode 100644 index 0000000000..d68a410903 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core-spi/DISCLAIMER @@ -0,0 +1,8 @@ +Apache Tuscany is an effort undergoing incubation at The Apache Software +Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is +required of all newly accepted projects until a further review indicates that +the infrastructure, communications, and decision making process have stabilized +in a manner consistent with other successful ASF projects. While incubation +status is not necessarily a reflection of the completeness or stability of the +code, it does indicate that the project has yet to be fully endorsed by the ASF. + diff --git a/tags/java/sca/1.0-RC1b/modules/core-spi/LICENSE b/tags/java/sca/1.0-RC1b/modules/core-spi/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/core-spi/NOTICE b/tags/java/sca/1.0-RC1b/modules/core-spi/NOTICE new file mode 100644 index 0000000000..94481d6cfa --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core-spi/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2007 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/tags/java/sca/1.0-RC1b/modules/core-spi/pom.xml b/tags/java/sca/1.0-RC1b/modules/core-spi/pom.xml new file mode 100644 index 0000000000..f4899f152b --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core-spi/pom.xml @@ -0,0 +1,111 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.0-incubating + ../pom.xml + + tuscany-core-spi + Apache Tuscany SCA Core SPI + + + + org.apache.tuscany.sca + tuscany-sca-api + 1.0-incubating + + + + org.apache.tuscany.sca + tuscany-assembly + 1.0-incubating + + + + org.apache.tuscany.sca + tuscany-policy + 1.0-incubating + + + + org.apache.tuscany.sca + tuscany-interface + 1.0-incubating + compile + + + + org.apache.tuscany.sca + tuscany-contribution + 1.0-incubating + + + + stax + stax-api + 1.0.1 + + + + javax.servlet + servlet-api + 2.5 + provided + + + + org.codehaus.woodstox + wstx-asl + 3.2.1 + runtime + + + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + + + package + package + + jar + + + + + true + true + Apache Tuscany is an effort undergoing incubation at the Apache Software Foundation(ASF) and sponsored by the Apache WS PMC. +
Apache Tuscany SCA Core SPI
+
Apache Tuscany SCA Core SPI
+ ${basedir}/src/main/java +
+
+
+
+ +
diff --git a/tags/java/sca/1.0-RC1b/modules/core-spi/src/doc/Context Model.emx b/tags/java/sca/1.0-RC1b/modules/core-spi/src/doc/Context Model.emx new file mode 100644 index 0000000000..0445ea5a6b --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core-spi/src/doc/Context Model.emx @@ -0,0 +1,673 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + +
+ + + + + + +
+ + + + + + +
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/context/ComponentContextFactory.java b/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/context/ComponentContextFactory.java new file mode 100644 index 0000000000..ed4b57639c --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/context/ContextFactoryExtensionPoint.java b/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/context/ContextFactoryExtensionPoint.java new file mode 100644 index 0000000000..e92a8f2844 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/context/DefaultContextFactoryExtensionPoint.java b/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/context/DefaultContextFactoryExtensionPoint.java new file mode 100644 index 0000000000..50958b7848 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/context/DefaultContextFactoryExtensionPoint.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.context; + +import java.util.HashMap; + +/** + * Default implementation of a model factory extension point. + * + * @version $Rev$ $Date$ + */ +public class DefaultContextFactoryExtensionPoint implements ContextFactoryExtensionPoint { + + private HashMap, Object> factories = new HashMap, Object>(); + + /** + * Add a model factory extension. + * + * @param factory The factory to add + */ + public void addFactory(Object factory) { + Class[] interfaces = factory.getClass().getInterfaces(); + for (int i = 0; i T getFactory(Class factoryInterface) { + Object factory = factories.get(factoryInterface); + return factoryInterface.cast(factory); + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/context/RequestContextFactory.java b/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/context/RequestContextFactory.java new file mode 100644 index 0000000000..546757c766 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/core/DefaultExtensionPointRegistry.java b/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/core/DefaultExtensionPointRegistry.java new file mode 100644 index 0000000000..f5805ba799 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/core/DefaultExtensionPointRegistry.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; + +import java.io.IOException; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Modifier; +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.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.util.ServiceConfigurationUtil; + +/** + * Default implementation of a registry to hold all the Tuscany core extension + * points. As the point of contact for all extension artifacts this registry + * allows loaded extensions to find all other parts of the system and register + * themselves appropriately. + * + * @version $Rev$ $Date$ + */ +public class DefaultExtensionPointRegistry implements ExtensionPointRegistry { + private Map, Object> extensionPoints = new HashMap, Object>(); + + /** + * Add an extension point to the registry. This default implementation + * stores extensions against the interfaces that they implement. + * + * @param extensionPoint The instance of the extension point + */ + public void addExtensionPoint(Object extensionPoint) { + Set interfaces = getAllInterfaces(extensionPoint.getClass()); + for (Class i : interfaces) { + extensionPoints.put(i, extensionPoint); + } + } + + /** + * Get the extension point by the interface that it implements + * + * @param extensionPointType The lookup key (extension point interface) + * @return The instance of the extension point + */ + public T getExtensionPoint(Class extensionPointType) { + Object extensionPoint = extensionPoints.get(extensionPointType); + if (extensionPoint == null) { + + // Dynamically load an extension point class declared under META-INF/services + ClassLoader classLoader = extensionPointType.getClassLoader(); + if (classLoader == null) { + classLoader = Thread.currentThread().getContextClassLoader(); + } + try { + List classNames = ServiceConfigurationUtil.getServiceClassNames(classLoader, extensionPointType.getName()); + if (!classNames.isEmpty()) { + Class extensionPointClass = Class.forName(classNames.iterator().next(), true, classLoader); + + // Construct the extension point + try { + Constructor constructor = extensionPointClass.getConstructor(); + extensionPoint = constructor.newInstance(); + } catch (NoSuchMethodException e) { + try { + Constructor constructor = extensionPointClass.getConstructor(ModelFactoryExtensionPoint.class); + extensionPoint = constructor.newInstance(getExtensionPoint(ModelFactoryExtensionPoint.class)); + } catch (NoSuchMethodException e2) { + try { + Constructor constructor = extensionPointClass.getConstructor(ExtensionPointRegistry.class); + extensionPoint = constructor.newInstance(this); + } catch (NoSuchMethodException e3) { + throw new IllegalArgumentException(e3); + } + } + } + + // Cache the loaded extension point + addExtensionPoint(extensionPoint); + } + } catch (InvocationTargetException e) { + throw new IllegalArgumentException(e); + } catch (IOException e) { + throw new IllegalArgumentException(e); + } catch (ClassNotFoundException e) { + throw new IllegalArgumentException(e); + } catch (InstantiationException e) { + throw new IllegalArgumentException(e); + } catch (IllegalAccessException e) { + throw new IllegalArgumentException(e); + } + } + return extensionPointType.cast(extensionPoint); + } + + /** + * Remove an extension point based on the interface that it implements + * + * @param extensionPoint The extension point to remove + */ + public void removeExtensionPoint(Object extensionPoint) { + Set interfaces = getAllInterfaces(extensionPoint.getClass()); + for (Class i : interfaces) { + extensionPoints.remove(i); + } + } + + /** + * Returns the set of interfaces implemented by the given class and its + * ancestors or a blank set if none + */ + private static Set getAllInterfaces(Class clazz) { + Set implemented = new HashSet(); + getAllInterfaces(clazz, implemented); + return implemented; + } + + private static void getAllInterfaces(Class clazz, Set implemented) { + Class[] interfaces = clazz.getInterfaces(); + for (Class interfaze : interfaces) { + String name = interfaze.getName(); + if (name.startsWith("java.") || name.startsWith("javax.")) { + continue; + } + if (Modifier.isPublic(interfaze.getModifiers())) { + implemented.add(interfaze); + } + } + Class superClass = clazz.getSuperclass(); + // Object has no superclass so check for null + if (superClass != null && !superClass.equals(Object.class)) { + getAllInterfaces(superClass, implemented); + } + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/core/ExtensionPointRegistry.java b/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/core/ExtensionPointRegistry.java new file mode 100644 index 0000000000..9609487080 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/core/ExtensionPointRegistry.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.core; + + +/** + * The registry for the Tuscany core extension points. As the point of contact + * for all extension artifacts this registry allows loaded extensions to find + * all other parts of the system and register themselves appropriately. + * + * @version $Rev$ $Date$ + */ +public interface ExtensionPointRegistry { + + /** + * Add an extension point to the registry + * @param extensionPoint The instance of the extension point + */ + void addExtensionPoint(Object extensionPoint); + + /** + * Get the extension point by the interface + * @param extensionPointType The lookup key (extension point interface) + * @return The instance of the extension point + */ + T getExtensionPoint(Class extensionPointType); + + /** + * Remove an extension point + * @param extensionPoint The extension point to remove + */ + void removeExtensionPoint(Object extensionPoint); +} diff --git a/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/core/ModuleActivator.java b/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/core/ModuleActivator.java new file mode 100644 index 0000000000..78cb4d14d6 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/core/ModuleActivator.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.core; + + +/** + * ModuleActivator represents a module that plugs into the Tuscany system. Each + * module should provide an implementation of this interface and register the + * ModuleActivator implementation class by defining a file named + * + * "META-INF/services/org.apache.tuscany.spi.bootstrp.ModuleActivator" + * + * The content of the file is the class name of the ModuleActivator implementation. + * The implementation class must have a no-arg constructor. The same instance + * will be used to invoke all the methods during different phases of the module + * activation. Note that the start and stop methods defined by this interface + * take a reference to the Tuscany SCA runtime ExtensionPointRegistry. This + * gives the ModuleActivator the oppotunity to add extension points to the + * registry as it is requested to start up and remove them when it is requested + * to shut down. + * + * @version $Rev$ $Date$ + */ +public interface ModuleActivator { + + /** + * This method is invoked when the module is started by the Tuscany system. + * It can be used by this module to registr extensions against extension + * points. + * + * @param registry The extension point registry + */ + void start(ExtensionPointRegistry registry); + + /** + * This method is invoked when the module is stopped by the Tuscany system. + * It can be used by this module to unregister extensions against the + * extension points. + * + * @param registry The extension point registry + */ + void stop(ExtensionPointRegistry registry); +} diff --git a/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/event/Event.java b/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/event/Event.java new file mode 100644 index 0000000000..6a0c44a404 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/event/EventFilter.java b/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/event/EventFilter.java new file mode 100644 index 0000000000..c116be921c --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/event/EventPublisher.java b/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/event/EventPublisher.java new file mode 100644 index 0000000000..b0debc36c4 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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 regisitered listeners + * @param object The event to publich + */ + 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/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/event/RuntimeEventListener.java b/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/event/RuntimeEventListener.java new file mode 100644 index 0000000000..b34dceee62 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/event/TrueFilter.java b/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/event/TrueFilter.java new file mode 100644 index 0000000000..ca0f4889a5 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/Interceptor.java b/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/Interceptor.java new file mode 100644 index 0000000000..a5f221fc11 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/InvocationChain.java b/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/InvocationChain.java new file mode 100644 index 0000000000..dcb9dba73a --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/InvocationChain.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.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 + * + * @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(); + + /** + * Returns the last invoker in the chain. + * + * @return The last invoker in the chain + */ + Invoker getTailInvoker(); + + /** + * Adds an interceptor at the given position in the interceptor stack + * + * @param index The position in the interceptor stack to add the interceptor + * @param interceptor The interceptor to add + */ + void addInterceptor(int index, Interceptor interceptor); + +} diff --git a/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/Invoker.java b/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/Invoker.java new file mode 100644 index 0000000000..2748bbed9a --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/Message.java b/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/Message.java new file mode 100644 index 0000000000..82586e1b2e --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/Message.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.invocation; + +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); + +} diff --git a/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/MessageFactory.java b/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/MessageFactory.java new file mode 100644 index 0000000000..c2a9c488b8 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/management/ManagementService.java b/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/management/ManagementService.java new file mode 100644 index 0000000000..3626e16425 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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 implementaion + * 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/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/BindingProviderFactory.java b/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/BindingProviderFactory.java new file mode 100644 index 0000000000..0f6a932c51 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/DefaultProviderFactoryExtensionPoint.java b/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/DefaultProviderFactoryExtensionPoint.java new file mode 100644 index 0000000000..2452e3cf1a --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/DefaultProviderFactoryExtensionPoint.java @@ -0,0 +1,263 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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.io.IOException; +import java.lang.reflect.Constructor; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.Implementation; +import org.apache.tuscany.sca.contribution.util.ServiceConfigurationUtil; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +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 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) { + providerFactories.put(providerFactory.getModelType(), providerFactory); + } + + /** + * Remove a provider factory. + * + * @param providerFactory The provider factory + */ + public void removeProviderFactory(ProviderFactory 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); + } + + /** + * Load provider factories declared under META-INF/services. + * @param registry + */ + private void loadProviderFactories() { + if (loaded) + return; + + loadProviderFactories(BindingProviderFactory.class); + loadProviderFactories(ImplementationProviderFactory.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 + List factoryDeclarations; + try { + ClassLoader classLoader = factoryClass.getClassLoader(); + factoryDeclarations = ServiceConfigurationUtil.getServiceClassNames(classLoader, factoryClass.getName()); + } catch (IOException e) { + throw new IllegalStateException(e); + } + + // Get the target extension point + ProviderFactoryExtensionPoint factoryExtensionPoint = registry.getExtensionPoint(ProviderFactoryExtensionPoint.class); + List factories = new ArrayList(); + + for (String factoryDeclaration: factoryDeclarations) { + Map attributes = ServiceConfigurationUtil.parseServiceDeclaration(factoryDeclaration); + String className = attributes.get("class"); + + // 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, className); + 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, className); + 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 String className; + private BindingProviderFactory factory; + private Class modelType; + + private LazyBindingProviderFactory(ExtensionPointRegistry registry, String modelTypeName, String className) { + this.registry = registry; + this.modelTypeName = modelTypeName; + this.className = className; + } + + @SuppressWarnings("unchecked") + private BindingProviderFactory getFactory() { + if (factory == null) { + try { + ClassLoader classLoader = BindingProviderFactory.class.getClassLoader(); + Class factoryClass = (Class)Class.forName(className, true, classLoader); + 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 { + ClassLoader classLoader = BindingProviderFactory.class.getClassLoader(); + modelType = Class.forName(modelTypeName, true, classLoader); + } 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 String className; + private ImplementationProviderFactory factory; + private Class modelType; + + private LazyImplementationProviderFactory(ExtensionPointRegistry registry, String modelTypeName, String className) { + this.registry = registry; + this.modelTypeName = modelTypeName; + this.className = className; + } + + @SuppressWarnings("unchecked") + private ImplementationProviderFactory getFactory() { + if (factory == null) { + try { + ClassLoader classLoader = ImplementationProviderFactory.class.getClassLoader(); + Class factoryClass = (Class)Class.forName(className, true, classLoader); + 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 { + ClassLoader classLoader = ImplementationProviderFactory.class.getClassLoader(); + modelType = Class.forName(modelTypeName, true, classLoader); + } catch (Exception e) { + throw new IllegalStateException(e); + } + } + return modelType; + } + + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ImplementationProvider.java b/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ImplementationProvider.java new file mode 100644 index 0000000000..015c673d66 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ImplementationProviderFactory.java b/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ImplementationProviderFactory.java new file mode 100644 index 0000000000..6a37d1e951 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ProviderFactory.java b/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ProviderFactory.java new file mode 100644 index 0000000000..2102806881 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ProviderFactoryExtensionPoint.java b/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ProviderFactoryExtensionPoint.java new file mode 100644 index 0000000000..5e781dd5b3 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ProviderFactoryExtensionPoint.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.provider; + + +/** + * 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); + +} diff --git a/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ReferenceBindingProvider.java b/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ReferenceBindingProvider.java new file mode 100644 index 0000000000..b3ab1d8b87 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ServiceBindingProvider.java b/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ServiceBindingProvider.java new file mode 100644 index 0000000000..e15234a549 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/DefaultWireProcessorExtensionPoint.java b/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/DefaultWireProcessorExtensionPoint.java new file mode 100644 index 0000000000..851afee3c1 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/EndpointReference.java b/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/EndpointReference.java new file mode 100644 index 0000000000..b6fafa5fb6 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/ReferenceParameters.java b/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/ReferenceParameters.java new file mode 100644 index 0000000000..0e19538aff --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponent.java b/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponent.java new file mode 100644 index 0000000000..1f1c6ba31b --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponent.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.runtime; + +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.provider.ImplementationProvider; + +/** + * 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 configuation 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 the state to set + */ + void setStarted(boolean started); +} diff --git a/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponentContext.java b/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponentContext.java new file mode 100644 index 0000000000..2f8dd70bc5 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponentContext.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.runtime; + +import java.io.IOException; +import java.io.Reader; +import java.io.Writer; + +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 ComponentContext { + /** + * 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 callable reference 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 callable reference 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/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponentReference.java b/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponentReference.java new file mode 100644 index 0000000000..13ebe0e51d --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponentReference.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.runtime; + +import java.util.List; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.ComponentReference; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Invoker; +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); + + + /** + * 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/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponentService.java b/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponentService.java new file mode 100644 index 0000000000..831cde433e --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponentService.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.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.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 assoicated 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); + + /** + * 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 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); +} diff --git a/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeWire.java b/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeWire.java new file mode 100644 index 0000000000..da37385af1 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeWire.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.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); + + /** + * 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/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeWireProcessor.java b/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeWireProcessor.java new file mode 100644 index 0000000000..fbb7aae467 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeWireProcessorExtensionPoint.java b/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeWireProcessorExtensionPoint.java new file mode 100644 index 0000000000..4b2c71b397 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/DuplicateRecordException.java b/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/DuplicateRecordException.java new file mode 100644 index 0000000000..3cf82982dc --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/DuplicateRecordException.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.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; + + public DuplicateRecordException() { + super(); + } + + public DuplicateRecordException(String message, Throwable cause) { + super(message, cause); + } + + public DuplicateRecordException(String message) { + super(message); + } + + public DuplicateRecordException(Throwable cause) { + super(cause); + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/RecoveryListener.java b/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/RecoveryListener.java new file mode 100644 index 0000000000..9d965a3369 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/Store.java b/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/Store.java new file mode 100644 index 0000000000..b15cde066a --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/StoreException.java b/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/StoreException.java new file mode 100644 index 0000000000..647eba33aa --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/StoreException.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; + + +/** + * Represents a generic exception thrown by a Store + * + * @version $Rev$ $Date$ + */ +public class StoreException extends Exception { + private static final long serialVersionUID = -319152147419962709L; + + public StoreException() { + super(); + } + + public StoreException(String message, Throwable cause) { + super(message, cause); + } + + public StoreException(String message) { + super(message); + } + + public StoreException(Throwable cause) { + super(cause); + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/StoreExpirationEvent.java b/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/StoreExpirationEvent.java new file mode 100644 index 0000000000..5c1a3ca79d --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/StoreMonitor.java b/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/StoreMonitor.java new file mode 100644 index 0000000000..66bbae684d --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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 monintor 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/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/StoreReadException.java b/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/StoreReadException.java new file mode 100644 index 0000000000..3a563b9fb5 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/StoreReadException.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.store; + +/** + * Thrown when an error occurs reading from persistent storage + * + * @version $Rev$ $Date$ + */ +public class StoreReadException extends StoreException { + private static final long serialVersionUID = -8624542082121467271L; + + public StoreReadException() { + super(); + } + + public StoreReadException(String message, Throwable cause) { + super(message, cause); + } + + public StoreReadException(String message) { + super(message); + } + + public StoreReadException(Throwable cause) { + super(cause); + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/StoreWriteException.java b/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/StoreWriteException.java new file mode 100644 index 0000000000..ad55ce386b --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/StoreWriteException.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.store; + +/** + * Thrown when an error occurs writing to persistent storage + * + * @version $Rev$ $Date$ + */ +public class StoreWriteException extends StoreException { + private static final long serialVersionUID = 5539070473942048555L; + + public StoreWriteException() { + super(); + } + + public StoreWriteException(String message, Throwable cause) { + super(message, cause); + } + + public StoreWriteException(String message) { + super(message); + } + + public StoreWriteException(Throwable cause) { + super(cause); + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/work/NotificationListener.java b/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/work/NotificationListener.java new file mode 100644 index 0000000000..5701a04ed1 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/work/NotificationListener.java @@ -0,0 +1,66 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.work; + +/** + * A callback inyterface that can be optionally used for registering + * interest in status of asynchronously scheduled unit of work. + * + */ +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 succesfully completed. + */ + void workCompleted(T work); + + /** + * Callback when the unit of work is started. + * + * @param work Unit of work that was started. + */ + void workStarted(T work); + + /** + * Callback when the unit of work is rejected. + * + * @param work Unit of work that was rejected. + */ + void workRejected(T work); + + /** + * Callnack when the unit of work fails to complete. + * + * @param work Unit of work that failed to complete. + * @param error Error that caused the unit of work to fail. + */ + void workFailed(T work, Throwable error); + + + +} diff --git a/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/work/WorkScheduler.java b/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/work/WorkScheduler.java new file mode 100644 index 0000000000..f4e97f71ec --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/work/WorkScheduler.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.work; + +/** + * Defines the contract for scheduling asychronous 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 notfied with the + * error details. + *

+ * + */ +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/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/work/WorkSchedulerException.java b/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/work/WorkSchedulerException.java new file mode 100644 index 0000000000..d1f4496337 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/java/org/apache/tuscany/sca/work/WorkSchedulerException.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.work; + + +/** + * Exception thrown by the work scheduler in case of unexpected exceptions. + * + * @version $Rev$ $Date$ + * + */ +public class WorkSchedulerException extends RuntimeException { + private static final long serialVersionUID = 1L; + + public WorkSchedulerException() { + super(); + } + + public WorkSchedulerException(String message, Throwable cause) { + super(message, cause); + } + + public WorkSchedulerException(String message) { + super(message); + } + + public WorkSchedulerException(Throwable cause) { + super(cause); + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.ProviderFactoryExtensionPoint b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.RuntimeWireProcessorExtensionPoint b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/resources/META-INF/services/org.apache.tuscany.sca.work.WorkScheduler b/tags/java/sca/1.0-RC1b/modules/core-spi/src/main/resources/META-INF/services/org.apache.tuscany.sca.work.WorkScheduler new file mode 100644 index 0000000000..56e99be0f2 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core-spi/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.Jsr237WorkScheduler diff --git a/tags/java/sca/1.0-RC1b/modules/core-spring/DISCLAIMER b/tags/java/sca/1.0-RC1b/modules/core-spring/DISCLAIMER new file mode 100644 index 0000000000..d68a410903 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core-spring/DISCLAIMER @@ -0,0 +1,8 @@ +Apache Tuscany is an effort undergoing incubation at The Apache Software +Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is +required of all newly accepted projects until a further review indicates that +the infrastructure, communications, and decision making process have stabilized +in a manner consistent with other successful ASF projects. While incubation +status is not necessarily a reflection of the completeness or stability of the +code, it does indicate that the project has yet to be fully endorsed by the ASF. + diff --git a/tags/java/sca/1.0-RC1b/modules/core-spring/LICENSE b/tags/java/sca/1.0-RC1b/modules/core-spring/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core-spring/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/tags/java/sca/1.0-RC1b/modules/core-spring/NOTICE b/tags/java/sca/1.0-RC1b/modules/core-spring/NOTICE new file mode 100644 index 0000000000..94481d6cfa --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core-spring/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2007 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/tags/java/sca/1.0-RC1b/modules/core-spring/pom.xml b/tags/java/sca/1.0-RC1b/modules/core-spring/pom.xml new file mode 100644 index 0000000000..ad7b19768c --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core-spring/pom.xml @@ -0,0 +1,107 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.0-incubating + ../pom.xml + + tuscany-core-spring + Apache Tuscany SCA Spring-based Core Runtime + + + + + org.apache.tuscany.sca + tuscany-assembly + 1.0-incubating + + + + org.apache.tuscany.sca + tuscany-interface-java + 1.0-incubating + + + + org.apache.tuscany.sca + tuscany-implementation-java + 1.0-incubating + + + + org.springframework + spring-core + 2.0.6 + + + + org.springframework + spring-beans + 2.0.6 + + + + org.springframework + spring-context + 2.0.6 + + + + org.apache.tuscany.sca + tuscany-sca-api + 1.0-incubating + + + + org.apache.tuscany.sca + tuscany-assembly-xml + 1.0-incubating + + + + org.apache.tuscany.sca + tuscany-interface-java-xml + 1.0-incubating + + + + org.apache.tuscany.sca + tuscany-implementation-java-xml + 1.0-incubating + + + + org.apache.tuscany.sca + tuscany-contribution-impl + 1.0-incubating + + + + org.apache.tuscany.sca + tuscany-binding-sca + 1.0-incubating + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/assembly/impl/BeanAssemblyFactory.java b/tags/java/sca/1.0-RC1b/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/assembly/impl/BeanAssemblyFactory.java new file mode 100644 index 0000000000..ffe6e530dd --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/assembly/impl/BeanAssemblyFactory.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.core.spring.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.ConstrainingType; +import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory; +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.interfacedef.Operation; +import org.springframework.beans.factory.support.BeanDefinitionRegistry; + +/** + * An alternate implementation of the SCA assembly model factory that creates SCA + * assembly model objects backed by Spring bean definitions. + * + * @version $Rev$ $Date$ + */ +public class BeanAssemblyFactory implements AssemblyFactory { + + private AssemblyFactory defaultFactory; + private BeanDefinitionRegistry beanRegistry; + + public BeanAssemblyFactory(AssemblyFactory defaultFactory, BeanDefinitionRegistry beanRegistry) { + this.defaultFactory = defaultFactory; + this.beanRegistry = beanRegistry; + } + + public BeanAssemblyFactory(BeanDefinitionRegistry beanRegistry) { + this(new DefaultAssemblyFactory(), beanRegistry); + } + + public AbstractProperty createAbstractProperty() { + return defaultFactory.createAbstractProperty(); + } + + public AbstractReference createAbstractReference() { + return defaultFactory.createAbstractReference(); + } + + public AbstractService createAbstractService() { + return defaultFactory.createAbstractService(); + } + + public Callback createCallback() { + return defaultFactory.createCallback(); + } + + public Component createComponent() { + return new BeanComponentImpl(beanRegistry); + } + + public ComponentProperty createComponentProperty() { + return defaultFactory.createComponentProperty(); + } + + public ComponentReference createComponentReference() { + return defaultFactory.createComponentReference(); + } + + public ComponentService createComponentService() { + return defaultFactory.createComponentService(); + } + + public ComponentType createComponentType() { + return defaultFactory.createComponentType(); + } + + public Composite createComposite() { + return defaultFactory.createComposite(); + } + + public CompositeReference createCompositeReference() { + return defaultFactory.createCompositeReference(); + } + + public CompositeService createCompositeService() { + return defaultFactory.createCompositeService(); + } + + public ConstrainingType createConstrainingType() { + return defaultFactory.createConstrainingType(); + } + + public Property createProperty() { + return defaultFactory.createProperty(); + } + + public Reference createReference() { + return defaultFactory.createReference(); + } + + public Service createService() { + return defaultFactory.createService(); + } + + public Wire createWire() { + return defaultFactory.createWire(); + } + + public Operation createOperation() { + return defaultFactory.createOperation(); + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/assembly/impl/BeanComponentImpl.java b/tags/java/sca/1.0-RC1b/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/assembly/impl/BeanComponentImpl.java new file mode 100644 index 0000000000..32918b171d --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/assembly/impl/BeanComponentImpl.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.core.spring.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.ConstrainingType; +import org.apache.tuscany.sca.assembly.Implementation; +import org.apache.tuscany.sca.policy.Intent; +import org.apache.tuscany.sca.policy.IntentAttachPointType; +import org.apache.tuscany.sca.policy.PolicySet; +import org.springframework.beans.factory.support.BeanDefinitionRegistry; +import org.springframework.beans.factory.support.ChildBeanDefinition; + +/** + * An implementation of the SCA assembly Component interface backed by a Spring + * Bean definition. + * + * @version $Rev$ $Date$ + */ +public class BeanComponentImpl extends ChildBeanDefinition implements Component, Cloneable { + public IntentAttachPointType getType() { + // TODO Auto-generated method stub + return null; + } + + public void setType(IntentAttachPointType type) { + // TODO Auto-generated method stub + + } + + private static final long serialVersionUID = 1L; + + private ConstrainingType constrainingType; + private Implementation implementation; + private String name; + private String uri; + private List services = new ArrayList(); + private List requiredIntents = new ArrayList(); + private List policySets = new ArrayList(); + private List extensions = new ArrayList(); + private boolean unresolved = false; + private BeanDefinitionRegistry beanRegistry; + + protected BeanComponentImpl(BeanDefinitionRegistry beanRegistry) { + super((String)""); + this.beanRegistry = beanRegistry; + } + + @Override + public Object clone() throws CloneNotSupportedException { + BeanComponentImpl clone = (BeanComponentImpl)super.clone(); + + clone.getProperties().clear(); + for (ComponentProperty property : getProperties()) { + clone.getProperties().add((ComponentProperty)property.clone()); + } + clone.getReferences().clear(); + for (ComponentReference reference : getReferences()) { + clone.getReferences().add((ComponentReference)reference.clone()); + } + clone.getServices().clear(); + for (ComponentService service : getServices()) { + clone.getServices().add((ComponentService)service.clone()); + } + return clone; + } + + @Override + public String getParentName() { + //TODO find a better name for bean definitions representing component types + return String.valueOf(System.identityHashCode(implementation)); + } + + public ConstrainingType getConstrainingType() { + return constrainingType; + } + + public Implementation getImplementation() { + return implementation; + } + + public String getURI() { + return uri; + } + + public void setURI(String uri) { + this.uri = uri; + + // Register this bean definition in the bean registry + this.beanRegistry.registerBeanDefinition(uri, this); + } + + public String getName() { + return name; + } + + //TODO use a better list implementation + private List properties = new ArrayList() { + private static final long serialVersionUID = 1L; + + // Add a property + @Override + public boolean add(ComponentProperty property) { + + // Add corresponding bean property value + getPropertyValues().addPropertyValue(property.getName(), property.getValue()); + + return super.add(property); + } + }; + + public List getProperties() { + return properties; + } + + //TODO use a better list implementation + private List references = new ArrayList() { + private static final long serialVersionUID = 1L; + + // Add a reference + @Override + public boolean add(ComponentReference reference) { + + // Add corresponding bean property value + if (!reference.getName().startsWith("$self$.")) { + BeanReferenceImpl beanReference = new BeanReferenceImpl(reference); + getPropertyValues().addPropertyValue(reference.getName(), beanReference); + } + return super.add(reference); + } + }; + + 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 super.getAutowireMode() == AUTOWIRE_BY_TYPE; + } + + public Boolean getAutowire() { + int autowire = super.getAutowireMode(); + if (autowire == AUTOWIRE_BY_TYPE) { + return Boolean.TRUE; + } else if (autowire == AUTOWIRE_NO) { + return Boolean.FALSE; + } else { + return null; + } + } + + public void setAutowire(Boolean autowire) { + super.setAutowireMode(autowire ? AUTOWIRE_BY_TYPE : AUTOWIRE_NO); + } + + public List getExtensions() { + return extensions; + } + + public boolean isUnresolved() { + return unresolved; + } + + public void setUnresolved(boolean undefined) { + this.unresolved = undefined; + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/assembly/impl/BeanReferenceImpl.java b/tags/java/sca/1.0-RC1b/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/assembly/impl/BeanReferenceImpl.java new file mode 100644 index 0000000000..be91c07d50 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/assembly/impl/BeanReferenceImpl.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.spring.assembly.impl; + +import org.apache.tuscany.sca.assembly.Reference; +import org.apache.tuscany.sca.assembly.SCABinding; +import org.springframework.beans.factory.config.RuntimeBeanReference; + +/** + * An implementation of RuntimeBeanReference wrappering an SCA assembly + * Reference + * + * @version $Rev$ $Date$ + */ +public class BeanReferenceImpl extends RuntimeBeanReference { + private Reference reference; + + protected BeanReferenceImpl(Reference reference) { + super("temp"); + this.reference = reference; + } + + @Override + public String getBeanName() { + SCABinding binding = reference.getBinding(SCABinding.class); + String name = binding.getURI(); + int s = name.lastIndexOf('/'); + if (s != -1) { + name = name.substring(0, s); + } + return name; + } + + @Override + public boolean equals(Object other) { + if (this != other) { + if (other instanceof RuntimeBeanReference) { + RuntimeBeanReference br = (RuntimeBeanReference)other; + return (getBeanName().equals(br.getBeanName()) && this.isToParent() == br.isToParent()); + } else + return false; + } else + return true; + } + + @Override + public int hashCode() { + return getBeanName().hashCode() * 29 + (this.isToParent() ? 1 : 0); + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/context/ModelResolverImpl.java b/tags/java/sca/1.0-RC1b/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/context/ModelResolverImpl.java new file mode 100644 index 0000000000..ba2d5045f2 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/context/ModelResolverImpl.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.core.spring.context; + +import java.lang.ref.WeakReference; +import java.util.HashMap; +import java.util.Map; + +import org.apache.tuscany.sca.contribution.resolver.ClassReference; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; + + +/** + * A default implementation of an artifact resolver, based on a map. + * + * @version $Rev$ $Date$ + */ +public class ModelResolverImpl implements ModelResolver { + private static final long serialVersionUID = -7826976465762296634L; + + private Map map = new HashMap(); + + private WeakReference classLoader; + + public ModelResolverImpl(ClassLoader classLoader) { + this.classLoader = new WeakReference(classLoader); + } + + 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; + try { + clazz = Class.forName(classReference.getClassName(), true, classLoader.get()); + } catch (ClassNotFoundException e) { + + // Return the unresolved object + return unresolved; + } + + // Store a new ClassReference wrappering the loaded class + resolved = new ClassReference(clazz); + map.put(resolved, resolved); + + // Return the resolved ClassReference + 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/tags/java/sca/1.0-RC1b/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/context/SCADomainContext.java b/tags/java/sca/1.0-RC1b/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/context/SCADomainContext.java new file mode 100644 index 0000000000..58f3d5e8e4 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/context/SCADomainContext.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.core.spring.context; + +import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLOutputFactory; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory; +import org.apache.tuscany.sca.assembly.SCABindingFactory; +import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException; +import org.apache.tuscany.sca.assembly.builder.CompositeBuilderMonitor; +import org.apache.tuscany.sca.assembly.builder.Problem; +import org.apache.tuscany.sca.assembly.builder.impl.CompositeBuilderImpl; +import org.apache.tuscany.sca.assembly.xml.ComponentTypeProcessor; +import org.apache.tuscany.sca.assembly.xml.CompositeProcessor; +import org.apache.tuscany.sca.assembly.xml.ConstrainingTypeProcessor; +import org.apache.tuscany.sca.contribution.ContributionFactory; +import org.apache.tuscany.sca.contribution.DefaultModelFactoryExtensionPoint; +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.service.ContributionException; +import org.apache.tuscany.sca.core.spring.assembly.impl.BeanAssemblyFactory; +import org.apache.tuscany.sca.core.spring.implementation.java.impl.BeanJavaImplementationFactory; +import org.apache.tuscany.sca.implementation.java.JavaImplementationFactory; +import org.apache.tuscany.sca.implementation.java.introspect.JavaClassVisitor; +import org.apache.tuscany.sca.implementation.java.introspect.impl.AllowsPassByReferenceProcessor; +import org.apache.tuscany.sca.implementation.java.introspect.impl.BaseJavaClassVisitor; +import org.apache.tuscany.sca.implementation.java.introspect.impl.ComponentNameProcessor; +import org.apache.tuscany.sca.implementation.java.introspect.impl.ConstructorProcessor; +import org.apache.tuscany.sca.implementation.java.introspect.impl.ContextProcessor; +import org.apache.tuscany.sca.implementation.java.introspect.impl.ConversationProcessor; +import org.apache.tuscany.sca.implementation.java.introspect.impl.DestroyProcessor; +import org.apache.tuscany.sca.implementation.java.introspect.impl.EagerInitProcessor; +import org.apache.tuscany.sca.implementation.java.introspect.impl.HeuristicPojoProcessor; +import org.apache.tuscany.sca.implementation.java.introspect.impl.InitProcessor; +import org.apache.tuscany.sca.implementation.java.introspect.impl.PolicyProcessor; +import org.apache.tuscany.sca.implementation.java.introspect.impl.PropertyProcessor; +import org.apache.tuscany.sca.implementation.java.introspect.impl.ReferenceProcessor; +import org.apache.tuscany.sca.implementation.java.introspect.impl.ResourceProcessor; +import org.apache.tuscany.sca.implementation.java.introspect.impl.ScopeProcessor; +import org.apache.tuscany.sca.implementation.java.introspect.impl.ServiceProcessor; +import org.apache.tuscany.sca.implementation.java.xml.JavaImplementationProcessor; +import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; +import org.apache.tuscany.sca.interfacedef.impl.InterfaceContractMapperImpl; +import org.apache.tuscany.sca.interfacedef.java.DefaultJavaInterfaceFactory; +import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory; +import org.apache.tuscany.sca.interfacedef.java.xml.JavaInterfaceProcessor; +import org.apache.tuscany.sca.policy.DefaultPolicyFactory; +import org.apache.tuscany.sca.policy.PolicyFactory; +import org.springframework.beans.factory.support.DefaultListableBeanFactory; + +/** + * A mini test runtime that uses the SCA assembly model variant implementation + * backed by Spring bean definitions. + * + * @version $Rev$ $Date$ + */ +public class SCADomainContext { + + private DefaultListableBeanFactory beanFactory; + + public SCADomainContext(String... compositeFiles) { + + // Create Spring bean factory + beanFactory = new DefaultListableBeanFactory(); + + // Create SCA assembly and SCA Java factories + ModelFactoryExtensionPoint modelFactories = new DefaultModelFactoryExtensionPoint(); + AssemblyFactory assemblyFactory = new BeanAssemblyFactory(new DefaultAssemblyFactory(), beanFactory); + modelFactories.addFactory(assemblyFactory); + SCABindingFactory scaBindingFactory = modelFactories.getFactory(SCABindingFactory.class); + PolicyFactory policyFactory = new DefaultPolicyFactory(); + modelFactories.addFactory(policyFactory); + ContributionFactory contributionFactory = modelFactories.getFactory(ContributionFactory.class); + InterfaceContractMapper interfaceContractMapper = new InterfaceContractMapperImpl(); + JavaInterfaceFactory javaFactory = new DefaultJavaInterfaceFactory(); + modelFactories.addFactory(javaFactory); + JavaImplementationFactory javaImplementationFactory = new BeanJavaImplementationFactory(beanFactory); + modelFactories.addFactory(javaImplementationFactory); + + BaseJavaClassVisitor[] extensions = new BaseJavaClassVisitor[] { + new ConstructorProcessor(assemblyFactory), + new AllowsPassByReferenceProcessor(assemblyFactory), + new ComponentNameProcessor(assemblyFactory), + new ContextProcessor(assemblyFactory), + new ConversationProcessor(assemblyFactory), + new DestroyProcessor(assemblyFactory), + new EagerInitProcessor(assemblyFactory), + new InitProcessor(assemblyFactory), + new PropertyProcessor(assemblyFactory), + new ReferenceProcessor(assemblyFactory, javaFactory), + new ResourceProcessor(assemblyFactory), + new ScopeProcessor(assemblyFactory), + new ServiceProcessor(assemblyFactory, javaFactory), + new HeuristicPojoProcessor(assemblyFactory, javaFactory), + new PolicyProcessor(assemblyFactory, policyFactory) + }; + for (JavaClassVisitor e : extensions) { + javaImplementationFactory.addClassVisitor(e); + } + + // Populate ArtifactProcessor registry + DefaultStAXArtifactProcessorExtensionPoint staxProcessors = new DefaultStAXArtifactProcessorExtensionPoint(modelFactories); + ExtensibleStAXArtifactProcessor staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, XMLInputFactory.newInstance(), XMLOutputFactory.newInstance()); + CompositeProcessor compositeProcessor = new CompositeProcessor(contributionFactory, assemblyFactory, policyFactory, + interfaceContractMapper, staxProcessor); + staxProcessors.addArtifactProcessor(compositeProcessor); + staxProcessors.addArtifactProcessor(new ComponentTypeProcessor(assemblyFactory, policyFactory, staxProcessor)); + staxProcessors.addArtifactProcessor(new ConstrainingTypeProcessor(assemblyFactory, policyFactory, staxProcessor)); + staxProcessors.addArtifactProcessor(new JavaInterfaceProcessor(modelFactories)); + staxProcessors.addArtifactProcessor(new JavaImplementationProcessor(modelFactories)); + + // Create a resolver + //FIXME The classloader should be passed in + ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); + ModelResolverImpl resolver = new ModelResolverImpl(classLoader); + + try { + + // Read the composite files + List composites = new ArrayList(); + for (String compositeFile: compositeFiles) { + InputStream is = classLoader.getResourceAsStream(compositeFile); + Composite composite = staxProcessor.read(is, Composite.class); + resolver.addModel(composite); + composites.add(composite); + } + + for (Composite composite: composites) { + + // Resolve the composite + compositeProcessor.resolve(composite, resolver); + } + + // Wire the top level component's composite + buildComposite(composites.get(0), assemblyFactory, scaBindingFactory, interfaceContractMapper); + + } catch (ContributionException e) { + throw new RuntimeException(e); + } catch (CompositeBuilderException e) { + throw new RuntimeException(e); + } + } + + private void buildComposite(Composite composite, AssemblyFactory assemblyFactory, + SCABindingFactory scaBindingFactory, InterfaceContractMapper interfaceContractMapper) throws CompositeBuilderException { + + CompositeBuilderMonitor monitor = new CompositeBuilderMonitor() { + + public void problem(Problem problem) { + // Uncommenting the following two lines can be useful to detect + // and troubleshoot SCA assembly XML composite configuration + // problems. + + System.out.println("Composite assembly problem: " + problem.getMessage()); + } + }; + + // Configure and wire the composite + CompositeBuilderImpl compositeUtil = new CompositeBuilderImpl(assemblyFactory, scaBindingFactory, interfaceContractMapper, null, monitor); + compositeUtil.build(composite); + + } + + public B getService(Class businessInterface, String serviceName) { + Object bean = beanFactory.getBean(serviceName); + return businessInterface.cast(bean); + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/implementation/java/impl/BeanBaseJavaImplementationImpl.java b/tags/java/sca/1.0-RC1b/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/implementation/java/impl/BeanBaseJavaImplementationImpl.java new file mode 100644 index 0000000000..fef6fa5863 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/implementation/java/impl/BeanBaseJavaImplementationImpl.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.core.spring.implementation.java.impl; + +import java.util.ArrayList; +import java.util.List; + +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.implementation.java.BaseJavaImplementation; +import org.springframework.beans.factory.support.BeanDefinitionRegistry; +import org.springframework.beans.factory.support.RootBeanDefinition; + +/** + * An implementation of the SCA assembly JavaImplementation interface backed by a Spring + * Bean definition. + * + * @version $Rev$ $Date$ + */ +public class BeanBaseJavaImplementationImpl extends RootBeanDefinition implements BaseJavaImplementation, Cloneable { + private static final long serialVersionUID = 1L; + + private List services = new ArrayList(); + private ConstrainingType constrainingType; + private List extensions = new ArrayList(); + private boolean unresolved; + private BeanDefinitionRegistry beanRegistry; + private String uri; + + protected BeanBaseJavaImplementationImpl(BeanDefinitionRegistry beanRegistry) { + this.beanRegistry = beanRegistry; + + // Register this bean definition in the bean registry + //TODO find a better name for bean definitions representing component types + String name = String.valueOf(System.identityHashCode(this)); + this.beanRegistry.registerBeanDefinition(name, this); + } + + @Override + public Object clone() throws CloneNotSupportedException { + BeanBaseJavaImplementationImpl clone = (BeanBaseJavaImplementationImpl)super.clone(); + + clone.getServices().clear(); + for (Service service: getServices()) { + clone.getServices().add((Service)service.clone()); + } + clone.getReferences().clear(); + for (Reference reference: getReferences()) { + clone.getReferences().add((Reference)reference.clone()); + } + clone.getProperties().clear(); + for (Property property: getProperties()) { + clone.getProperties().add((Property)property.clone()); + } + return clone; + } + + public Class getJavaClass() { + return super.getBeanClass(); + } + + public String getName() { + return super.getBeanClassName(); + } + + public void setJavaClass(Class javaClass) { + super.setBeanClass(javaClass); + } + + public void setName(String className) { + super.setBeanClassName(className); + } + + public String getURI() { + return uri; + } + + public void setURI(String uri) { + this.uri = uri; + } + + public ConstrainingType getConstrainingType() { + return constrainingType; + } + + //TODO use a better list implementation + private List properties = new ArrayList() { + private static final long serialVersionUID = 1L; + + // Add a property + @Override + public boolean add(Property property) { + + // Add corresponding bean property value + getPropertyValues().addPropertyValue(property.getName(), property.getValue()); + + return super.add(property); + } + }; + + public List getProperties() { + return properties; + } + + //TODO use a better list implementation + private List references = new ArrayList() { + private static final long serialVersionUID = 1L; + + // Add a reference + @Override + public boolean add(Reference reference) { + + // Add corresponding bean property value + String target; + if (!reference.getTargets().isEmpty()) { + //TODO handle multiplicity + target = reference.getTargets().get(0).getName(); + int i = target.indexOf('/'); + if (i != -1) + target = target.substring(0, i); + } else { + target = null; + } + getPropertyValues().addPropertyValue(reference.getName(), target); + + return super.add(reference); + } + }; + + public List getReferences() { + return references; + } + + public List getServices() { + return services; + } + + public void setConstrainingType(ConstrainingType constrainingType) { + this.constrainingType = constrainingType; + } + + public List getExtensions() { + return extensions; + } + + public boolean isUnresolved() { + return unresolved; + } + + public void setUnresolved(boolean unresolved) { + this.unresolved = unresolved; + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/implementation/java/impl/BeanJavaImplementationFactory.java b/tags/java/sca/1.0-RC1b/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/implementation/java/impl/BeanJavaImplementationFactory.java new file mode 100644 index 0000000000..6b19bac413 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/implementation/java/impl/BeanJavaImplementationFactory.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.spring.implementation.java.impl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.sca.implementation.java.IntrospectionException; +import org.apache.tuscany.sca.implementation.java.JavaImplementation; +import org.apache.tuscany.sca.implementation.java.JavaImplementationFactory; +import org.apache.tuscany.sca.implementation.java.impl.JavaClassIntrospectorImpl; +import org.apache.tuscany.sca.implementation.java.introspect.JavaClassVisitor; +import org.springframework.beans.factory.support.BeanDefinitionRegistry; + +/** + * An alternate implementation of the SCA Java assembly model factory that + * creates SCA Java assembly model objects backed by Spring bean definitions. + * + * @version $Rev$ $Date$ + */ +public class BeanJavaImplementationFactory implements JavaImplementationFactory { + + private BeanDefinitionRegistry beanRegistry; + private List visitors = new ArrayList(); + private JavaClassIntrospectorImpl introspector; + + public BeanJavaImplementationFactory(BeanDefinitionRegistry beanRegistry) { + this.beanRegistry = beanRegistry; + introspector = new JavaClassIntrospectorImpl(visitors); + } + + public JavaImplementation createJavaImplementation() { + return new BeanJavaImplementationImpl(beanRegistry); + } + + public void createJavaImplementation(JavaImplementation javaImplementation, Class implementationClass) + throws IntrospectionException { + introspector.introspectClass(javaImplementation, implementationClass); + } + + public JavaImplementation createJavaImplementation(Class implementationClass) throws IntrospectionException { + JavaImplementation javaImplementation = createJavaImplementation(); + introspector.introspectClass(javaImplementation, implementationClass); + return javaImplementation; + } + + public void addClassVisitor(JavaClassVisitor visitor) { + visitors.add(visitor); + } + + public void removeClassVisitor(JavaClassVisitor visitor) { + visitors.remove(visitor); + } + + public List getClassVisitors() { + return visitors; + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/implementation/java/impl/BeanJavaImplementationImpl.java b/tags/java/sca/1.0-RC1b/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/implementation/java/impl/BeanJavaImplementationImpl.java new file mode 100644 index 0000000000..7b24c76711 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/implementation/java/impl/BeanJavaImplementationImpl.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.core.spring.implementation.java.impl; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Member; +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.implementation.java.JavaImplementation; +import org.apache.tuscany.sca.implementation.java.impl.JavaConstructorImpl; +import org.apache.tuscany.sca.implementation.java.impl.JavaElementImpl; +import org.apache.tuscany.sca.implementation.java.impl.JavaResourceImpl; +import org.apache.tuscany.sca.implementation.java.impl.JavaScopeImpl; +import org.springframework.beans.factory.support.BeanDefinitionRegistry; + +/** + * An implementation of the SCA assembly JavaImplementation interface backed by a Spring + * Bean definition. + * + * @version $$Rev$$ $$Date$$ + */ +public class BeanJavaImplementationImpl extends BeanBaseJavaImplementationImpl implements JavaImplementation { + private static final long serialVersionUID = 6792198458193774178L; + + private JavaConstructorImpl constructorDefinition; + private Map constructors = new HashMap(); + private Method initMethod; + private Method destroyMethod; + private final Map resources = new HashMap(); + private final Map propertyMembers = new HashMap(); + private final Map referenceMembers = new HashMap(); + private final Map callbackMembers = new HashMap(); + private List conversationIDMember = new ArrayList(); + private boolean eagerInit; + private boolean allowsPassByReference; + private List allowsPassByReferenceMethods = new ArrayList(); + private long maxAge = -1; + private long maxIdleTime = -1; + private JavaScopeImpl scope = JavaScopeImpl.STATELESS; + + protected BeanJavaImplementationImpl(BeanDefinitionRegistry beanRegistry) { + super(beanRegistry); + } + + public JavaConstructorImpl getConstructor() { + return constructorDefinition; + } + + public void setConstructor(JavaConstructorImpl definition) { + this.constructorDefinition = definition; + } + + public Method getInitMethod() { + return initMethod; + } + + public void setInitMethod(Method initMethod) { + this.initMethod = initMethod; + } + + public Method getDestroyMethod() { + return destroyMethod; + } + + public void setDestroyMethod(Method destroyMethod) { + this.destroyMethod = destroyMethod; + } + + public Map getResources() { + return resources; + } + + public List getConversationIDMembers() { + return this.conversationIDMember; + } + + public void addConversationIDMember(Member conversationIDMember) { + this.conversationIDMember.add(conversationIDMember); + } + + public boolean isAllowsPassByReference() { + return allowsPassByReference; + } + + public void setAllowsPassByReference(boolean allowsPassByReference) { + this.allowsPassByReference = allowsPassByReference; + } + + public List getAllowsPassByReferenceMethods() { + return allowsPassByReferenceMethods; + } + + public boolean isAllowsPassByReference(Method method) { + return allowsPassByReference || allowsPassByReferenceMethods.contains(method); + } + + public Map getConstructors() { + return constructors; + } + + public boolean isEagerInit() { + return eagerInit; + } + + public void setEagerInit(boolean eagerInit) { + this.eagerInit = eagerInit; + } + + public Map getCallbackMembers() { + return callbackMembers; + } + + public Map getPropertyMembers() { + return propertyMembers; + } + + public Map getReferenceMembers() { + return referenceMembers; + } + + public JavaScopeImpl getJavaScope() { + return scope; + } + + public void setJavaScope(JavaScopeImpl scope) { + this.scope = scope; + } + + public long getMaxAge() { + return maxAge; + } + + public void setMaxAge(long maxAge) { + this.maxAge = maxAge; + } + + public long getMaxIdleTime() { + return maxIdleTime; + } + + public void setMaxIdleTime(long maxIdleTime) { + this.maxIdleTime = maxIdleTime; + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/implementation/java/impl/BeanJavaInterfaceContractImpl.java b/tags/java/sca/1.0-RC1b/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/implementation/java/impl/BeanJavaInterfaceContractImpl.java new file mode 100644 index 0000000000..17a7e9084c --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/implementation/java/impl/BeanJavaInterfaceContractImpl.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.core.spring.implementation.java.impl; + +import org.apache.tuscany.sca.interfacedef.java.impl.JavaInterfaceContractImpl; + +/** + * An implementation of a Java interface contract. + * + * @version $Rev$ $Date$ + */ +public class BeanJavaInterfaceContractImpl extends JavaInterfaceContractImpl { + + protected BeanJavaInterfaceContractImpl() { + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/implementation/java/impl/BeanJavaInterfaceFactory.java b/tags/java/sca/1.0-RC1b/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/implementation/java/impl/BeanJavaInterfaceFactory.java new file mode 100644 index 0000000000..492ab2732e --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/implementation/java/impl/BeanJavaInterfaceFactory.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.spring.implementation.java.impl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException; +import org.apache.tuscany.sca.interfacedef.java.JavaInterface; +import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceContract; +import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory; +import org.apache.tuscany.sca.interfacedef.java.impl.JavaInterfaceIntrospectorImpl; +import org.apache.tuscany.sca.interfacedef.java.introspect.JavaInterfaceVisitor; + +/** + * An alternate implementation of the SCA Java assembly model factory that creates SCA + * Java assembly model objects backed by Spring bean definitions. + * + * @version $Rev$ $Date$ + */ +public class BeanJavaInterfaceFactory implements JavaInterfaceFactory { + + private List visitors = new ArrayList(); + private JavaInterfaceIntrospectorImpl introspector; + + public BeanJavaInterfaceFactory() { + introspector = new JavaInterfaceIntrospectorImpl(this); + } + + public JavaInterface createJavaInterface() { + return new BeanJavaInterfaceImpl(); + } + + public JavaInterface createJavaInterface(Class interfaceClass) throws InvalidInterfaceException { + JavaInterface javaInterface = createJavaInterface(); + introspector.introspectInterface(javaInterface, interfaceClass); + return javaInterface; + } + + public void createJavaInterface(JavaInterface javaInterface, Class interfaceClass) throws InvalidInterfaceException { + introspector.introspectInterface(javaInterface, interfaceClass); + } + + public JavaInterfaceContract createJavaInterfaceContract() { + return new BeanJavaInterfaceContractImpl(); + } + + public void addInterfaceVisitor(JavaInterfaceVisitor extension) { + visitors.add(extension); + } + + public void removeInterfaceVisitor(JavaInterfaceVisitor extension) { + visitors.remove(extension); + } + + public List getInterfaceVisitors() { + return visitors; + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/implementation/java/impl/BeanJavaInterfaceImpl.java b/tags/java/sca/1.0-RC1b/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/implementation/java/impl/BeanJavaInterfaceImpl.java new file mode 100644 index 0000000000..5f90ddf454 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/implementation/java/impl/BeanJavaInterfaceImpl.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.core.spring.implementation.java.impl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.java.JavaInterface; +import org.apache.tuscany.sca.policy.Intent; + +/** + * An alternate implementation of the SCA Java assembly model JavaInterface + * interface. + * + * @version $Rev$ $Date$ + */ +public class BeanJavaInterfaceImpl implements JavaInterface { + + private String className; + private Class javaClass; + private Class callbackClass; + private boolean conversational; + private boolean remotable; + List requiredIntents = new ArrayList(); + private List extensions = new ArrayList(); + private List operations = new ArrayList(); + private boolean unresolved = false; + + protected BeanJavaInterfaceImpl() { + } + + public String getName() { + if (isUnresolved()) { + return className; + } + else { + return javaClass.getName(); + } + } + + public void setName(String className) { + if (!isUnresolved()) + throw new IllegalStateException(); + this.className = className; + } + + public Class getJavaClass() { + return javaClass; + } + + public void setJavaClass(Class javaClass) { + this.javaClass = javaClass; + } + + public Class getCallbackClass() { + return callbackClass; + } + + public void setCallbackClass(Class callbackClass) { + this.callbackClass = callbackClass; + } + + public boolean isConversational() { + return conversational; + } + + public boolean isRemotable() { + return remotable; + } + + public void setConversational(boolean conversational) { + this.conversational = conversational; + } + + public void setRemotable(boolean local) { + this.remotable = local; + } + + public List getRequiredIntents() { + return requiredIntents; + } + + public List getExtensions() { + return extensions; + } + + public List getOperations() { + return operations; + } + + public boolean isUnresolved() { + return unresolved; + } + + public void setUnresolved(boolean undefined) { + this.unresolved = undefined; + } + + public void setDefaultDataBinding(String dataBinding) { + } + + public boolean isDynamic() { + return false; + } + + @Override + public Object clone() throws CloneNotSupportedException { + return super.clone(); + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/core-spring/src/test/java/calculator/AddService.java b/tags/java/sca/1.0-RC1b/modules/core-spring/src/test/java/calculator/AddService.java new file mode 100644 index 0000000000..4eeb30a9c2 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core-spring/src/test/java/calculator/AddService.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 calculator; + +public interface AddService { + + double add(double n1, double n2); + +} diff --git a/tags/java/sca/1.0-RC1b/modules/core-spring/src/test/java/calculator/AddServiceImpl.java b/tags/java/sca/1.0-RC1b/modules/core-spring/src/test/java/calculator/AddServiceImpl.java new file mode 100644 index 0000000000..ea3e5341d5 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core-spring/src/test/java/calculator/AddServiceImpl.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 calculator; + +import org.osoa.sca.annotations.EagerInit; +import org.osoa.sca.annotations.Scope; + +/** + * An implementation of the Add service + */ +@Scope("COMPOSITE") +@EagerInit +public class AddServiceImpl implements AddService { + + public double add(double n1, double n2) { + return n1 + n2; + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/core-spring/src/test/java/calculator/CalculatorClient.java b/tags/java/sca/1.0-RC1b/modules/core-spring/src/test/java/calculator/CalculatorClient.java new file mode 100644 index 0000000000..56e737e3ab --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core-spring/src/test/java/calculator/CalculatorClient.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 calculator; + +import org.apache.tuscany.sca.core.spring.context.SCADomainContext; + +/** + * This client program shows how to create an SCA runtime, start it, locate the + * Calculator service and invoke it. + */ +public class CalculatorClient { + public static void main(String[] args) throws Exception { + + SCADomainContext context = new SCADomainContext("org/apache/tuscany/core/spring/Calculator.composite"); + + CalculatorService calculatorService = context.getService(CalculatorService.class, "CalculatorServiceComponent"); + + // Calculate + System.out.println("3 + 2=" + calculatorService.add(3, 2)); + System.out.println("3 - 2=" + calculatorService.subtract(3, 2)); + System.out.println("3 * 2=" + calculatorService.multiply(3, 2)); + System.out.println("3 / 2=" + calculatorService.divide(3, 2)); + + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/core-spring/src/test/java/calculator/CalculatorService.java b/tags/java/sca/1.0-RC1b/modules/core-spring/src/test/java/calculator/CalculatorService.java new file mode 100644 index 0000000000..c89043276e --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core-spring/src/test/java/calculator/CalculatorService.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 calculator; + +/** + * The Calculator service interface. + */ +public interface CalculatorService { + + double add(double n1, double n2); + + double subtract(double n1, double n2); + + double multiply(double n1, double n2); + + double divide(double n1, double n2); + +} diff --git a/tags/java/sca/1.0-RC1b/modules/core-spring/src/test/java/calculator/CalculatorServiceImpl.java b/tags/java/sca/1.0-RC1b/modules/core-spring/src/test/java/calculator/CalculatorServiceImpl.java new file mode 100644 index 0000000000..11e8974657 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core-spring/src/test/java/calculator/CalculatorServiceImpl.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 calculator; + +import org.osoa.sca.annotations.Reference; +import org.osoa.sca.annotations.Scope; + +/** + * An implementation of the Calculator service. + */ +@Scope("COMPOSITE") +public class CalculatorServiceImpl implements CalculatorService { + + private AddService addService; + private SubtractService subtractService; + private MultiplyService multiplyService; + private DivideService divideService; + + @Reference + public void setAddService(AddService addService) { + this.addService = addService; + } + + @Reference + public void setSubtractService(SubtractService subtractService) { + this.subtractService = subtractService; + } + + @Reference + public void setDivideService(DivideService divideService) { + this.divideService = divideService; + } + + @Reference + public void setMultiplyService(MultiplyService multiplyService) { + this.multiplyService = multiplyService; + } + + public double add(double n1, double n2) { + return addService.add(n1, n2); + } + + public double subtract(double n1, double n2) { + return subtractService.subtract(n1, n2); + } + + public double multiply(double n1, double n2) { + return multiplyService.multiply(n1, n2); + } + + public double divide(double n1, double n2) { + return divideService.divide(n1, n2); + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/core-spring/src/test/java/calculator/DivideService.java b/tags/java/sca/1.0-RC1b/modules/core-spring/src/test/java/calculator/DivideService.java new file mode 100644 index 0000000000..131c5a8014 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core-spring/src/test/java/calculator/DivideService.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 calculator; + +public interface DivideService { + + double divide(double n1, double n2); + +} diff --git a/tags/java/sca/1.0-RC1b/modules/core-spring/src/test/java/calculator/DivideServiceImpl.java b/tags/java/sca/1.0-RC1b/modules/core-spring/src/test/java/calculator/DivideServiceImpl.java new file mode 100644 index 0000000000..9c7e96a668 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core-spring/src/test/java/calculator/DivideServiceImpl.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 calculator; + +import org.osoa.sca.annotations.Scope; + +/** + * An implementation of the Divide service. + */ +@Scope("COMPOSITE") +public class DivideServiceImpl implements DivideService { + + public double divide(double n1, double n2) { + return n1 / n2; + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/core-spring/src/test/java/calculator/MultiplyService.java b/tags/java/sca/1.0-RC1b/modules/core-spring/src/test/java/calculator/MultiplyService.java new file mode 100644 index 0000000000..a917896aeb --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core-spring/src/test/java/calculator/MultiplyService.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 calculator; + +public interface MultiplyService { + + double multiply(double n1, double n2); + +} diff --git a/tags/java/sca/1.0-RC1b/modules/core-spring/src/test/java/calculator/MultiplyServiceImpl.java b/tags/java/sca/1.0-RC1b/modules/core-spring/src/test/java/calculator/MultiplyServiceImpl.java new file mode 100644 index 0000000000..4892481203 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core-spring/src/test/java/calculator/MultiplyServiceImpl.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 calculator; + +import org.osoa.sca.annotations.Scope; + +/** + * An implementation of the Multiply service. + */ +@Scope("COMPOSITE") +public class MultiplyServiceImpl implements MultiplyService { + + public double multiply(double n1, double n2) { + return n1 * n2; + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/core-spring/src/test/java/calculator/NestedCalculatorClient.java b/tags/java/sca/1.0-RC1b/modules/core-spring/src/test/java/calculator/NestedCalculatorClient.java new file mode 100644 index 0000000000..27430b7f5d --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core-spring/src/test/java/calculator/NestedCalculatorClient.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 calculator; + +import org.apache.tuscany.sca.core.spring.context.SCADomainContext; + +/** + * This client program shows how to create an SCA runtime, start it, locate the + * Calculator service and invoke it. + */ +public class NestedCalculatorClient { + public static void main(String[] args) throws Exception { + + SCADomainContext context = new SCADomainContext( + "org/apache/tuscany/core/spring/OuterCalculator.composite", + "org/apache/tuscany/core/spring/InnerCalculator.composite", + "org/apache/tuscany/core/spring/InnerOperations.composite"); + + CalculatorService calculatorService = context.getService(CalculatorService.class, "CalculatorServiceComponent/CalculatorServiceComponent"); + + // Calculate + System.out.println("3 + 2=" + calculatorService.add(3, 2)); + System.out.println("3 - 2=" + calculatorService.subtract(3, 2)); + System.out.println("3 * 2=" + calculatorService.multiply(3, 2)); + System.out.println("3 / 2=" + calculatorService.divide(3, 2)); + + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/core-spring/src/test/java/calculator/SubtractService.java b/tags/java/sca/1.0-RC1b/modules/core-spring/src/test/java/calculator/SubtractService.java new file mode 100644 index 0000000000..e328f024ea --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core-spring/src/test/java/calculator/SubtractService.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 calculator; + +public interface SubtractService { + + double subtract(double n1, double n2); + +} diff --git a/tags/java/sca/1.0-RC1b/modules/core-spring/src/test/java/calculator/SubtractServiceImpl.java b/tags/java/sca/1.0-RC1b/modules/core-spring/src/test/java/calculator/SubtractServiceImpl.java new file mode 100644 index 0000000000..ee1d7c3457 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core-spring/src/test/java/calculator/SubtractServiceImpl.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 calculator; + +import org.osoa.sca.annotations.Scope; + +/** + * An implementation of the subtract service. + */ +@Scope("COMPOSITE") +public class SubtractServiceImpl implements SubtractService { + + public double subtract(double n1, double n2) { + return n1 - n2; + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/core-spring/src/test/java/org/apache/tuscany/sca/core/spring/CalculatorTestCase.java b/tags/java/sca/1.0-RC1b/modules/core-spring/src/test/java/org/apache/tuscany/sca/core/spring/CalculatorTestCase.java new file mode 100644 index 0000000000..6e81358b03 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core-spring/src/test/java/org/apache/tuscany/sca/core/spring/CalculatorTestCase.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.spring; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.core.spring.context.SCADomainContext; + +import calculator.CalculatorService; + +/** + * This shows how to test the Calculator service component. + */ +public class CalculatorTestCase extends TestCase { + + private SCADomainContext context; + private CalculatorService calculatorService; + + @Override + protected void setUp() throws Exception { + context = new SCADomainContext("org/apache/tuscany/sca/core/spring/Calculator.composite"); + + calculatorService = context.getService(CalculatorService.class, "CalculatorServiceComponent"); + } + + @Override + protected void tearDown() throws Exception { + } + + public void testCalculator() throws Exception { + // Calculate + assertEquals(calculatorService.add(3, 2), 5.0); + assertEquals(calculatorService.subtract(3, 2), 1.0); + assertEquals(calculatorService.multiply(3, 2), 6.0); + assertEquals(calculatorService.divide(3, 2), 1.5); + + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/core-spring/src/test/java/org/apache/tuscany/sca/core/spring/NestedCalculatorTestCaseFIXME.java b/tags/java/sca/1.0-RC1b/modules/core-spring/src/test/java/org/apache/tuscany/sca/core/spring/NestedCalculatorTestCaseFIXME.java new file mode 100644 index 0000000000..04e4d6232e --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core-spring/src/test/java/org/apache/tuscany/sca/core/spring/NestedCalculatorTestCaseFIXME.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.spring; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.core.spring.context.SCADomainContext; + +import calculator.CalculatorService; + +/** + * This shows how to test the Calculator service component. + */ +public class NestedCalculatorTestCaseFIXME extends TestCase { + + private SCADomainContext context; + private CalculatorService calculatorService; + + @Override + protected void setUp() throws Exception { + context = new SCADomainContext( + "org/apache/tuscany/sca/core/spring/OuterCalculator.composite", + "org/apache/tuscany/sca/core/spring/InnerCalculator.composite", + "org/apache/tuscany/sca/core/spring/InnerOperations.composite"); + + calculatorService = context.getService(CalculatorService.class, "CalculatorServiceComponent/InnerCalculatorServiceComponent"); + } + + @Override + protected void tearDown() throws Exception { + } + + public void testCalculator() throws Exception { + // Calculate + assertEquals(calculatorService.add(3, 2), 5.0); + assertEquals(calculatorService.subtract(3, 2), 1.0); + assertEquals(calculatorService.multiply(3, 2), 6.0); + assertEquals(calculatorService.divide(3, 2), 1.5); + + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/core-spring/src/test/resources/org/apache/tuscany/sca/core/spring/Calculator.composite b/tags/java/sca/1.0-RC1b/modules/core-spring/src/test/resources/org/apache/tuscany/sca/core/spring/Calculator.composite new file mode 100644 index 0000000000..6d998ba035 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core-spring/src/test/resources/org/apache/tuscany/sca/core/spring/Calculator.composite @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/core-spring/src/test/resources/org/apache/tuscany/sca/core/spring/InnerCalculator.composite b/tags/java/sca/1.0-RC1b/modules/core-spring/src/test/resources/org/apache/tuscany/sca/core/spring/InnerCalculator.composite new file mode 100644 index 0000000000..8b043f2b4f --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core-spring/src/test/resources/org/apache/tuscany/sca/core/spring/InnerCalculator.composite @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/core-spring/src/test/resources/org/apache/tuscany/sca/core/spring/InnerOperations.composite b/tags/java/sca/1.0-RC1b/modules/core-spring/src/test/resources/org/apache/tuscany/sca/core/spring/InnerOperations.composite new file mode 100644 index 0000000000..d7d1124050 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core-spring/src/test/resources/org/apache/tuscany/sca/core/spring/InnerOperations.composite @@ -0,0 +1,57 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/core-spring/src/test/resources/org/apache/tuscany/sca/core/spring/OuterCalculator.composite b/tags/java/sca/1.0-RC1b/modules/core-spring/src/test/resources/org/apache/tuscany/sca/core/spring/OuterCalculator.composite new file mode 100644 index 0000000000..c2b6cced36 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core-spring/src/test/resources/org/apache/tuscany/sca/core/spring/OuterCalculator.composite @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/core/.checkstyle b/tags/java/sca/1.0-RC1b/modules/core/.checkstyle new file mode 100644 index 0000000000..3e57539570 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core/.checkstyle @@ -0,0 +1,24 @@ + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/core/.pmd b/tags/java/sca/1.0-RC1b/modules/core/.pmd new file mode 100644 index 0000000000..ffc4fe2bbb --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core/.pmd @@ -0,0 +1,20 @@ + + +true diff --git a/tags/java/sca/1.0-RC1b/modules/core/.ruleset b/tags/java/sca/1.0-RC1b/modules/core/.ruleset new file mode 100644 index 0000000000..ba9b5ce886 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core/.ruleset @@ -0,0 +1,190 @@ + + + + PMD Plugin preferences rule set + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/core/DISCLAIMER b/tags/java/sca/1.0-RC1b/modules/core/DISCLAIMER new file mode 100644 index 0000000000..d68a410903 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core/DISCLAIMER @@ -0,0 +1,8 @@ +Apache Tuscany is an effort undergoing incubation at The Apache Software +Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is +required of all newly accepted projects until a further review indicates that +the infrastructure, communications, and decision making process have stabilized +in a manner consistent with other successful ASF projects. While incubation +status is not necessarily a reflection of the completeness or stability of the +code, it does indicate that the project has yet to be fully endorsed by the ASF. + diff --git a/tags/java/sca/1.0-RC1b/modules/core/LICENSE b/tags/java/sca/1.0-RC1b/modules/core/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/core/NOTICE b/tags/java/sca/1.0-RC1b/modules/core/NOTICE new file mode 100644 index 0000000000..94481d6cfa --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2007 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/tags/java/sca/1.0-RC1b/modules/core/pom.xml b/tags/java/sca/1.0-RC1b/modules/core/pom.xml new file mode 100644 index 0000000000..3cf18c7bca --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core/pom.xml @@ -0,0 +1,76 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.0-incubating + ../pom.xml + + tuscany-core + Apache Tuscany SCA Core Runtime + + + + org.apache.tuscany.sca + tuscany-core-spi + 1.0-incubating + + + + org.apache.tuscany.sca + tuscany-contribution + 1.0-incubating + + + + org.apache.tuscany.sca + tuscany-contribution-java + 1.0-incubating + + + + org.apache.tuscany.sca + tuscany-interface-java + 1.0-incubating + + + + org.apache.geronimo.specs + geronimo-commonj_1.1_spec + 1.0 + + + + org.codehaus.woodstox + wstx-asl + 3.2.1 + runtime + + + + cglib + cglib-nodep + 2.1_3 + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/ActivationException.java b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/ActivationException.java new file mode 100644 index 0000000000..c86c876075 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/CompositeActivator.java b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/CompositeActivator.java new file mode 100644 index 0000000000..29dcc20f0b --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/CompositeActivatorImpl.java b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/CompositeActivatorImpl.java new file mode 100644 index 0000000000..2a52b5f272 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/CompositeActivatorImpl.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.core.assembly; + +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.Implementation; +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.OptimizableBinding; +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.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.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 final static 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 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, + 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.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); + } + } + + 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); + } + } + } + + 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 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); + } + return bindingProvider; + } else { + throw new IllegalStateException("Provider factory not found for class: " + binding.getClass().getName()); + } + } + + /** + * @param reference + */ + private void resolveTargets(RuntimeComponentReference reference) { + // Support for distributed domain follows + + // go over any targets that have not been resolved yet (as they are running on other nodes) + // and try an resolve them remotely + // TODO - this should work for any kind of wired binding but the only wireable binding + // is currently the SCA binding so we assume that + for (ComponentService service : reference.getTargets()) { + if (service.isUnresolved()) { + for (Binding binding : service.getBindings()) { + // TODO - we should look at all the bindings now associated with the + // unresolved target but we assume the SCA binding here as + // its currently the only wireable one + if (binding instanceof OptimizableBinding) { + OptimizableBinding scaBinding = (OptimizableBinding)binding; + + // clone the SCA binding and fill in service details + // its cloned as each target + SCABinding clonedSCABinding = null; + try { + clonedSCABinding = (SCABinding)((OptimizableBinding)scaBinding).clone(); + clonedSCABinding.setURI(service.getName()); + // wireable binding stuff needs to go. SCA binding uses it + // currently to get to the service to work out if the service + // is resolved. + OptimizableBinding endpoint = ((OptimizableBinding)clonedSCABinding); + endpoint.setTargetComponentService(service); + //endpoint.setTargetComponent(component); - not known for unresolved target + //endpoint.setTargetBinding(serviceBinding); - not known for unresolved target + + // add the cloned SCA binding to the reference as it will be used to look up the + // provider later + reference.getBindings().remove(binding); + reference.getBindings().add(clonedSCABinding); + } catch (Exception e) { + // warning("The binding doesn't support clone: " + binding.getClass().getSimpleName(), binding); + } + } else { + throw new IllegalStateException( + "Unable to create a distributed SCA binding provider for reference: " + reference + .getName() + + " and target: " + + service.getName()); + } + } + } + } + } + + /** + * 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(); + } + + // 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 + } + } + } + */ + } + + /** + * 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 = + componentTypeRef == null ? reference.getInterfaceContract() : 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 (binding.getName().equals(refBinding.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); + + 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()); + } + } + + private void removeImplementationProvider(RuntimeComponent component) { + component.setImplementationProvider(null); + } + + /** + * @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); + } + 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); + } + + private void removeReferenceBindingProvider(RuntimeComponent component, + RuntimeComponentReference reference, + Binding binding) { + reference.setBindingProvider(binding, null); + } + + 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 (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); + 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 (Binding binding : reference.getBindings()) { + ReferenceBindingProvider bindingProvider = runtimeRef.getBindingProvider(binding); + if (bindingProvider != null) { + bindingProvider.start(); + } + } + } + + 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()) { + ServiceBindingProvider bindingProvider = runtimeService.getBindingProvider(binding); + if (bindingProvider != null) { + bindingProvider.start(); + } + } + } + + 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 (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()) { + ServiceBindingProvider bindingProvider = ((RuntimeComponentService)service).getBindingProvider(binding); + if (bindingProvider != null) { + bindingProvider.stop(); + } + } + } + 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()) { + ReferenceBindingProvider bindingProvider = runtimeRef.getBindingProvider(binding); + if (bindingProvider != null) { + bindingProvider.stop(); + } + } + } + Implementation implementation = component.getImplementation(); + if (implementation instanceof Composite) { + stop((Composite)implementation); + } else { + ImplementationProvider implementationProvider = ((RuntimeComponent)component).getImplementationProvider(); + if (implementationProvider != null) { + implementationProvider.stop(); + } + } + + if (component instanceof ScopedRuntimeComponent) { + ScopedRuntimeComponent runtimeComponent = (ScopedRuntimeComponent)component; + if (runtimeComponent.getScopeContainer() != null) { + 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 (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 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) { + String prefix = componentURI + "/"; + for (Component component : composite.getComponents()) { + String uri = component.getURI(); + if (uri.equals(componentURI)) { + return component; + } + if (componentURI.startsWith(prefix)) { + 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/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/EndpointReferenceImpl.java b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/EndpointReferenceImpl.java new file mode 100644 index 0000000000..d3aebcf97a --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/EndpointReferenceImpl.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.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(); + 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/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/ReferenceParameterProcessor.java b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/ReferenceParameterProcessor.java new file mode 100644 index 0000000000..555eb43e4c --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/ReferenceParameterProcessor.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.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.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.runtime.ReferenceParameters; + +/** + * @version $Rev$ $Date$ + */ +public class ReferenceParameterProcessor implements StAXArtifactProcessor { + private final static QName REFERENCE_PARAMETERS = + new QName("http://tuscany.apache.org/xmlns/sca/1.0", "referenceParameters", "tuscany"); + + /** + * @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/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/ReferenceParametersImpl.java b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/ReferenceParametersImpl.java new file mode 100644 index 0000000000..14a5f565fc --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/RuntimeAssemblyFactory.java b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/RuntimeAssemblyFactory.java new file mode 100644 index 0000000000..b174dea6ce --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/RuntimeComponentImpl.java b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/RuntimeComponentImpl.java new file mode 100644 index 0000000000..e232ff63c6 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/RuntimeComponentImpl.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.core.assembly; + +import org.apache.tuscany.sca.assembly.impl.ComponentImpl; +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.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentContext; + +/** + * @version $Rev$ $Date$ + */ +public class RuntimeComponentImpl extends ComponentImpl implements RuntimeComponent, ScopedRuntimeComponent { + protected RuntimeComponentContext componentContext; + protected ImplementationProvider implementationProvider; + protected ScopeContainer scopeContainer; + protected boolean started; + + /** + */ + 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; + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/RuntimeComponentReferenceImpl.java b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/RuntimeComponentReferenceImpl.java new file mode 100644 index 0000000000..c7def053ef --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/RuntimeComponentReferenceImpl.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.core.assembly; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.impl.ComponentReferenceImpl; +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.ReferenceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.apache.tuscany.sca.runtime.RuntimeWire; + +public class RuntimeComponentReferenceImpl extends ComponentReferenceImpl implements RuntimeComponentReference { + private List wires; + private Map bindingProviders = 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; + } + } + return null; + } + + public ReferenceBindingProvider getBindingProvider(Binding binding) { + return bindingProviders.get(binding); + } + + public void setBindingProvider(Binding binding, ReferenceBindingProvider bindingProvider) { + bindingProviders.put(binding, bindingProvider); + } + + 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(); + return ref; + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/RuntimeComponentServiceImpl.java b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/RuntimeComponentServiceImpl.java new file mode 100644 index 0000000000..d3e722038e --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/RuntimeComponentServiceImpl.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.core.assembly; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +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.ServiceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; +import org.apache.tuscany.sca.runtime.RuntimeWire; +import org.osoa.sca.ServiceRuntimeException; + +public class RuntimeComponentServiceImpl extends ComponentServiceImpl implements RuntimeComponentService { + private List wires = new ArrayList(); + private List callbackWires = new ArrayList(); + private Map bindingProviders = 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 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 = + (Map)((HashMap)bindingProviders).clone(); + clone.wires = (List)((ArrayList)wires).clone(); + clone.callbackWires = (List)((ArrayList)callbackWires).clone(); + return clone; + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/RuntimeWireImpl.java b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/RuntimeWireImpl.java new file mode 100644 index 0000000000..b47d6d43d5 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/RuntimeWireImpl.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.assembly; + +import java.lang.reflect.InvocationTargetException; +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.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.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.provider.ImplementationProvider; +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.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; + + private List chains; + + /** + * @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 InvocationChain getInvocationChain(Operation operation) { + 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())) { + return chain; + } + } + return null; + } + + public Object invoke(Operation operation, Object[] args) throws InvocationTargetException { + Message msg = messageFactory.createMessage(); + msg.setBody(args); + msg.setTo(wireTarget); + 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); + if (operation.isNonBlocking()) { + addNonBlockingInterceptor(reference, refBinding, chain); + } + addBindingInterceptor(reference, refBinding, chain, operation); + chains.add(chain); + } + } else { + // It's the service wire + RuntimeComponentService service = (RuntimeComponentService)wireTarget.getContract(); + RuntimeComponent serviceComponent = wireTarget.getComponent(); + 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); + addImplementationInterceptor(serviceComponent, service, chain, targetOperation); + chains.add(chain); + } + } + wireProcessor.process(this); + } + + 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 binding + * + * @param reference + * @param binding + * @param chain + * @param operation + */ + private void addBindingInterceptor(ComponentReference reference, + Binding binding, + InvocationChain chain, + Operation operation) { + try { + ReferenceBindingProvider provider = ((RuntimeComponentReference)reference).getBindingProvider(binding); + if (provider != null) { + Invoker invoker = provider.createInvoker(operation); + if (invoker != null) { + chain.addInvoker(invoker); + } + } + } catch (RuntimeException e) { + throw e; + } + } + + /** + * 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(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); + } + } + + /** + * @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); + return copy; + } + + /** + * @return the conversationManager + */ + public ConversationManager getConversationManager() { + return conversationManager; + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/context/CallableReferenceImpl.java b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/context/CallableReferenceImpl.java new file mode 100644 index 0000000000..d4f0962f07 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/context/CallableReferenceImpl.java @@ -0,0 +1,349 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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.util.UUID; + +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.Reference; +import org.apache.tuscany.sca.assembly.SCABinding; +import org.apache.tuscany.sca.assembly.OptimizableBinding; +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.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.factory.ObjectFactory; +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, ObjectFactory { + protected transient CompositeActivator compositeActivator; + protected transient ProxyFactory proxyFactory; + + protected transient Class businessInterface; + + // 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; + + protected CallableReferenceImpl() { + super(); + } + + 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 spec is not clear how we should handle multiplicty for CallableReference + if (this.binding == null) { + this.binding = this.reference.getBinding(SCABinding.class); + if (this.binding == null) { + this.binding = this.reference.getBindings().get(0); + } + } + + // 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(); + RuntimeWire wire = this.reference.getRuntimeWire(this.binding); + init(wire); + } + + public CallableReferenceImpl(Class businessInterface, RuntimeWire wire, ProxyFactory proxyFactory) { + this.proxyFactory = proxyFactory; + this.businessInterface = businessInterface; + bind(wire); + } + + public RuntimeWire getRuntimeWire() { + if (reference != null) { + return reference.getRuntimeWire(binding); + } else { + return null; + } + } + + protected void bind(RuntimeWire wire) { + if (wire != null) { + 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(); + init(wire); + } + } + + protected void init(RuntimeWire wire) { + EndpointReference target = wire.getTarget(); + + // look to see if the target is conversational and if so create a conversation + InterfaceContract contract = target.getInterfaceContract(); + if (contract == null) { + contract = reference.getInterfaceContract(); + } + Interface contractInterface = contract.getInterface(); + + if (contract.getCallbackInterface() != null) { + this.callbackID = createCallbackID(); + } + } + + public B getInstance() throws ObjectCreationException { + try { + resolve(); + //FIXME Can't we just return a single proxy + return businessInterface.cast(proxyFactory.createProxy(this)); + } catch (Exception e) { + throw new ObjectCreationException(e); + } + } + + public B getService() { + try { + return getInstance(); + } catch (Exception e) { + throw new ServiceRuntimeException(e); + } + } + + public Class getBusinessInterface() { + return businessInterface; + } + + public boolean isConversational() { + return reference == null ? false : reference.getInterfaceContract().getInterface().isConversational(); + } + + public Conversation getConversation() { + if (conversation == null || conversation.getState() == ConversationState.ENDED) { + conversation = null; + } + return conversation; + } + + public Object getCallbackID() { + return callbackID; + } + + /** + * @see java.io.Externalizable#readExternal(java.io.ObjectInput) + */ + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + this.scdl = in.readUTF(); + } + + /** + * @throws IOException + */ + private synchronized void resolve() throws Exception { + if (scdl != null && component == null && reference == null) { + ComponentContextHelper componentContextHelper = ComponentContextHelper.getCurrentComponentContextHelper(); + if (componentContextHelper != null) { + CompositeActivator currentActivator = ComponentContextHelper.getCurrentCompositeActivator(); + this.compositeActivator = currentActivator; + this.conversationManager = this.compositeActivator.getConversationManager(); + Component c = componentContextHelper.fromXML(scdl); + this.component = (RuntimeComponent)c; + currentActivator.configureComponentContext(this.component); + this.reference = (RuntimeComponentReference)c.getReferences().get(0); + this.reference.setComponent(this.component); + ReferenceParameters parameters = null; + for (Object ext : reference.getExtensions()) { + if (ext instanceof ReferenceParameters) { + parameters = (ReferenceParameters)ext; + break; + } + } + if (parameters != null) { + this.callbackID = parameters.getCallbackID(); + this.conversationID = parameters.getConversationID(); + } + + for (Binding binding : reference.getBindings()) { + if (binding instanceof OptimizableBinding) { + String targetURI = binding.getURI(); + int index = targetURI.lastIndexOf('/'); + String serviceName = ""; + if (index > -1) { + serviceName = targetURI.substring(index + 1); + targetURI = targetURI.substring(0, index); + } + Component targetComponet = compositeActivator.resolve(targetURI); + ComponentService targetService = null; + if (targetComponet != null) { + if ("".equals(serviceName)) { + targetService = ComponentContextHelper.getSingleService(targetComponet); + } else { + for (ComponentService service : targetComponet.getServices()) { + if (service.getName().equals(serviceName)) { + targetService = service; + break; + } + } + } + } + OptimizableBinding optimizableBinding = (OptimizableBinding)binding; + optimizableBinding.setTargetComponent(targetComponet); + optimizableBinding.setTargetComponentService(targetService); + if (targetService != null) { + for (Binding serviceBinding : targetService.getBindings()) { + if (serviceBinding.getClass() == binding.getClass()) { + optimizableBinding.setTargetBinding(serviceBinding); + break; + } + } + } + } + } + // FIXME: The SCA spec is not clear how we should handle multiplicty 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()) { + javaInterface.setJavaClass(Thread.currentThread().getContextClassLoader() + .loadClass(javaInterface.getName())); + currentActivator.getJavaInterfaceFactory().createJavaInterface(javaInterface, + javaInterface.getJavaClass()); + } + this.businessInterface = (Class)javaInterface.getJavaClass(); + } + this.proxyFactory = currentActivator.getProxyFactory(); + } + } + } + + /** + * @see java.io.Externalizable#writeExternal(java.io.ObjectOutput) + */ + public void writeExternal(ObjectOutput out) throws IOException { + try { + if (reference != null) { + ReferenceParameters parameters = new ReferenceParametersImpl(); + parameters.setCallbackID(callbackID); + if (conversationID != null) { + parameters.setConversationID(conversationID); + } else { + parameters.setConversationID(null); + } + reference.getExtensions().add(parameters); + scdl = + ((CompositeActivatorImpl)compositeActivator).getComponentContextHelper() + .toXML(component, reference); + reference.getExtensions().remove(parameters); + } + out.writeUTF(scdl); + } catch (Exception e) { + e.printStackTrace(); + throw new IOException(e.getMessage()); + } + } + + /** + * 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; + } + + + protected ReferenceParameters getReferenceParameters() { + ReferenceParameters parameters = new ReferenceParametersImpl(); + parameters.setCallbackID(callbackID); + if (getConversation() != null) { + parameters.setConversationID(conversation.getConversationID()); + } + return parameters; + } + + public EndpointReference getEndpointReference() { + // 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; + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/context/ComponentContextHelper.java b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/context/ComponentContextHelper.java new file mode 100644 index 0000000000..5bf70b2a0f --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/context/ComponentContextHelper.java @@ -0,0 +1,295 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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.Reference; +import org.apache.tuscany.sca.assembly.Service; +import org.apache.tuscany.sca.assembly.OptimizableBinding; +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.assembly.ReferenceParameterProcessor; +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; + staxProcessors.addArtifactProcessor(new ReferenceParameterProcessor()); + } + + /** + * 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 { + 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); + comp.getReferences().add(reference); + + 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 RuntimeComponent read(Reader reader) throws IOException { + try { + StAXArtifactProcessor processor = staxProcessors.getProcessor(Composite.class); + XMLInputFactory inputFactory = XMLInputFactory.newInstance(); + XMLStreamReader streamReader = inputFactory.createXMLStreamReader(reader); + 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 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/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/context/ComponentContextImpl.java b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/context/ComponentContextImpl.java new file mode 100644 index 0000000000..4d48cbf6f2 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/context/ComponentContextImpl.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.core.context; + +import java.io.IOException; +import java.io.Reader; +import java.io.Writer; + +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.Reference; +import org.apache.tuscany.sca.assembly.Service; +import org.apache.tuscany.sca.assembly.OptimizableBinding; +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; + + 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())) { + 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); + } + } + + public B getProperty(Class type, String propertyName) { + for (ComponentProperty p : component.getProperties()) { + if (propertyName.equals(propertyName)) { + return type.cast(p.getValue()); + } + } + 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(); + ref.setInterfaceContract(interfaceContract); + } + 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 { + 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; + } + + /** + * @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); + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/context/DefaultComponentContextFactory.java b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/context/DefaultComponentContextFactory.java new file mode 100644 index 0000000000..c5b68389b2 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/context/InstanceWrapper.java b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/context/InstanceWrapper.java new file mode 100644 index 0000000000..b577180291 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/context/RequestContextImpl.java b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/context/RequestContextImpl.java new file mode 100644 index 0000000000..7df1fa6166 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/context/RequestContextImpl.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.context; + +import java.util.List; + +import javax.security.auth.Subject; + +import org.apache.tuscany.sca.core.invocation.CallbackWireObjectFactory; +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() { + throw new UnsupportedOperationException(); + } + + 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.getTo().getReferenceParameters(); + ((CallableReferenceImpl) callableReference).attachCallbackID(parameters.getCallbackID()); + if (callableReference.getConversation() != null) { + ((CallableReferenceImpl) callableReference).attachConversationID(parameters.getConversationID()); + } + return callableReference; + } + + @SuppressWarnings("unchecked") + public CB getCallback() { + return (CB) getCallbackReference().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(); + CallbackWireObjectFactory factory = new CallbackWireObjectFactory(javaClass, proxyFactory, wires); + factory.resolveTarget(); + ReferenceParameters parameters = msgContext.getTo().getReferenceParameters(); + factory.attachCallbackID(parameters.getCallbackID()); + if (factory.getConversation() != null) { + factory.attachConversationID(parameters.getConversationID()); + } + return factory; + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/context/ServiceReferenceImpl.java b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/context/ServiceReferenceImpl.java new file mode 100644 index 0000000000..b2944b0ea7 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/context/ServiceReferenceImpl.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.core.context; + +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 ServiceReferenceImpl() { + super(); + } + + /** + * @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("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; + } + + 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("java:" + System.identityHashCode(callback)); + } + } + return parameters; + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/conversation/ConversationListener.java b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/conversation/ConversationListener.java new file mode 100644 index 0000000000..efa362a929 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/conversation/ConversationManager.java b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/conversation/ConversationManager.java new file mode 100644 index 0000000000..97fa13ba46 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/conversation/ConversationManager.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.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 listner to this conversation + * @param listener + */ + void addListener(ConversationListener listener); + + /** + * Remove a listener from this conversation + * @param listener + */ + void removeListener(ConversationListener listener); +} diff --git a/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/conversation/ConversationManagerImpl.java b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/conversation/ConversationManagerImpl.java new file mode 100644 index 0000000000..c053c9e4e8 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/conversation/ConversationManagerImpl.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.core.conversation; + +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; + + +/** + * @version $Rev$ $Date$ + */ +public class ConversationManagerImpl implements ConversationManager { + private List listeners = Collections.synchronizedList(new ArrayList()); + private Map converations = new ConcurrentHashMap(); + + /** + * @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); + converations.remove(conversationID); + } else { + throw new IllegalStateException("Conversation " + conversationID + " doesn't exist."); + } + } + + public void expireConversation(Object conversationID) { + ExtendedConversation conv = getConversation(conversationID); + if (conv != null) { + ((ExtendedConversationImpl)conv).setState(ConversationState.EXPIRED); + for (ConversationListener listener : listeners) { + listener.conversationExpired(conv); + } + } 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) { + return converations.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); + } + + /** + * @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); + converations.put(conversationID, conversation); + for (ConversationListener listener : listeners) { + listener.conversationStarted(conversation); + } + return conversation; + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/conversation/ConversationState.java b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/conversation/ConversationState.java new file mode 100644 index 0000000000..692d6861ba --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/conversation/ExtendedConversation.java b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/conversation/ExtendedConversation.java new file mode 100644 index 0000000000..635b2d7cf5 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/conversation/ExtendedConversation.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.core.conversation; + +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(); + + /** + * Mark the conversation expired + */ + void expire(); + + /** + * @param state the state to set + */ + public void setState(ConversationState state); + + /** + * @param conversationID the conversationID to set + */ + public void setConversationID(Object conversationID); +} diff --git a/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/conversation/ExtendedConversationImpl.java b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/conversation/ExtendedConversationImpl.java new file mode 100644 index 0000000000..256f9cc4ad --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/conversation/ExtendedConversationImpl.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.core.conversation; + + +/** + * + * @version $Rev$ $Date$ + */ +public class ExtendedConversationImpl implements ExtendedConversation { + private ConversationManager manager; + private Object conversationID; + private ConversationState state; + + /** + * @param manager + * @param conversationID + * @param state + */ + public ExtendedConversationImpl(ConversationManager manager, Object conversationID, ConversationState state) { + super(); + this.manager = manager; + this.conversationID = conversationID; + this.state = state; + } + + public void expire() { + manager.expireConversation(conversationID); + } + + public ConversationState getState() { + return state; + } + + public void end() { + manager.endConversation(conversationID); + } + + public Object getConversationID() { + return conversationID; + } + + /** + * @param state the state to set + */ + public void setState(ConversationState state) { + this.state = state; + } + + /** + * @param conversationID the conversationID to set + */ + public void setConversationID(Object conversationID) { + if (state != ConversationState.ENDED) { + throw new IllegalStateException("The state of conversation " + conversationID + " " + state); + } + this.conversationID = conversationID; + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/event/BaseEventPublisher.java b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/event/BaseEventPublisher.java new file mode 100644 index 0000000000..517e5579a4 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/event/ComponentStart.java b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/event/ComponentStart.java new file mode 100644 index 0000000000..8e90c953e5 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/event/ComponentStop.java b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/event/ComponentStop.java new file mode 100644 index 0000000000..d879182e14 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/event/ConversationEnd.java b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/event/ConversationEnd.java new file mode 100644 index 0000000000..cd14710880 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/event/ConversationStart.java b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/event/ConversationStart.java new file mode 100644 index 0000000000..a4cc49204e --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/event/HttpSessionEnd.java b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/event/HttpSessionEnd.java new file mode 100644 index 0000000000..4c3fd8b397 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/event/HttpSessionStart.java b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/event/HttpSessionStart.java new file mode 100644 index 0000000000..67b922b99c --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/event/RequestEnd.java b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/event/RequestEnd.java new file mode 100644 index 0000000000..8b5c512cf2 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/event/RequestStart.java b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/event/RequestStart.java new file mode 100644 index 0000000000..974563b57c --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/factory/ObjectCreationException.java b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/factory/ObjectCreationException.java new file mode 100644 index 0000000000..d35b27fd24 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/factory/ObjectFactory.java b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/factory/ObjectFactory.java new file mode 100644 index 0000000000..3f64d2405b --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallableReferenceObjectFactory.java b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallableReferenceObjectFactory.java new file mode 100644 index 0000000000..1ec007eacf --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallableReferenceObjectFactory.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.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 callable reference + * + * @version $Rev$ $Date$ + */ +public class CallableReferenceObjectFactory implements ObjectFactory> { + private CallableReference callableReference; + + /** + * Constructor. + * + * To support the @Reference protected CallableReference ref; + * + * @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 CallableReferenceObjectFactory(Class businessInterface, + RuntimeComponent component, + RuntimeComponentReference reference, + Binding binding) { + this.callableReference = + component.getComponentContext().getServiceReference(businessInterface, reference, binding); + } + + public CallableReferenceObjectFactory(CallableReference callableReference) { + this.callableReference = callableReference; + } + + public CallableReference getInstance() throws ObjectCreationException { + return callableReference; + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallbackInterfaceInterceptor.java b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallbackInterfaceInterceptor.java new file mode 100644 index 0000000000..cd1f12a995 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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.getTo().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/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallbackWireObjectFactory.java b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallbackWireObjectFactory.java new file mode 100644 index 0000000000..8eb706446a --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallbackWireObjectFactory.java @@ -0,0 +1,183 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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.assembly.Binding; +import org.apache.tuscany.sca.assembly.OptimizableBinding; +import org.apache.tuscany.sca.core.context.CallableReferenceImpl; +import org.apache.tuscany.sca.core.factory.ObjectCreationException; +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; +import org.osoa.sca.ServiceRuntimeException; + +/** + * Returns proxy instance for a wire callback + * + * @version $Rev$ $Date$ + */ +public class CallbackWireObjectFactory extends CallableReferenceImpl { + private RuntimeWire wire; + private List wires; + private EndpointReference resolvedEndpoint; + + public CallbackWireObjectFactory(Class interfaze, ProxyFactory proxyFactory, List wires) { + super(interfaze, null, proxyFactory); + this.wires = wires; + } + + public void resolveTarget() { + Message msgContext = ThreadMessageContext.getMessageContext(); + wire = selectCallbackWire(msgContext); + if (wire == null) { + //FIXME: need better exception + throw new RuntimeException("No callback wire found for " + msgContext.getFrom().getURI()); + } + this.resolvedEndpoint = getCallbackEndpoint(msgContext); + bind(wire); + } + + @Override + public B getInstance() throws ObjectCreationException { + if (wire != null) { + // wire and endpoint already resolved, so return a pre-wired proxy + wire.setTarget(resolvedEndpoint); + wire.rebuild(); + return super.getInstance(); + } else { + // wire not yet selected, so return a proxy that resolves the target dynamically + return proxyFactory.createCallbackProxy(businessInterface, wires); + } + } + + public RuntimeWire selectCallbackWire(Message msgContext) { + EndpointReference callbackEPR = getCallbackEndpoint(msgContext); + if (callbackEPR == null) { + return null; + } + + //FIXME: need a cache for better performance. This requires making this + // method non-static, which means changing the signature of createCallbackProxy(). + + // first choice is wire with matching destination endpoint + for (RuntimeWire wire : wires) { + if (callbackEPR.getURI().equals(wire.getTarget().getURI())) { + try { + return (RuntimeWire)wire.clone(); + } catch (CloneNotSupportedException e) { + throw new ServiceRuntimeException(e); + } + } + } + + // no exact match, so find 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())) { + //FIXME: need better way to represent dynamic wire + if (wire.getTarget().getURI().equals("/")) { // dynamic wire + //FIXME: avoid doing this for genuine dynamic wires + return cloneAndBind(msgContext, wire); + } + //FIXME: no dynamic wire, so should attempt to create a static wire + } + } + + // no match so far, so find callback binding with same type as service binding + for (RuntimeWire wire : wires) { + if (wire.getSource().getBinding().getClass() == to.getBinding().getClass()) { + //FIXME: need better way to represent dynamic wire + if (wire.getTarget().getURI().equals("/")) { // dynamic wire + //FIXME: avoid doing this for genuine dynamic wires + return cloneAndBind(msgContext, wire); + } + //FIXME: no dynamic wire, so should attempt to create a static wire + } + } + + // no suitable callback wire was found + return null; + } + + /** + * @param msgContext + */ + private static EndpointReference getCallbackEndpoint(Message msgContext) { + EndpointReference to = msgContext.getTo(); + if (to == null) { + return null; + } + return to.getReferenceParameters().getCallbackReference(); + } + + private static RuntimeWire cloneAndBind(Message msgContext, RuntimeWire wire) { + EndpointReference callback = getCallbackEndpoint(msgContext); + if (callback != null && callback.getContract() != null) { + try { + RuntimeComponentReference ref = null; + if (callback.getContract() instanceof RuntimeComponentReference) { + ref = (RuntimeComponentReference)callback.getContract(); + return ref.getRuntimeWire(callback.getBinding()); + } else { + ref = + bind((RuntimeComponentReference)wire.getSource().getContract(), + callback.getComponent(), + (RuntimeComponentService)callback.getContract()); + + return ref.getRuntimeWires().get(0); + } + } catch (CloneNotSupportedException e) { + // will not happen + return null; + } + } else { + return wire; + } + } + + 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; + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CglibProxyFactory.java b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CglibProxyFactory.java new file mode 100644 index 0000000000..e498717dbd --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CglibProxyFactory.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.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.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() { + this(new MessageFactoryImpl(), new InterfaceContractMapperImpl()); + } + + public CglibProxyFactory(MessageFactory messageFactory, InterfaceContractMapper mapper) { + this.messageFactory = messageFactory; + + } + + public T createProxy(Class interfaze, RuntimeWire wire) throws ProxyCreationException { + Enhancer enhancer = new Enhancer(); + enhancer.setSuperclass(interfaze); + enhancer.setCallback(new CglibMethodInterceptor(interfaze, wire)); + Object proxy = enhancer.create(); + return interfaze.cast(proxy); + } + + /** + * 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(); + enhancer.setSuperclass(interfaze); + enhancer.setCallback(new CglibMethodInterceptor(callableReference)); + Object proxy = enhancer.create(); + 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 { + Enhancer enhancer = new Enhancer(); + enhancer.setSuperclass(interfaze); + enhancer.setCallback(new CglibMethodInterceptor(interfaze, wires)); + Object proxy = enhancer.create(); + 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(Class interfaze, RuntimeWire wire) { + ServiceReference serviceRef = new ServiceReferenceImpl(interfaze, wire, CglibProxyFactory.this); + invocationHandler = new JDKInvocationHandler(messageFactory, serviceRef); + } + + public CglibMethodInterceptor(Class interfaze, List wires) { + CallbackWireObjectFactory wireFactory = new CallbackWireObjectFactory(interfaze, CglibProxyFactory.this, wires); + invocationHandler = new JDKCallbackInvocationHandler(messageFactory, wireFactory); + } + + /** + * @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/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/DefaultProxyFactoryExtensionPoint.java b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/DefaultProxyFactoryExtensionPoint.java new file mode 100644 index 0000000000..b40574394b --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/DefaultProxyFactoryExtensionPoint.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.core.invocation; + +import java.util.List; + +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; + +public class DefaultProxyFactoryExtensionPoint implements ProxyFactoryExtensionPoint { + private InterfaceContractMapper interfaceContractMapper; + private MessageFactory messageFactory; + + private ProxyFactory interfaceFactory; + private ProxyFactory classFactory; + + public DefaultProxyFactoryExtensionPoint() { + this(new MessageFactoryImpl(), new InterfaceContractMapperImpl()); + } + + public DefaultProxyFactoryExtensionPoint(MessageFactory messageFactory, InterfaceContractMapper mapper) { + this.interfaceContractMapper = mapper; + this.messageFactory = messageFactory; + interfaceFactory = new JDKProxyFactory(messageFactory, mapper); + } + + /** + * @see org.apache.tuscany.sca.core.invocation.ProxyFactoryExtensionPoint#getClassProxyFactory() + */ + public ProxyFactory getClassProxyFactory() { + return classFactory; + } + + /** + * @see org.apache.tuscany.sca.core.invocation.ProxyFactoryExtensionPoint#getInterfaceProxyFactory() + */ + public ProxyFactory getInterfaceProxyFactory() { + return interfaceFactory; + } + + /** + * @see org.apache.tuscany.sca.core.invocation.ProxyFactoryExtensionPoint#setClassProxyFactory(org.apache.tuscany.sca.core.invocation.ProxyFactory) + */ + public void setClassProxyFactory(ProxyFactory factory) { + this.classFactory = factory; + + } + + /** + * @see org.apache.tuscany.sca.core.invocation.ProxyFactoryExtensionPoint#setInterfaceProxyFactory(org.apache.tuscany.sca.core.invocation.ProxyFactory) + */ + public void setInterfaceProxyFactory(ProxyFactory factory) { + this.interfaceFactory = factory; + + } + + /** + * @see org.apache.tuscany.sca.core.invocation.ProxyFactory#cast(java.lang.Object) + */ + @SuppressWarnings("unchecked") + public > R cast(B target) throws IllegalArgumentException { + 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 { + if (interfaze.isInterface()) { + return interfaceFactory.createCallbackProxy(interfaze, wires); + } else { + return classFactory.createCallbackProxy(interfaze, wires); + } + } + + public T createProxy(CallableReference callableReference) throws ProxyCreationException { + if (callableReference.getBusinessInterface().isInterface()) { + return interfaceFactory.createProxy(callableReference); + } else { + return classFactory.createProxy(callableReference); + } + } + + /** + * @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 { + 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) { + return interfaceFactory.isProxyClass(clazz) || (classFactory != null && classFactory.isProxyClass(clazz)); + } + + /** + * @return the interfaceContractMapper + */ + public InterfaceContractMapper getInterfaceContractMapper() { + return interfaceContractMapper; + } + + /** + * @return the messageFactory + */ + public MessageFactory getMessageFactory() { + return messageFactory; + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ExtensibleWireProcessor.java b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ExtensibleWireProcessor.java new file mode 100644 index 0000000000..934f2f7aa0 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/InvocationChainImpl.java b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/InvocationChainImpl.java new file mode 100644 index 0000000000..72ce0f87fb --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/InvocationChainImpl.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.core.invocation; + +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; + +/** + * Default implementation of an invocation chain + * + * @version $Rev$ $Date$ + */ +public class InvocationChainImpl implements InvocationChain { + private Operation sourceOperation; + private Operation targetOperation; + private Invoker invokerChainHead; + private Invoker invokerChainTail; + + public InvocationChainImpl(Operation operation) { + assert operation != null; + this.targetOperation = operation; + this.sourceOperation = operation; + } + + public InvocationChainImpl(Operation sourceOperation, Operation targetOperation) { + assert sourceOperation != null; + assert targetOperation != null; + this.targetOperation = targetOperation; + this.sourceOperation = sourceOperation; + } + + public Operation getTargetOperation() { + return targetOperation; + } + + public void setTargetOperation(Operation operation) { + this.targetOperation = operation; + } + + public void addInterceptor(Interceptor interceptor) { + if (invokerChainHead == null) { + invokerChainHead = interceptor; + } else { + if (invokerChainHead instanceof Interceptor) { + ((Interceptor)invokerChainTail).setNext(interceptor); + } + } + invokerChainTail = interceptor; + } + + public void addInvoker(Invoker invoker) { + if (invokerChainHead == null) { + invokerChainHead = invoker; + } else { + if (invokerChainTail instanceof Interceptor) { + ((Interceptor)invokerChainTail).setNext(invoker); + } + } + invokerChainTail = invoker; + } + + public Invoker getHeadInvoker() { + return invokerChainHead; + } + + public Invoker getTailInvoker() { + return invokerChainTail; + } + + /** + * @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) { + int i = 0; + Invoker next = invokerChainHead; + Invoker prev = null; + while (next != null && i < index) { + prev = next; + if (next instanceof Interceptor) { + next = ((Interceptor)next).getNext(); + i++; + } else { + throw new ArrayIndexOutOfBoundsException(index); + } + } + if (i == index) { + if (prev != null) { + ((Interceptor)prev).setNext(interceptor); + } else { + invokerChainHead = interceptor; + } + interceptor.setNext(next); + if (next == null) { + invokerChainTail = interceptor; + } + } else { + throw new ArrayIndexOutOfBoundsException(index); + } + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/JDKCallbackInvocationHandler.java b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/JDKCallbackInvocationHandler.java new file mode 100644 index 0000000000..6442bb7bfc --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/JDKCallbackInvocationHandler.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.core.invocation; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import org.apache.tuscany.sca.assembly.Binding; +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.invocation.InvocationChain; +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.RuntimeComponentReference; +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, CallbackWireObjectFactory wireFactory) { + super(messageFactory, wireFactory); + 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); + } + + // wire not pre-selected, so select a wire now to be used for the callback + Message msgContext = ThreadMessageContext.getMessageContext(); + RuntimeWire wire = ((CallbackWireObjectFactory)callableReference).selectCallbackWire(msgContext); + if (wire == null) { + //FIXME: need better exception + throw new ServiceRuntimeException("No callback wire found for " + msgContext.getFrom().getURI()); + } + + // set the conversational state based on the interface that + // is specified for the reference that this wire belongs to + init(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 = msgContext.getTo().getReferenceParameters().getConversationID(); + if (convID != null) { + conversation = ((RuntimeWireImpl)wire).getConversationManager().getConversation(convID); + if (callableReference != null) { + ((CallableReferenceImpl)callableReference).attachConversation(conversation); + } + } + } + } + + callbackID = msgContext.getTo().getReferenceParameters().getCallbackID(); + ((CallbackWireObjectFactory)callableReference).attachCallbackID(callbackID); + + EndpointReference epr = msgContext.getTo().getReferenceParameters().getCallbackReference(); + setEndpoint(epr); + + // 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 + wire.getSource().getBinding().setURI(epr.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(); + Binding binding = wire.getSource().getBinding(); + wire.getTarget().setInterfaceContract(ref.getBindingProvider(binding).getBindingInterfaceContract()); + + //FIXME: can we use the same code as JDKInvocationHandler to select the chain? + InvocationChain chain = getInvocationChain(method, wire); + if (chain == null) { + throw new IllegalArgumentException("No matching operation is found: " + method); + } + + try { + return invoke(chain, args, wire); + } catch (InvocationTargetException e) { + Throwable t = e.getCause(); + if (t instanceof NoRegisteredCallbackException) { + throw t; + } + throw e; + } + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/JDKInvocationHandler.java b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/JDKInvocationHandler.java new file mode 100644 index 0000000000..a3cbb08691 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/JDKInvocationHandler.java @@ -0,0 +1,411 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +import org.apache.tuscany.sca.core.assembly.RuntimeWireImpl; +import org.apache.tuscany.sca.core.context.CallableReferenceImpl; +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.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.CallableReference; +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 target; + protected Object conversationID; + protected Object callbackID; + protected Object callbackObject; + protected RuntimeWire wire; + protected CallableReference callableReference; + protected Class businessInterface; + + protected boolean fixedWire = true; + protected transient Map chains = new HashMap(); + + 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.callbackID = callableReference.getCallbackID(); + this.conversation = (ExtendedConversation)callableReference.getConversation(); + this.wire = ((CallableReferenceImpl)callableReference).getRuntimeWire(); + if (callableReference instanceof ServiceReference) { + this.conversationID = ((ServiceReference)callableReference).getConversationID(); + this.callbackObject = ((ServiceReference)callableReference).getCallback(); + } + if (wire != null) { + init(wire); + } + } + } + + protected void init(RuntimeWire wire) { + if (wire != null) { + try { + // Clone the wire so that reference parameters can be changed + this.wire = (RuntimeWire)wire.clone(); + } catch (CloneNotSupportedException e) { + throw new ServiceRuntimeException(e); + } + } + InterfaceContract contract = wire.getSource().getInterfaceContract(); + this.conversational = contract.getInterface().isConversational(); + } + + 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); + } + + // send the invocation down the wire + Object result = invoke(chain, args, wire); + + 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 + */ + @SuppressWarnings("unchecked") + private static boolean match(Operation operation, Method method) { + Class[] params = method.getParameterTypes(); + DataType> 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]; + if (!operation.getInputType().getLogical().get(i).getPhysical().isAssignableFrom(clazz)) { + matched = false; + } + } + } else { + matched = false; + } + return matched; + + } + + protected synchronized InvocationChain getInvocationChain(Method method, RuntimeWire wire) { + if (fixedWire && chains.containsKey(method)) { + return chains.get(method); + } + 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) throws Throwable { + + Message msg = messageFactory.createMessage(); + msg.setFrom(wire.getSource()); + if (target != null) { + msg.setTo(target); + } else { + msg.setTo(wire.getTarget()); + } + Invoker headInvoker = chain.getHeadInvoker(); + Operation operation = chain.getTargetOperation(); + msg.setOperation(operation); + msg.setBody(args); + + Message msgContext = ThreadMessageContext.getMessageContext(); + Object currentConversationID = msgContext.getTo().getReferenceParameters().getConversationID(); + + conversationPreinvoke(msg, wire); + handleCallback(msg, wire, currentConversationID); + ThreadMessageContext.setMessageContext(msg); + try { + // dispatch the wire down the chain and get the response + Message resp = headInvoker.invoke(msg); + Object body = resp.getBody(); + if (resp.isFault()) { + throw (Throwable)body; + } + return body; + } finally { + conversationPostInvoke(msg, wire); + ThreadMessageContext.setMessageContext(msgContext); + } + } + + /** + * @param msg + * @param wire + * @param interfaze + * @throws TargetResolutionException + */ + private void handleCallback(Message msg, RuntimeWire wire, Object currentConversationID) + throws TargetResolutionException { + ReferenceParameters parameters = msg.getTo().getReferenceParameters(); + parameters.setCallbackID(callbackID); + if (wire.getSource() == null || wire.getSource().getCallbackEndpoint() == null) { + return; + } + + parameters.setCallbackReference(wire.getSource().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 + if (conversational && callbackObject == null) { + // the component instance is already registered + // so add another registration + ScopeContainer scopeContainer = getConversationalScopeContainer(wire); + + if (scopeContainer != null) { + scopeContainer.addWrapperReference(currentConversationID, conversation.getConversationID()); + } + } + + Interface interfaze = msg.getOperation().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 { + ScopeContainer scopeContainer = getConversationalScopeContainer(wire); + if (scopeContainer != null) { + InstanceWrapper wrapper = new CallbackObjectWrapper(callbackObject); + scopeContainer.registerWrapper(wrapper, conversation.getConversationID()); + } + parameters.setCallbackObjectID("java:" + System.identityHashCode(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(conversationID); + if (callableReference != null) { + ((CallableReferenceImpl)callableReference).attachConversation(conversation); + } + } + // TODO - assuming that the conversation ID is a string here when + // it can be any object that is serializable to XML + msg.getTo().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) throws TargetDestructionException { + Operation operation = msg.getOperation(); + ConversationSequence sequence = operation.getConversationSequence(); + if (sequence == ConversationSequence.CONVERSATION_END) { + conversation.end(); + + // remove conversation id from scope container + ScopeContainer scopeContainer = getConversationalScopeContainer(wire); + + if (scopeContainer != null) { + scopeContainer.remove(conversation.getConversationID()); + } + } + } + + 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 conversational id + * + * @return the conversational id + */ + private Object createConversationID() { + if (conversationID == null) { + return UUID.randomUUID().toString(); + } + return conversationID; + } + + /** + * @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 + } + + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/JDKProxyFactory.java b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/JDKProxyFactory.java new file mode 100644 index 0000000000..20bc36c0cd --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/JDKProxyFactory.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.invocation; + +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Proxy; +import java.util.List; + +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; + +/** + * the default implementation of a wire service that uses JDK dynamic proxies + * + * @version $$Rev$$ $$Date: 2007-04-11 18:59:43 -0700 (Wed, 11 Apr + * 2007) $$ + */ +public class JDKProxyFactory implements ProxyFactory { + protected InterfaceContractMapper contractMapper; + private MessageFactory messageFactory; + + public JDKProxyFactory() { + this(new MessageFactoryImpl(), new InterfaceContractMapperImpl()); + } + + 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 conversaton object to null + */ + public T createProxy(Class interfaze, RuntimeWire wire) throws ProxyCreationException { + JDKInvocationHandler handler = new JDKInvocationHandler(messageFactory, interfaze, wire); + ClassLoader cl = interfaze.getClassLoader(); + return interfaze.cast(Proxy.newProxyInstance(cl, new Class[] {interfaze}, handler)); + } + + public T createProxy(CallableReference callableReference) throws ProxyCreationException { + assert callableReference != null; + Class interfaze = callableReference.getBusinessInterface(); + JDKInvocationHandler handler = new JDKInvocationHandler(messageFactory, callableReference); + ClassLoader cl = interfaze.getClassLoader(); + return interfaze.cast(Proxy.newProxyInstance(cl, new Class[] {interfaze}, handler)); + } + + public T createCallbackProxy(Class interfaze, List wires) throws ProxyCreationException { + ClassLoader cl = interfaze.getClassLoader(); + CallbackWireObjectFactory wireFactory = new CallbackWireObjectFactory(interfaze, this, wires); + JDKCallbackInvocationHandler handler = new JDKCallbackInvocationHandler(messageFactory, wireFactory); + return interfaze.cast(Proxy.newProxyInstance(cl, new Class[] {interfaze}, handler)); + } + + public > R cast(B target) throws IllegalArgumentException { + InvocationHandler handler = Proxy.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 Proxy.isProxyClass(clazz); + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/MessageFactoryImpl.java b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/MessageFactoryImpl.java new file mode 100644 index 0000000000..6e182a6a14 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/MessageImpl.java b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/MessageImpl.java new file mode 100644 index 0000000000..1e4e8fc6a9 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/MessageImpl.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.core.invocation; + +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 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; + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/NoMethodForOperationException.java b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/NoMethodForOperationException.java new file mode 100644 index 0000000000..733544d387 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/NonBlockingInterceptor.java b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/NonBlockingInterceptor.java new file mode 100644 index 0000000000..e8621571e4 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/NonBlockingInterceptor.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.invocation; + +import java.util.LinkedList; + +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(); + + 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 usefull 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 { + next.invoke(msg); + } 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; + } + + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ProxyCreationException.java b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ProxyCreationException.java new file mode 100644 index 0000000000..c0646f577a --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ProxyFactory.java b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ProxyFactory.java new file mode 100644 index 0000000000..b72730397e --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ProxyFactory.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.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 callable reference + * + * @param callableReference The callable reference + * @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; + + /** + * Cast a proxy to a CallableReference. + * + * @param target a proxy generated by this implementation + * @return a CallableReference (or subclass) equivalent to this prozy + * @throws IllegalArgumentException if the object supplied is not a proxy + */ + > 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/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ProxyFactoryExtensionPoint.java b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ProxyFactoryExtensionPoint.java new file mode 100644 index 0000000000..fdd710c465 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ProxyFactoryExtensionPoint.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.core.invocation; + +import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; + +/** + * The extension point to plug in proxy factories + * @version $Rev$ $Date$ + */ +public interface ProxyFactoryExtensionPoint extends ProxyFactory { + /** + * 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); + + /** + * @return the interfaceContractMapper + */ + InterfaceContractMapper getInterfaceContractMapper(); + +} diff --git a/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/RuntimeWireInvoker.java b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/RuntimeWireInvoker.java new file mode 100644 index 0000000000..11d03355e6 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/RuntimeWireInvoker.java @@ -0,0 +1,295 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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.util.UUID; + +import org.apache.tuscany.sca.core.context.CallableReferenceImpl; +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.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.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.ServiceReference; +import org.osoa.sca.ServiceRuntimeException; + +/** + * @version $Rev$ $Date$ + */ +public class RuntimeWireInvoker { + protected ConversationManager conversationManager; + protected boolean conversational; + protected ExtendedConversation conversation; + protected MessageFactory messageFactory; + protected EndpointReference endpoint; + 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(); + } + } + + 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 { + + msg.setFrom(wire.getSource()); + EndpointReference epTo = null; + if (endpoint != null) { + epTo = endpoint; + } else { + epTo = wire.getTarget(); + } + if (msg.getTo() != null) { + msg.getTo().mergeEndpoint(epTo); + } else { + msg.setTo(epTo); + } + Invoker headInvoker = chain.getHeadInvoker(); + Operation operation = chain.getTargetOperation(); + msg.setOperation(operation); + + Message msgContext = ThreadMessageContext.getMessageContext(); + Object currentConversationID = msgContext.getTo().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 to = msgContext.getTo(); + return to == null ? null : to.getReferenceParameters().getCallbackReference(); + } + + /** + * @param msg + * @param wire + * @param interfaze + * @throws TargetResolutionException + */ + @SuppressWarnings("unchecked") + private void handleCallback(Message msg, Object currentConversationID) throws TargetResolutionException { + EndpointReference from = msg.getFrom(); + EndpointReference to = msg.getTo(); + msg.getTo().getReferenceParameters().setCallbackID(callbackID); + if (from == null || from.getCallbackEndpoint() == null) { + return; + } + // 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 + if (conversational && callbackObject == null) { + // the component instance is already registered + // so add another registration + ScopeContainer scopeContainer = getConversationalScopeContainer(msg); + + if (scopeContainer != null) { + scopeContainer.addWrapperReference(currentConversationID, to.getReferenceParameters() + .getConversationID()); + } + } + + ReferenceParameters parameters = msg.getTo().getReferenceParameters(); + Interface interfaze = msg.getOperation().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 { + ScopeContainer scopeContainer = getConversationalScopeContainer(msg); + if (scopeContainer != null) { + InstanceWrapper wrapper = new CallbackObjectWrapper(callbackObject); + scopeContainer.registerWrapper(wrapper, conversation.getConversationID()); + } + parameters.setCallbackObjectID("java:" + System.identityHashCode(callbackObject)); + } + } + } + } + } + + /** + * Pre-invoke for the conversation handling + * @param msg + * @throws TargetResolutionException + */ + private void conversationPreinvoke(Message msg) { + if (!conversational) { + // Not conversational or the conversation has been started + return; + } + if (conversation == null || conversation.getState() == ConversationState.ENDED) { + conversation = conversationManager.startConversation(conversationID); + } + // TODO - assuming that the conversation ID is a string here when + // it can be any object that is serializable to XML + msg.getTo().getReferenceParameters().setConversationID(conversation.getConversationID()); + + } + + /** + * Post-invoke for the conversation handling + * @param wire + * @param operation + * @throws TargetDestructionException + */ + @SuppressWarnings("unchecked") + private void conversationPostInvoke(Message msg) throws TargetDestructionException { + Operation operation = msg.getOperation(); + ConversationSequence sequence = operation.getConversationSequence(); + if (sequence == ConversationSequence.CONVERSATION_END) { + conversation.end(); + + // remove conversation id from scope container + ScopeContainer scopeContainer = getConversationalScopeContainer(msg); + + if (scopeContainer != null) { + scopeContainer.remove(conversation.getConversationID()); + } + } + } + + @SuppressWarnings("unchecked") + private ScopeContainer getConversationalScopeContainer(Message msg) { + ScopeContainer scopeContainer = null; + + RuntimeComponent component = msg.getFrom().getComponent(); + + if (component instanceof ScopedRuntimeComponent) { + ScopedRuntimeComponent scopedRuntimeComponent = (ScopedRuntimeComponent)component; + ScopeContainer container = scopedRuntimeComponent.getScopeContainer(); + + if ((container != null) && (container.getScope() == Scope.CONVERSATION)) { + scopeContainer = container; + } + } + + return scopeContainer; + } + + /** + * Creates a new conversational id + * + * @return the conversational id + */ + private Object createConversationID() { + if (conversationID == null) { + return UUID.randomUUID().toString(); + } + return conversationID; + } + + /** + * 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/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/TargetInvocationException.java b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/TargetInvocationException.java new file mode 100644 index 0000000000..2c4d657882 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ThreadMessageContext.java b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ThreadMessageContext.java new file mode 100644 index 0000000000..7f419028f9 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ThreadMessageContext.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.core.invocation; + +import org.apache.tuscany.sca.core.assembly.EndpointReferenceImpl; +import org.apache.tuscany.sca.invocation.Message; + +/** + * Class for tunneling 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(); + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/WireObjectFactory.java b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/WireObjectFactory.java new file mode 100644 index 0000000000..0a40d49b36 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/WireObjectFactory.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; + +import org.apache.tuscany.sca.core.context.ServiceReferenceImpl; +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 extends ServiceReferenceImpl implements ObjectFactory { + /** + * 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) { + super(interfaze, wire, proxyService); + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/AbstractScopeContainer.java b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/AbstractScopeContainer.java new file mode 100644 index 0000000000..fbc402bfe3 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/AbstractScopeContainer.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.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 spossed 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 implmentation 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/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/CompositeScopeContainer.java b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/CompositeScopeContainer.java new file mode 100644 index 0000000000..7e7ab7a9e4 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/CompositeScopeContainer.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.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(); + wrapper.start(); + } + 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/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/CompositeScopeContainerFactory.java b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/CompositeScopeContainerFactory.java new file mode 100644 index 0000000000..786988613b --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ConversationalScopeContainer.java b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ConversationalScopeContainer.java new file mode 100644 index 0000000000..63968eba23 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ConversationalScopeContainer.java @@ -0,0 +1,405 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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.Iterator; +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; + +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; +import org.osoa.sca.ConversationEndedException; + +/** + * A scope context which manages atomic component instances keyed on ConversationID + * + */ +public class ConversationalScopeContainer extends AbstractScopeContainer implements ConversationListener { + private ConversationManager conversationManager; + private Map instanceLifecycleCollection = + new ConcurrentHashMap(); + + //TODO: This needs to observe the value set by ConversationalAttributes for now we will hard code it. + private long max_age = 60 * 60 * 1000; // 1 hour; + private long max_idle_time = 60 * 60 * 1000; // 1 hour; + private long reaper_interval = 60; // every minute; + private ScheduledExecutorService scheduler; + + 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. + // + String aProperty; + aProperty = System.getProperty("org.apache.tuscany.sca.core.scope.ConversationalScopeContainer.MaxIdleTime"); + if (aProperty != null) { + try { + max_idle_time = (new Long(aProperty) * 1000); + } catch (NumberFormatException nfe) { + // Ignore + } + } + + aProperty = System.getProperty("org.apache.tuscany.sca.core.scope.ConversationalScopeContainer.MaxAge"); + if (aProperty != null) { + try { + max_age = (new Long(aProperty) * 1000); + } catch (NumberFormatException nfe) { + // Ignore + } + } + + aProperty = System.getProperty("org.apache.tuscany.sca.core.scope.ConversationalScopeContainer.ReaperInterval"); + if (aProperty != null) { + try { + reaper_interval = new Long(aProperty); + } catch (NumberFormatException nfe) { + // Ignore + } + } + + // Check to see if the maxAge and/or maxIdleTime have been specified using @ConversationAttributes. + // Implementation annoated attributes are honored first. + if (this.getComponent().getImplementationProvider() instanceof ScopedImplementationProvider) { + ScopedImplementationProvider aScopedImpl = + (ScopedImplementationProvider)this.getComponent().getImplementationProvider(); + + long maxAge = aScopedImpl.getMaxAge(); + if (maxAge > 0) { + max_age = maxAge; + } + long maxIdleTime = aScopedImpl.getMaxIdleTime(); + if (maxIdleTime > 0) { + max_idle_time = maxIdleTime; + } + } + + } + + @Override + public synchronized void start() { + if (lifecycleState != UNINITIALIZED && lifecycleState != STOPPED) { + throw new IllegalStateException("Scope must be in UNINITIALIZED or STOPPED state [" + lifecycleState + "]"); + } + + // Get a scheduler and scheduled a task to be run in the future indefinitely until its explicitly shutdown. + this.scheduler = Executors.newSingleThreadScheduledExecutor(); + scheduler.scheduleAtFixedRate(new ConversationalInstanceReaper(this.instanceLifecycleCollection), + 3, + reaper_interval, + TimeUnit.SECONDS); + + lifecycleState = RUNNING; + } + + @Override + public synchronized void stop() { + + // Prevent the scheduler from submitting any additional reapers, initiate an orderly shutdown if a reaper task is in progress. + if (this.scheduler != null) + this.scheduler.shutdown(); + + lifecycleState = STOPPED; + } + + 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.getTo().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); + } + // If an existing instance is found return it only if its not expired and update its + // last referenced time. + else { + if (anInstanceWrapper.isExpired()) + throw new ConversationEndedException(); + anInstanceWrapper.updateLastReferencedTime(); + } + + 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 + */ + 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); + } + } + + 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 long creationTime; + private long lastReferencedTime; + private long expirationInterval; + private long maxIdleTime; + + private InstanceLifeCycleWrapper(Object contextId) throws TargetResolutionException { + this.clientConversationId = contextId; + this.creationTime = System.currentTimeMillis(); + this.lastReferencedTime = this.creationTime; + this.expirationInterval = max_age; + this.maxIdleTime = max_idle_time; + this.createInstance(contextId); + } + + private InstanceLifeCycleWrapper(InstanceWrapper wrapper, Object contextId) throws TargetResolutionException { + this.clientConversationId = contextId; + this.creationTime = System.currentTimeMillis(); + this.lastReferencedTime = this.creationTime; + this.expirationInterval = max_age; + this.maxIdleTime = max_idle_time; + wrappers.put(contextId, wrapper); + } + + private boolean isExpired() { + long currentTime = System.currentTimeMillis(); + if ((this.lastReferencedTime + this.maxIdleTime) < currentTime) // max idle time exceeded + return true; + if ((this.creationTime + this.expirationInterval) < currentTime) // max time to live exceeded + return true; + + return false; + } + + private void updateLastReferencedTime() { + this.lastReferencedTime = System.currentTimeMillis(); + } + + // 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.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); + } + + } + + // + // This inner class is an instance reaper. It periodically iterates over the InstanceLifeCycleCollection + // and for any instances that have expired removes the backing instance and the entry in the InstanceLifeCycle + // Collection. + // + class ConversationalInstanceReaper implements Runnable { + private Map instanceLifecycleCollection; + + public ConversationalInstanceReaper(Map aMap) { + this.instanceLifecycleCollection = aMap; + } + + public void run() { + Iterator> anIterator = + this.instanceLifecycleCollection.entrySet().iterator(); + + while (anIterator.hasNext()) { + Map.Entry anEntry = anIterator.next(); + InstanceLifeCycleWrapper anInstanceLifeCycleWrapper = anEntry.getValue(); + if (anInstanceLifeCycleWrapper.isExpired()) { + try { + // 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 : anInstanceLifeCycleWrapper.callbackConversations) { + anInstanceLifeCycleWrapper.removeInstanceWrapper(conversationID); + this.instanceLifecycleCollection.remove(conversationID); + } + + if (anInstanceLifeCycleWrapper.clientConversationId != null) { + anInstanceLifeCycleWrapper + .removeInstanceWrapper(anInstanceLifeCycleWrapper.clientConversationId); + this.instanceLifecycleCollection.remove(anInstanceLifeCycleWrapper.clientConversationId); + } + } catch (Exception ex) { + // TODO - what to do with any asynchronous exceptions? + } + } + } + } + } + + /** + * @see org.apache.tuscany.sca.core.conversation.ConversationListener#conversationEnded(org.apache.tuscany.sca.core.conversation.ExtendedConversation) + */ + public void conversationEnded(ExtendedConversation conversation) { + stopContext(conversation.getConversationID()); + } + + /** + * @see org.apache.tuscany.sca.core.conversation.ConversationListener#conversationExpired(org.apache.tuscany.sca.core.conversation.ExtendedConversation) + */ + public void conversationExpired(ExtendedConversation conversation) { + } + + /** + * @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/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ConversationalScopeContainerFactory.java b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ConversationalScopeContainerFactory.java new file mode 100644 index 0000000000..a6663aba09 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/HttpSessionScopeContainer.java b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/HttpSessionScopeContainer.java new file mode 100644 index 0000000000..5ae8b94647 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/HttpSessionScopeContainerFactory.java b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/HttpSessionScopeContainerFactory.java new file mode 100644 index 0000000000..49f89661b1 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/RequestScopeContainer.java b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/RequestScopeContainer.java new file mode 100644 index 0000000000..f11a61e662 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/RequestScopeContainer.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.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(); + // } + 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(); + ctx.start(); + wrappers.put(Thread.currentThread(), ctx); + } + return ctx; + } + + @Override + public InstanceWrapper getWrapper(Thread contextId) throws TargetResolutionException { + return getInstanceWrapper(true); + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/RequestScopeContainerFactory.java b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/RequestScopeContainerFactory.java new file mode 100644 index 0000000000..1cfb6b06a4 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/Scope.java b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/Scope.java new file mode 100644 index 0000000000..0a20d793f7 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ScopeContainer.java b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ScopeContainer.java new file mode 100644 index 0000000000..6b2980b989 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ScopeContainerFactory.java b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ScopeContainerFactory.java new file mode 100644 index 0000000000..b19c14b3e0 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ScopeRegistry.java b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ScopeRegistry.java new file mode 100644 index 0000000000..43a3288ff2 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ScopeRegistryImpl.java b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ScopeRegistryImpl.java new file mode 100644 index 0000000000..75261e11a8 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ScopedImplementationProvider.java b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ScopedImplementationProvider.java new file mode 100644 index 0000000000..85a6626cdd --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ScopedRuntimeComponent.java b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ScopedRuntimeComponent.java new file mode 100644 index 0000000000..c27b112f8a --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/StatelessScopeContainer.java b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/StatelessScopeContainer.java new file mode 100644 index 0000000000..a2c0edb9b4 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/StatelessScopeContainer.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.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(); + ctx.start(); + 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/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/StatelessScopeContainerFactory.java b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/StatelessScopeContainerFactory.java new file mode 100644 index 0000000000..0471b2c52e --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/TargetDestructionException.java b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/TargetDestructionException.java new file mode 100644 index 0000000000..0f83dad97d --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/TargetInitializationException.java b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/TargetInitializationException.java new file mode 100644 index 0000000000..15959c0608 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/TargetNotFoundException.java b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/TargetNotFoundException.java new file mode 100644 index 0000000000..6e51a8c9ec --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/TargetResolutionException.java b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/TargetResolutionException.java new file mode 100644 index 0000000000..ea8d0e876c --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/store/MemoryStore.java b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/store/MemoryStore.java new file mode 100644 index 0000000000..5b838116c5 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/work/Jsr237Work.java b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/work/Jsr237Work.java new file mode 100644 index 0000000000..6fe883157f --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/work/Jsr237Work.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.work; + +/* + * JCA work wrapper. + */ +public class Jsr237Work implements commonj.work.Work { + + // Work that is being executed. + private T work; + + /* + * Initializes the work instance. + */ + public Jsr237Work(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/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/work/Jsr237WorkScheduler.java b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/work/Jsr237WorkScheduler.java new file mode 100644 index 0000000000..1abe040c14 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/work/Jsr237WorkScheduler.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.work; + +import org.apache.tuscany.sca.work.NotificationListener; +import org.apache.tuscany.sca.work.WorkScheduler; +import org.apache.tuscany.sca.work.WorkSchedulerException; + +import commonj.work.WorkEvent; +import commonj.work.WorkListener; + +/** + * 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 implementaion available. For example, if the managed environment supports work manager the runtime can use + * the appropriate lookup mechanism to inject the work manager implementation.

+ */ +public class Jsr237WorkScheduler implements WorkScheduler { + + /** + * Underlying JSR-237 work manager + */ + private ThreadPoolWorkManager jsr237WorkManager; + + /** + * Initializes the JSR 237 work manager. + * + * @param jsr237WorkManager JSR 237 work manager. + */ + public Jsr237WorkScheduler() { + jsr237WorkManager = new ThreadPoolWorkManager(10); + } + + /** + * 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"); + } + + Jsr237Work jsr237Work = new Jsr237Work(work); + try { + if (listener == null) { + jsr237WorkManager.schedule(jsr237Work); + } else { + Jsr237WorkListener jsr237WorkListener = new Jsr237WorkListener(listener, work); + jsr237WorkManager.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() { + jsr237WorkManager.destroy(); + } + + /* + * 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/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/work/ThreadPoolWorkManager.java b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/work/ThreadPoolWorkManager.java new file mode 100644 index 0000000000..60696692e1 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/work/ThreadPoolWorkManager.java @@ -0,0 +1,219 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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 org.osoa.sca.annotations.Destroy; +import org.osoa.sca.annotations.Property; + +import commonj.work.Work; +import commonj.work.WorkEvent; +import commonj.work.WorkException; +import commonj.work.WorkItem; +import commonj.work.WorkListener; +import commonj.work.WorkManager; + +/** + * A thread-pool based implementation for the JSR-237 work manager. + *

+ *

+ * This implementation supports only local work. + *

+ * TODO Elaborate the implementation.

+ */ +public class ThreadPoolWorkManager implements WorkManager { + + // 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. + */ + public ThreadPoolWorkManager(@Property(name = "poolSize") int threadPoolSize) { + 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 { + + WorkItemImpl workItem = new WorkItemImpl(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 WorkEventImpl(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 accptance. + * + * @param workItem Work item representing the work that was accepted. + * @param work Work that was accepted. + */ + private void workAccepted(final WorkItemImpl workItem, final Work work) { + WorkListener listener = workItems.get(workItem); + if (listener != null) { + workItem.setStatus(WorkEvent.WORK_ACCEPTED); + WorkEvent event = new WorkEventImpl(workItem); + listener.workAccepted(event); + } + } + + /* + * Method to indicate a work start. + */ + private void workStarted(final WorkItemImpl workItem, final Work work) { + WorkListener listener = workItems.get(workItem); + if (listener != null) { + workItem.setStatus(WorkEvent.WORK_STARTED); + WorkEvent event = new WorkEventImpl(workItem); + listener.workStarted(event); + } + } + + /* + * Method to indicate a work completion. + */ + private void workCompleted(final WorkItemImpl workItem, final Work work) { + workCompleted(workItem, work, null); + } + + /* + * Method to indicate a work completion. + */ + private void workCompleted(final WorkItemImpl workItem, final Work work, final WorkException exception) { + WorkListener listener = workItems.get(workItem); + if (listener != null) { + workItem.setStatus(WorkEvent.WORK_COMPLETED); + workItem.setResult(work); + workItem.setException(exception); + WorkEvent event = new WorkEventImpl(workItem); + listener.workCompleted(event); + workItems.remove(workItem); + } + } + + /* + * Schedules the work using the threadpool. + */ + private boolean scheduleWork(final Work work, final WorkItemImpl 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 WorkItemImpl workItem; + + // The original work. + private Work decoratedWork; + + /* + * Initializes the work item and underlying work. + */ + private DecoratingWork(final WorkItemImpl 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 WorkException(th.getMessage(), th)); + } + } + + } + + @Destroy + public void destroy() { + executor.shutdown(); + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/work/WorkEventImpl.java b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/work/WorkEventImpl.java new file mode 100644 index 0000000000..62ebeea1fb --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/work/WorkEventImpl.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.work; + + +import commonj.work.WorkEvent; +import commonj.work.WorkException; +import commonj.work.WorkItem; + +/** + * Default immutable implementation of the WorkEvent class. + */ +class WorkEventImpl implements WorkEvent { + + // Work item for this event + private WorkItem workItem; + + // Exception if something has gone wrong + private WorkException exception; + + /** + * Instantiates the event. + * + * @param workItem Work item for this event. + */ + public WorkEventImpl(final WorkItemImpl 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 WorkException getException() { + return exception; + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/work/WorkItemImpl.java b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/work/WorkItemImpl.java new file mode 100644 index 0000000000..39a7c647f7 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core/src/main/java/org/apache/tuscany/sca/core/work/WorkItemImpl.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.core.work; + +import commonj.work.Work; +import commonj.work.WorkException; +import commonj.work.WorkItem; + +/** + * An identity based immutable implementation of the WorkItem + * interface. + * + */ +class WorkItemImpl implements 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 WorkException exception; + + /** + * Instantiates an id for this item. + * + * @param id of this work event. + */ + protected WorkItemImpl(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 WorkException getException() { + return exception; + } + + /** + * Sets the exception. + * + * @param exception Exception. + */ + protected void setException(final WorkException 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() == WorkItemImpl.class) && ((WorkItemImpl) 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() != WorkItemImpl.class) { + throw new ClassCastException(o.getClass().getName()); + } else { + return ((WorkItemImpl) o).getId().compareTo(getId()); + } + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/core/src/test/java/org/apache/tuscany/sca/core/DefaultExtensionPointRegistryTestCase.java b/tags/java/sca/1.0-RC1b/modules/core/src/test/java/org/apache/tuscany/sca/core/DefaultExtensionPointRegistryTestCase.java new file mode 100644 index 0000000000..7b44736d4b --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/core/src/test/java/org/apache/tuscany/sca/core/event/BaseEventPublisherTestCase.java b/tags/java/sca/1.0-RC1b/modules/core/src/test/java/org/apache/tuscany/sca/core/event/BaseEventPublisherTestCase.java new file mode 100644 index 0000000000..2bc78c3d35 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/core/src/test/java/org/apache/tuscany/sca/core/event/EventTestCase.java b/tags/java/sca/1.0-RC1b/modules/core/src/test/java/org/apache/tuscany/sca/core/event/EventTestCase.java new file mode 100644 index 0000000000..48dcf8df07 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/core/src/test/java/org/apache/tuscany/sca/core/scope/AbstractScopeContainerTestCase.java b/tags/java/sca/1.0-RC1b/modules/core/src/test/java/org/apache/tuscany/sca/core/scope/AbstractScopeContainerTestCase.java new file mode 100644 index 0000000000..64114f7fb2 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/core/src/test/java/org/apache/tuscany/sca/core/store/MemoryStoreTestCase.java b/tags/java/sca/1.0-RC1b/modules/core/src/test/java/org/apache/tuscany/sca/core/store/MemoryStoreTestCase.java new file mode 100644 index 0000000000..d46d77b4b8 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/core/src/test/java/org/apache/tuscany/sca/core/wire/CallbackInterfaceInterceptorTestCase.java b/tags/java/sca/1.0-RC1b/modules/core/src/test/java/org/apache/tuscany/sca/core/wire/CallbackInterfaceInterceptorTestCase.java new file mode 100644 index 0000000000..bc5d426a9f --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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.getTo().getReferenceParameters().setCallbackObjectID("java:" + System.identityHashCode("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.getTo().getReferenceParameters().setCallbackObjectID(null); + try { + interceptor.invoke(msg); + fail(); + } catch (NoRegisteredCallbackException e) { + // expected + } + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/core/src/test/java/org/apache/tuscany/sca/core/wire/InvocationChainImplTestCase.java b/tags/java/sca/1.0-RC1b/modules/core/src/test/java/org/apache/tuscany/sca/core/wire/InvocationChainImplTestCase.java new file mode 100644 index 0000000000..83f7bdd887 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core/src/test/java/org/apache/tuscany/sca/core/wire/InvocationChainImplTestCase.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.wire; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.core.invocation.InvocationChainImpl; +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; + +/** + * @version $Rev$ $Date$ + */ +public class InvocationChainImplTestCase extends TestCase { + + public void testInsertAtEnd() throws Exception { + InvocationChain chain = new InvocationChainImpl(new OperationImpl("foo")); + 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()); + + } + + 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; + } + + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/core/src/test/java/org/apache/tuscany/sca/core/wire/NonBlockingInterceptorTestCase.java b/tags/java/sca/1.0-RC1b/modules/core/src/test/java/org/apache/tuscany/sca/core/wire/NonBlockingInterceptorTestCase.java new file mode 100644 index 0000000000..e3fdf483ad --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/core/src/test/java/org/apache/tuscany/sca/core/wire/NonBlockingInterceptorTestCase.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.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.replay(next); + EasyMock.replay(msg); + Interceptor interceptor = new NonBlockingInterceptor(scheduler, next); + interceptor.invoke(msg); + verify(context); + verify(next); + verify(msg); + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/core/src/test/java/org/apache/tuscany/sca/scope/ScopeTestCase.java b/tags/java/sca/1.0-RC1b/modules/core/src/test/java/org/apache/tuscany/sca/scope/ScopeTestCase.java new file mode 100644 index 0000000000..341d889b7d --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/databinding-axiom/.ruleset b/tags/java/sca/1.0-RC1b/modules/databinding-axiom/.ruleset new file mode 100644 index 0000000000..27b9ab847c --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-axiom/.ruleset @@ -0,0 +1,191 @@ + + + + + PMD Plugin preferences rule set + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-axiom/DISCLAIMER b/tags/java/sca/1.0-RC1b/modules/databinding-axiom/DISCLAIMER new file mode 100644 index 0000000000..d68a410903 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-axiom/DISCLAIMER @@ -0,0 +1,8 @@ +Apache Tuscany is an effort undergoing incubation at The Apache Software +Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is +required of all newly accepted projects until a further review indicates that +the infrastructure, communications, and decision making process have stabilized +in a manner consistent with other successful ASF projects. While incubation +status is not necessarily a reflection of the completeness or stability of the +code, it does indicate that the project has yet to be fully endorsed by the ASF. + diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-axiom/LICENSE b/tags/java/sca/1.0-RC1b/modules/databinding-axiom/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/databinding-axiom/NOTICE b/tags/java/sca/1.0-RC1b/modules/databinding-axiom/NOTICE new file mode 100644 index 0000000000..94481d6cfa --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-axiom/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2007 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-axiom/pom.xml b/tags/java/sca/1.0-RC1b/modules/databinding-axiom/pom.xml new file mode 100755 index 0000000000..9f77b8cc9a --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-axiom/pom.xml @@ -0,0 +1,91 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.0-incubating + ../pom.xml + + tuscany-databinding-axiom + Apache Tuscany SCA Data Binding for Axiom + + + + org.apache.tuscany.sca + tuscany-core-spi + 1.0-incubating + + + org.apache.tuscany.sca + tuscany-databinding + 1.0-incubating + + + + stax + stax-api + 1.0.1 + + + + org.apache.ws.commons.axiom + axiom-api + + + xerces + xercesImpl + + + 1.2.5 + + + + xerces + xercesImpl + 2.8.1 + runtime + + + + org.apache.ws.commons.axiom + axiom-impl + 1.2.5 + runtime + + + + commons-logging + commons-logging + 1.1 + runtime + + + + org.codehaus.woodstox + wstx-asl + 3.2.1 + runtime + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/AxiomDataBinding.java b/tags/java/sca/1.0-RC1b/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/AxiomDataBinding.java new file mode 100644 index 0000000000..dd90b079d0 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/AxiomDataBinding.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.axiom; + +import org.apache.axiom.om.OMElement; +import org.apache.tuscany.sca.databinding.ExceptionHandler; +import org.apache.tuscany.sca.databinding.WrapperHandler; +import org.apache.tuscany.sca.databinding.impl.BaseDataBinding; + +/** + * DataBinding for AXIOM + */ +public class AxiomDataBinding extends BaseDataBinding { + + public static final String NAME = OMElement.class.getName(); + public static final String[] ALIASES = new String[] {"axiom"}; + + public AxiomDataBinding() { + super(NAME, ALIASES, OMElement.class); + } + + /** + * @see org.apache.tuscany.sca.databinding.impl.BaseDataBinding#getWrapperHandler() + */ + @Override + public WrapperHandler getWrapperHandler() { + return new OMElementWrapperHandler(); + } + + @Override + public Object copy(Object source) { + 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); + } + + @Override + public ExceptionHandler getExceptionHandler() { + return new AxiomExceptionHandler(); + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/AxiomExceptionHandler.java b/tags/java/sca/1.0-RC1b/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/AxiomExceptionHandler.java new file mode 100644 index 0000000000..fccf6c530d --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/AxiomExceptionHandler.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.axiom; + +import org.apache.axiom.om.OMElement; +import org.apache.tuscany.sca.databinding.ExceptionHandler; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; +import org.apache.tuscany.sca.interfacedef.util.FaultException; +import org.apache.tuscany.sca.interfacedef.util.XMLType; + +/** + * AXIOM implementation of ExceptionHandler + * + * @version $Rev$ $Date$ + */ +public class AxiomExceptionHandler implements ExceptionHandler { + + public Exception createException(DataType exceptionType, String message, Object faultInfo, Throwable cause) { + return new FaultException(message, faultInfo, cause); + } + + public Object getFaultInfo(Exception exception) { + if (exception == null) { + return null; + } + FaultException faultException = (FaultException)exception; + return faultException.getFaultInfo(); + + } + + public DataType getFaultType(DataType exceptionType) { + if (FaultException.class == exceptionType.getPhysical()) { + XMLType type = XMLType.UNKNOWN; + if(exceptionType.getLogical() instanceof XMLType) { + type = (XMLType) exceptionType.getLogical(); + } + DataType faultType = new DataTypeImpl(AxiomDataBinding.NAME, OMElement.class, type); + return faultType; + } else { + return null; + } + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/AxiomHelper.java b/tags/java/sca/1.0-RC1b/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/AxiomHelper.java new file mode 100644 index 0000000000..f120d66b0d --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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 expection 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/tags/java/sca/1.0-RC1b/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/OMElement2Object.java b/tags/java/sca/1.0-RC1b/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/OMElement2Object.java new file mode 100644 index 0000000000..c119e55dc5 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/OMElement2Object.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.databinding.axiom; + +import org.apache.axiom.om.OMElement; +import org.apache.tuscany.sca.databinding.impl.SimpleType2JavaTransformer; + +/** + * Transformer to convert data from a simple java bject to OMElement + */ +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/tags/java/sca/1.0-RC1b/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/OMElement2String.java b/tags/java/sca/1.0-RC1b/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/OMElement2String.java new file mode 100755 index 0000000000..f5c657e29d --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/OMElement2String.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 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 + */ +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 + public Class getSourceType() { + return OMElement.class; + } + + @Override + public Class getTargetType() { + return String.class; + } + + @Override + public int getWeight() { + return 40; + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/OMElement2XMLStreamReader.java b/tags/java/sca/1.0-RC1b/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/OMElement2XMLStreamReader.java new file mode 100755 index 0000000000..c1c94a1828 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/OMElement2XMLStreamReader.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 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; + +public class OMElement2XMLStreamReader extends BaseTransformer implements PullTransformer { + // private XmlOptions options; + + public XMLStreamReader transform(OMElement source, TransformationContext context) { + return source.getXMLStreamReader(); + } + + @Override + public Class getSourceType() { + return OMElement.class; + } + + @Override + public Class getTargetType() { + return XMLStreamReader.class; + } + + @Override + public int getWeight() { + return 10; + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/OMElementWrapperHandler.java b/tags/java/sca/1.0-RC1b/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/OMElementWrapperHandler.java new file mode 100644 index 0000000000..9123c38dff --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/OMElementWrapperHandler.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.axiom; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Set; + +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.WrapperHandler; +import org.apache.tuscany.sca.interfacedef.DataType; +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.XMLType; + +/** + * OMElement wrapper handler implementation + */ +public class OMElementWrapperHandler implements WrapperHandler { + + private OMFactory factory; + + public OMElementWrapperHandler() { + super(); + this.factory = OMAbstractFactory.getOMFactory(); + } + + public OMElement create(ElementInfo element, TransformationContext context) { + OMElement wrapper = AxiomHelper.createOMElement(factory, element.getQName()); + return wrapper; + } + + public void setChild(OMElement wrapper, int i, ElementInfo childElement, Object value) { + OMElement element = (OMElement)value; + QName elementName = childElement.getQName(); + OMNamespace namespace = factory.createOMNamespace(elementName.getNamespaceURI(), elementName.getPrefix()); + element.setNamespace(namespace); + element.setLocalName(childElement.getQName().getLocalPart()); + wrapper.addChild((OMElement)value); + } + + public List getChildren(OMElement wrapper, List childElements, TransformationContext context) { + List elements = new ArrayList(); + int i = 0; + for (ElementInfo e : childElements) { + elements.add(getChild(wrapper, e, i, context)); + i++; + } + return elements; + } + + /** + * @see org.apache.tuscany.sca.databinding.WrapperHandler#getWrapperType(org.apache.tuscany.sca.interfacedef.util.ElementInfo, List, org.apache.tuscany.sca.databinding.TransformationContext) + */ + public DataType getWrapperType(ElementInfo element, List childElements, TransformationContext context) { + DataType wrapperType = + new DataTypeImpl(AxiomDataBinding.NAME, OMElement.class, new XMLType(element)); + return wrapperType; + } + + public boolean isInstance(Object wrapperObj, + ElementInfo element, + List childElements, + TransformationContext context) { + OMElement wrapper = (OMElement)wrapperObj; + if (!element.getQName().equals(wrapper.getQName())) { + return false; + } + 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"); + + public Object getChild(OMElement wrapper, ElementInfo childElement, int index, TransformationContext context) { + int pos = 0; + for (Iterator i = wrapper.getChildElements(); i.hasNext();) { + OMElement e = (OMElement)i.next(); + if (pos == index) { + TypeInfo type = childElement.getType(); + if (type != null) { + OMAttribute attr = e.getAttribute(XSI_TYPE_QNAME); + if (attr == null) { + OMNamespace ns = + e.getOMFactory().createOMNamespace(type.getQName().getNamespaceURI(), "_typens_"); + e.declareNamespace(ns); + OMNamespace xsiNS = + e.getOMFactory().createOMNamespace(XSI_TYPE_QNAME.getNamespaceURI(), + XSI_TYPE_QNAME.getPrefix()); + e.declareNamespace(xsiNS); + attr = + e.getOMFactory().createOMAttribute("type", + xsiNS, + "_typens_:" + type.getQName().getLocalPart()); + e.addAttribute(attr); + } + } + return e; + } + pos++; + } + return null; + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/Object2OMElement.java b/tags/java/sca/1.0-RC1b/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/Object2OMElement.java new file mode 100644 index 0000000000..f7ccb13e6e --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/Object2OMElement.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.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 + */ +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/tags/java/sca/1.0-RC1b/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/String2OMElement.java b/tags/java/sca/1.0-RC1b/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/String2OMElement.java new file mode 100755 index 0000000000..224c956fcb --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/String2OMElement.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.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; + +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 + public Class getTargetType() { + return OMElement.class; + } + + @Override + public Class getSourceType() { + return String.class; + } + + @Override + public int getWeight() { + return 40; + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/XMLStreamReader2OMElement.java b/tags/java/sca/1.0-RC1b/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/XMLStreamReader2OMElement.java new file mode 100755 index 0000000000..0b3bc7a414 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/XMLStreamReader2OMElement.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.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; + +public class XMLStreamReader2OMElement extends BaseTransformer implements + PullTransformer { + + public XMLStreamReader2OMElement() { + super(); + } + + public OMElement transform(XMLStreamReader source, TransformationContext context) { + try { + StAXOMBuilder builder = new StAXOMBuilder(source); + OMElement element = builder.getDocumentElement(); + AxiomHelper.adjustElementName(context, element); + return element; + } catch (Exception e) { + throw new TransformationException(e); + } + } + + @Override + public Class getTargetType() { + return OMElement.class; + } + + @Override + public Class getSourceType() { + return XMLStreamReader.class; + } + + @Override + public int getWeight() { + return 10; + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-axiom/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.DataBinding b/tags/java/sca/1.0-RC1b/modules/databinding-axiom/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.DataBinding new file mode 100644 index 0000000000..2e94116177 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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;type=org.apache.axiom.om.OMElement,name=axiom + diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-axiom/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer b/tags/java/sca/1.0-RC1b/modules/databinding-axiom/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer new file mode 100644 index 0000000000..78f1a80c37 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-axiom/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer @@ -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 classes for the transformers +org.apache.tuscany.sca.databinding.axiom.Object2OMElement;source=java:simpleType,target=org.apache.axiom.om.OMElement,weight=10000 +org.apache.tuscany.sca.databinding.axiom.OMElement2Object;source=org.apache.axiom.om.OMElement,target=java:simpleType,weight=10000 +org.apache.tuscany.sca.databinding.axiom.OMElement2String;source=org.apache.axiom.om.OMElement,target=java.lang.String,weight=40 +org.apache.tuscany.sca.databinding.axiom.OMElement2XMLStreamReader;source=org.apache.axiom.om.OMElement,target=javax.xml.stream.XMLStreamReader,weight=10 +org.apache.tuscany.sca.databinding.axiom.String2OMElement;source=java.lang.String,target=org.apache.axiom.om.OMElement,weight=40 +org.apache.tuscany.sca.databinding.axiom.XMLStreamReader2OMElement;source=javax.xml.stream.XMLStreamReader,target=org.apache.axiom.om.OMElement,weight=10 diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-axiom/src/test/java/org/apache/tuscany/sca/databinding/axiom/AxiomExceptionHandlerTestCase.java b/tags/java/sca/1.0-RC1b/modules/databinding-axiom/src/test/java/org/apache/tuscany/sca/databinding/axiom/AxiomExceptionHandlerTestCase.java new file mode 100644 index 0000000000..d553772d7e --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-axiom/src/test/java/org/apache/tuscany/sca/databinding/axiom/AxiomExceptionHandlerTestCase.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.axiom; + +import java.io.StringReader; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamReader; + +import junit.framework.TestCase; + +import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.impl.builder.StAXOMBuilder; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; +import org.apache.tuscany.sca.interfacedef.util.FaultException; +import org.apache.tuscany.sca.interfacedef.util.XMLType; + +/** + * Test case for SDOExceptionHandler + */ +public class AxiomExceptionHandlerTestCase 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 AxiomExceptionHandler handler; + private OMElement faultElement; + + /** + * @see junit.framework.TestCase#setUp() + */ + @Override + protected void setUp() throws Exception { + super.setUp(); + this.handler = new AxiomExceptionHandler(); + XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(new StringReader(IPO_XML)); + StAXOMBuilder builder = new StAXOMBuilder(reader); + faultElement = builder.getDocumentElement(); + } + + public void testGetFaultType() { + DataType dataType = handler.getFaultType(new DataTypeImpl(FaultException.class, null)); + assertEquals(OMElement.class, dataType.getPhysical()); + assertEquals(XMLType.UNKNOWN, dataType.getLogical()); + assertEquals(AxiomDataBinding.NAME, dataType.getDataBinding()); + dataType = handler.getFaultType(new DataTypeImpl(Exception.class, null)); + assertNull(dataType); + } + + public void testCreate() { + + Exception ex = handler.createException(null, "Order", faultElement, null); + assertTrue(ex instanceof FaultException); + FaultException exception = (FaultException)ex; + assertEquals("Order", exception.getMessage()); + assertSame(faultElement, exception.getFaultInfo()); + } + + public void testGetFaultInfo() { + FaultException exception = new FaultException("Order", faultElement, null); + Object faultInfo = handler.getFaultInfo(exception); + assertSame(faultElement, faultInfo); + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-axiom/src/test/java/org/apache/tuscany/sca/databinding/axiom/OMElementTestCase.java b/tags/java/sca/1.0-RC1b/modules/databinding-axiom/src/test/java/org/apache/tuscany/sca/databinding/axiom/OMElementTestCase.java new file mode 100755 index 0000000000..661fb72905 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-axiom/src/test/java/org/apache/tuscany/sca/databinding/axiom/OMElementTestCase.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.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; + +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); + assertNotSame(element, copy); + assertEquals(new QName("http://www.example.com/IPO", "purchaseOrder"), copy.getQName()); + } + + private final static 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/tags/java/sca/1.0-RC1b/modules/databinding-axiom/src/test/resources/ipo.xml b/tags/java/sca/1.0-RC1b/modules/databinding-axiom/src/test/resources/ipo.xml new file mode 100755 index 0000000000..df901d183d --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/databinding-axiom/src/test/resources/ipo.xsd b/tags/java/sca/1.0-RC1b/modules/databinding-axiom/src/test/resources/ipo.xsd new file mode 100755 index 0000000000..af1e73172d --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/databinding-axiom/src/test/resources/order.wsdl b/tags/java/sca/1.0-RC1b/modules/databinding-axiom/src/test/resources/order.wsdl new file mode 100644 index 0000000000..a5ead60382 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-axiom/src/test/resources/order.wsdl @@ -0,0 +1,76 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-jaxb/.ruleset b/tags/java/sca/1.0-RC1b/modules/databinding-jaxb/.ruleset new file mode 100644 index 0000000000..27b9ab847c --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-jaxb/.ruleset @@ -0,0 +1,191 @@ + + + + + PMD Plugin preferences rule set + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-jaxb/DISCLAIMER b/tags/java/sca/1.0-RC1b/modules/databinding-jaxb/DISCLAIMER new file mode 100644 index 0000000000..d68a410903 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-jaxb/DISCLAIMER @@ -0,0 +1,8 @@ +Apache Tuscany is an effort undergoing incubation at The Apache Software +Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is +required of all newly accepted projects until a further review indicates that +the infrastructure, communications, and decision making process have stabilized +in a manner consistent with other successful ASF projects. While incubation +status is not necessarily a reflection of the completeness or stability of the +code, it does indicate that the project has yet to be fully endorsed by the ASF. + diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-jaxb/LICENSE b/tags/java/sca/1.0-RC1b/modules/databinding-jaxb/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/databinding-jaxb/NOTICE b/tags/java/sca/1.0-RC1b/modules/databinding-jaxb/NOTICE new file mode 100644 index 0000000000..94481d6cfa --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-jaxb/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2007 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-jaxb/pom.xml b/tags/java/sca/1.0-RC1b/modules/databinding-jaxb/pom.xml new file mode 100755 index 0000000000..ccae213380 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-jaxb/pom.xml @@ -0,0 +1,155 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.0-incubating + ../pom.xml + + tuscany-databinding-jaxb + Apache Tuscany SCA Data Binding for JAXB + + + + org.apache.tuscany.sca + tuscany-core-spi + 1.0-incubating + + + org.apache.tuscany.sca + tuscany-databinding + 1.0-incubating + + + org.apache.tuscany.sca + tuscany-interface-java-xml + 1.0-incubating + + + javax.xml.bind + jaxb-api + 2.1 + + + + javax.xml.ws + jaxws-api + + 2.1 + + + + com.sun.xml.bind + jaxb-impl + 2.1.4 + runtime + + + + javax.xml.bind + jsr173_api + + + + + + + + + + true + + java.net + java.net Maven 1.x Repository + http://download.java.net/maven/1 + legacy + + + + + + + true + + java.net + java.net Maven 1.x Repository + http://download.java.net/maven/1 + legacy + + + + + + + org.codehaus.mojo + build-helper-maven-plugin + 1.0 + + + add-test-source + generate-sources + + add-test-source + + + + target/jaxb-source + + + + + + + + com.sun.tools.xjc.maven2 + maven-jaxb-plugin + 1.1 + + + generate-jaxb + generate-test-sources + + generate + + + + + com.example.ipo.jaxb + ${project.build.directory}/jaxb-source + ${basedir}/src/test/resources + + ipo.xsd + + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXB2Node.java b/tags/java/sca/1.0-RC1b/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXB2Node.java new file mode 100755 index 0000000000..6e0f03951b --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXB2Node.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.jaxb; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBElement; +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; + +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(); + JAXBElement jaxbElement = JAXBContextHelper.createJAXBElement(tContext.getSourceDataType(), source); + marshaller.marshal(jaxbElement, document); + return document; + } catch (Exception e) { + throw new TransformationException(e); + } + } + + @Override + public Class getSourceType() { + return Object.class; + } + + @Override + public Class getTargetType() { + return Node.class; + } + + @Override + public int getWeight() { + return 30; + } + + @Override + public String getSourceDataBinding() { + return JAXBDataBinding.NAME; + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextHelper.java b/tags/java/sca/1.0-RC1b/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextHelper.java new file mode 100644 index 0000000000..54e51cd97c --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextHelper.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.jaxb; + +import java.beans.Introspector; +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBElement; +import javax.xml.bind.JAXBException; +import javax.xml.bind.annotation.XmlEnum; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlSchema; +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.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.util.XMLType; + +public class JAXBContextHelper { + // TODO: Do we need to set them for source and target? + public static final String JAXB_CLASSES = "jaxb.classes"; + + public static final String JAXB_CONTEXT_PATH = "jaxb.contextPath"; + + private JAXBContextHelper() { + } + + public static JAXBContext createJAXBContext(TransformationContext tContext, boolean source) throws JAXBException { + if (tContext == null) + throw new TransformationException("JAXB context is not set for the transformation."); + + DataType bindingContext = source ? tContext.getSourceDataType() : tContext.getTargetDataType(); + // FIXME: We should check the context path or classes + // FIXME: What should we do if JAXB is an intermediate node? + + String contextPath = null; + JAXBContext context = null; + Class cls = bindingContext.getPhysical(); + if (cls.getPackage() != null) { + contextPath = cls.getPackage().getName(); + context = JAXBContext.newInstance(contextPath); + } + if (context == null) { + throw new TransformationException("JAXB context is not set for the transformation."); + } + return context; + } + + @SuppressWarnings("unchecked") + public static JAXBElement createJAXBElement(DataType dataType, Object value) { + if (value instanceof JAXBElement) { + return (JAXBElement)value; + } else { + Class type = dataType.getPhysical(); + Object logical = dataType.getLogical(); + QName elementName = JAXBDataBinding.ROOT_ELEMENT; + if (logical instanceof XMLType) { + XMLType xmlType = (XMLType)logical; + QName element = xmlType.getElementName(); + if (element != null) { + elementName = element; + } else { + /** + * Set the declared type to Object.class so that xsi:type + * will be produced + */ + type = Object.class; + } + } else { + type = Object.class; + } + return new JAXBElement(elementName, type, value); + } + } + + @SuppressWarnings("unchecked") + public static Object createReturnValue(DataType dataType, Object value) { + Class cls = getJavaType(dataType); + if (cls == JAXBElement.class) { + return createJAXBElement(dataType, value); + } else { + if (value instanceof JAXBElement) { + return ((JAXBElement)value).getValue(); + } else { + return value; + } + } + } + + public static Class getJavaType(DataType dataType) { + if (dataType == null) { + return null; + } + Type type = dataType.getPhysical(); + if (type instanceof Class) { + Class cls = (Class)type; + if (JAXBElement.class.isAssignableFrom(cls)) { + return null; + } else { + return cls; + } + } else if (type instanceof ParameterizedType) { + ParameterizedType pType = (ParameterizedType)type; + return (Class)pType.getRawType(); + } + return null; + } + + public static XMLType getXmlTypeName(Class javaType) { + 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(); + } + } + XmlType type = javaType.getAnnotation(XmlType.class); + if (type != null) { + String typeNamespace = type.namespace(); + String typeName = type.name(); + + if (typeNamespace.equals("##default") && typeName.equals("")) { + XmlRootElement rootElement = javaType.getAnnotation(XmlRootElement.class); + if (rootElement != null) { + namespace = rootElement.namespace(); + } else { + // FIXME: The namespace should be from the referencing + // property + namespace = null; + } + } else if (typeNamespace.equals("##default")) { + // namespace is from the package + } else { + namespace = typeNamespace; + } + + if (typeName.equals("##default")) { + name = Introspector.decapitalize(javaType.getSimpleName()); + } else { + name = typeName; + } + } else { + XmlEnum xmlEnum = javaType.getAnnotation(XmlEnum.class); + if (xmlEnum != null) { + name = Introspector.decapitalize(javaType.getSimpleName()); + } + } + if (name == null) { + return null; + } + return new XMLType(null, new QName(namespace, name)); + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBDataBinding.java b/tags/java/sca/1.0-RC1b/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBDataBinding.java new file mode 100644 index 0000000000..9706ffdc21 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBDataBinding.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.jaxb; + +import java.lang.annotation.Annotation; +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.ExceptionHandler; +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.util.XMLType; +import org.w3c.dom.Document; + +/** + * JAXB DataBinding + */ +public class JAXBDataBinding extends BaseDataBinding { + public static final String NAME = JAXBElement.class.getName(); + public static final String[] ALIASES = new String[] {"jaxb"}; + + 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"); + + public JAXBDataBinding() { + super(NAME, ALIASES, JAXBElement.class); + } + + @Override + public boolean introspect(DataType dataType, Annotation[] annotations) { + Object physical = dataType.getPhysical(); + if (!(physical instanceof Class)) { + return false; + } + Class javaType = (Class)physical; + 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(getName()); + return true; + } + } + } + dataType.setLogical(XMLType.UNKNOWN); + dataType.setDataBinding(getName()); + return true; + } + + XMLType xmlType = JAXBContextHelper.getXmlTypeName(javaType); + if (xmlType == null) { + return false; + } + dataType.setLogical(xmlType); + dataType.setDataBinding(getName()); + return true; + } + + @SuppressWarnings("unchecked") + @Override + public Object copy(Object arg) { + try { + boolean isElement = false; + Class cls = arg.getClass(); + if (arg instanceof JAXBElement) { + isElement = true; + cls = ((JAXBElement)arg).getDeclaredType(); + } else { + arg = new JAXBElement(ROOT_ELEMENT, Object.class, arg); + } + JAXBContext context = JAXBContext.newInstance(cls); + Document doc = DOMHelper.newDocument(); + context.createMarshaller().marshal(arg, doc); + JAXBElement element = context.createUnmarshaller().unmarshal(doc, cls); + return isElement ? element : element.getValue(); + } catch (Exception e) { + throw new IllegalArgumentException(e); + } + } + + @Override + public ExceptionHandler getExceptionHandler() { + return new JAXBExceptionHandler(); + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBExceptionHandler.java b/tags/java/sca/1.0-RC1b/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBExceptionHandler.java new file mode 100644 index 0000000000..aa37031c04 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBExceptionHandler.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.databinding.jaxb; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Method; + +import javax.xml.namespace.QName; +import javax.xml.ws.WebFault; + +import org.apache.tuscany.sca.databinding.ExceptionHandler; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; +import org.apache.tuscany.sca.interfacedef.util.XMLType; + +/** + * JAXB implementation of ExceptionHandler + * + * @version $Rev$ $Date$ + */ +public class JAXBExceptionHandler implements ExceptionHandler { + private static final Class[] EMPTY_CLASS_ARRAY = new Class[0]; + + /** + *
    + *
  • WrapperException(String message, FaultBean faultInfo)
    + * A constructor where WrapperException is replaced with the name of the + * generated wrapper exception and FaultBean is replaced by the name of the + * generated fault bean. + *
  • WrapperException(String message, FaultBean faultInfo, Throwable + * cause)
    + * A constructor whereWrapperException is replaced with the name of the + * generated wrapper exception and FaultBean is replaced by the name of the + * generated fault bean. The last argument, cause, may be used to convey + * protocol specific fault information + *
+ */ + public Exception createException(DataType exceptionType, String message, Object faultInfo, Throwable cause) { + Class exceptionClass = exceptionType.getPhysical(); + DataType faultBeanType = exceptionType.getLogical(); + Class faultBeanClass = faultBeanType.getPhysical(); + try { + Constructor constructor = + exceptionClass.getConstructor(new Class[] {String.class, faultBeanClass, Throwable.class}); + return (Exception)constructor.newInstance(new Object[] {message, faultInfo, cause}); + } catch (Throwable e) { + throw new IllegalArgumentException(e); + } + } + + public Object getFaultInfo(Exception exception) { + if (exception == null) { + return null; + } + try { + Method method = exception.getClass().getMethod("getFaultInfo", EMPTY_CLASS_ARRAY); + return method.invoke(exception, (Object[])null); + } catch (Throwable e) { + throw new IllegalArgumentException(e); + } + } + + public DataType getFaultType(DataType exDataType) { + Class exceptionType = exDataType.getPhysical(); + WebFault webFault = exceptionType.getAnnotation(WebFault.class); + if (webFault == null) { + return null; + } else { + QName element = new QName(webFault.targetNamespace(), webFault.name()); + // TODO: Need to determine the fault bean class + // String faultBean = webFault.faultBean(); + Class faultBeanClass = null; + try { + Method method = exceptionType.getMethod("getFaultInfo", EMPTY_CLASS_ARRAY); + faultBeanClass = method.getReturnType(); + } catch (NoSuchMethodException e) { + faultBeanClass = null; + } + // The logical type of a fault is the QName of the element that the + // only part in + // the fault message references + DataType faultType = + new DataTypeImpl(JAXBDataBinding.NAME, faultBeanClass, new XMLType(element, null)); + // faultType.setMetadata(ElementInfo.class.getName(), new + // ElementInfo(element, null)); + return faultType; + } + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBWrapperHandler.java b/tags/java/sca/1.0-RC1b/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBWrapperHandler.java new file mode 100644 index 0000000000..c3e97a4818 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBWrapperHandler.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 java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.List; + +import javax.xml.bind.JAXBElement; +import javax.xml.bind.annotation.XmlElementDecl; +import javax.xml.bind.annotation.XmlRegistry; +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.WrapperHandler; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; +import org.apache.tuscany.sca.interfacedef.util.ElementInfo; +import org.apache.tuscany.sca.interfacedef.util.XMLType; + +/** + * JAXB WrapperHandler implementation + */ +public class JAXBWrapperHandler implements WrapperHandler> { + + public JAXBElement create(ElementInfo element, TransformationContext context) { + try { + // FIXME: How do we map the global element to a factory? + String packageName = null; + String factoryClassName = packageName + ".ObjectFactory"; + ClassLoader classLoader = context != null ? context.getClassLoader() : null; + if (classLoader == null) { + //FIXME Understand why we need this, the classloader should be passed in + classLoader = Thread.currentThread().getContextClassLoader(); + } + Class factoryClass = Class.forName(factoryClassName, true, classLoader); + assert factoryClass.isAnnotationPresent(XmlRegistry.class); + Object factory = factoryClass.newInstance(); + QName elementName = element.getQName(); + Method method = null; + for (Method m : factoryClass.getMethods()) { + XmlElementDecl xmlElement = m.getAnnotation(XmlElementDecl.class); + QName name = new QName(xmlElement.namespace(), xmlElement.name()); + if (xmlElement != null && name.equals(elementName)) { + method = m; + break; + } + } + if (method != null) { + Class typeClass = method.getParameterTypes()[0]; + Object value = typeClass.newInstance(); + return (JAXBElement)method.invoke(factory, new Object[] {value}); + } else { + throw new TransformationException("ObjectFactory cannot be resolved."); + } + } catch (Exception e) { + throw new TransformationException(e); + } + } + + public void setChild(JAXBElement wrapper, int i, ElementInfo childElement, Object value) { + Object wrapperValue = wrapper.getValue(); + Class wrapperClass = wrapperValue.getClass(); + + XmlType xmlType = wrapperClass.getAnnotation(XmlType.class); + String[] properties = xmlType.propOrder(); + String property = properties[i]; + + try { + for (Method m : wrapperClass.getMethods()) { + if (m.getName().equals("set" + capitalize(property))) { + m.invoke(wrapperValue, new Object[] {value}); + return; + } + } + } 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, List, TransformationContext) + */ + public List getChildren(JAXBElement wrapper, List childElements, TransformationContext context) { + Object wrapperValue = wrapper.getValue(); + Class wrapperClass = wrapperValue.getClass(); + + XmlType xmlType = wrapperClass.getAnnotation(XmlType.class); + String[] properties = xmlType.propOrder(); + List elements = new ArrayList(); + for (String p : properties) { + try { + Method method = wrapperClass.getMethod("get" + capitalize(p), (Class[])null); + Object value = method.invoke(wrapperValue, (Object[])null); + elements.add(value); + } catch (Throwable e) { + throw new TransformationException(e); + } + } + return elements; + } + + /** + * @see org.apache.tuscany.sca.databinding.WrapperHandler#getWrapperType(org.apache.tuscany.sca.interfacedef.util.ElementInfo, List, org.apache.tuscany.sca.databinding.TransformationContext) + */ + public DataType getWrapperType(ElementInfo element, List childElements, TransformationContext context) { + try { + // FIXME: How do we map the global element to a factory? + String packageName = null; + String factoryClassName = packageName + ".ObjectFactory"; + ClassLoader classLoader = context != null ? context.getClassLoader() : null; + if (classLoader == null) { + //FIXME Understand why we need this, the classloader should be passed in + classLoader = Thread.currentThread().getContextClassLoader(); + } + Class factoryClass = Class.forName(factoryClassName, true, classLoader); + assert factoryClass.isAnnotationPresent(XmlRegistry.class); + QName elementName = element.getQName(); + Method method = null; + for (Method m : factoryClass.getMethods()) { + XmlElementDecl xmlElement = m.getAnnotation(XmlElementDecl.class); + QName name = new QName(xmlElement.namespace(), xmlElement.name()); + if (xmlElement != null && name.equals(elementName)) { + method = m; + break; + } + } + if (method != null) { + Class typeClass = method.getParameterTypes()[0]; + DataType wrapperType = + new DataTypeImpl(JAXBDataBinding.NAME, typeClass, new XMLType(element)); + return wrapperType; + } + + return null; + } catch (Throwable e) { + return null; + } + } + + /** + * @see org.apache.tuscany.sca.databinding.WrapperHandler#isInstance(java.lang.Object, org.apache.tuscany.sca.interfacedef.util.ElementInfo, java.util.List, org.apache.tuscany.sca.databinding.TransformationContext) + */ + public boolean isInstance(Object wrapper, + ElementInfo element, + List childElements, + TransformationContext context) { + // TODO: Implement the logic + return true; + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXWSJavaInterfaceProcessor.java b/tags/java/sca/1.0-RC1b/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXWSJavaInterfaceProcessor.java new file mode 100644 index 0000000000..b5ac3fb47f --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXWSJavaInterfaceProcessor.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.databinding.jaxb; + +import java.lang.reflect.Method; +import java.util.HashMap; +import java.util.Map; + +import javax.jws.WebMethod; +import javax.jws.WebService; + +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; + +/** + * The databinding annotation processor for java interfaces + * + * @version $Rev$ $Date$ + */ +public class JAXWSJavaInterfaceProcessor implements JavaInterfaceVisitor { + + public JAXWSJavaInterfaceProcessor() { + super(); + } + + public void visitInterface(JavaInterface contract) throws InvalidInterfaceException { + + Class clazz = contract.getJavaClass(); + WebService webService = clazz.getAnnotation(WebService.class); + String tns = ""; + if (webService != null) { + tns = webService.targetNamespace(); + // Mark SEI as Remotable + contract.setRemotable(true); + } + if (!contract.isRemotable()) { + return; + } + Map operations = new HashMap(); + for (Operation op : contract.getOperations()) { + operations.put(op.getName(), op); + } + for (Method method : clazz.getMethods()) { + Operation operation = operations.get(method.getName()); + + WebMethod webMethod = method.getAnnotation(WebMethod.class); + if (webMethod == null) { + return; + } + + /* + String operationName = getValue(webMethod.operationName(), operation.getName()); + + RequestWrapper requestWrapper = method.getAnnotation(RequestWrapper.class); + ResponseWrapper responseWrapper = method.getAnnotation(ResponseWrapper.class); + if (requestWrapper == null) { + return; + } + + String ns = getValue(requestWrapper.targetNamespace(), tns); + String name = getValue(requestWrapper.localName(), operationName); + QName inputWrapper = new QName(ns, name); + + ns = getValue(responseWrapper.targetNamespace(), tns); + name = getValue(responseWrapper.localName(), operationName + "Response"); + + QName outputWrapper = new QName(ns, name); + + List inputElements = new ArrayList(); + for (Annotation[] annotations : method.getParameterAnnotations()) { + for (Annotation annotation : annotations) { + if (annotation.annotationType() == WebParam.class) { + WebParam param = (WebParam)annotation; + inputElements.add(new ElementInfo(new QName(param.targetNamespace(), param.name()), null)); + break; + } + } + } + + List outputElements = new ArrayList(); + WebResult result = method.getAnnotation(WebResult.class); + outputElements.add(new ElementInfo(new QName(result.targetNamespace(), result.name()), null)); + + WrapperInfo wrapperInfo = + new WrapperInfo(JAXBDataBinding.NAME, new ElementInfo(inputWrapper, null), + new ElementInfo(outputWrapper, null), inputElements, outputElements); + operation.setWrapper(wrapperInfo); + */ + operation.setWrapperStyle(false); + operation.setDataBinding(JAXBDataBinding.NAME); + } + } + + private static String getValue(String value, String defaultValue) { + return "".equals(value) ? defaultValue : value; + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/Node2JAXB.java b/tags/java/sca/1.0-RC1b/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/Node2JAXB.java new file mode 100755 index 0000000000..1490183edb --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/Node2JAXB.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.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; + +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); + return JAXBContextHelper.createReturnValue(context.getTargetDataType(), result); + } catch (Exception e) { + throw new TransformationException(e); + } + } + + @Override + public Class getSourceType() { + return Node.class; + } + + @Override + public Class getTargetType() { + return Object.class; + } + + @Override + public int getWeight() { + return 30; + } + + @Override + public String getTargetDataBinding() { + return JAXBDataBinding.NAME; + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/Reader2JAXB.java b/tags/java/sca/1.0-RC1b/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/Reader2JAXB.java new file mode 100644 index 0000000000..c4aab8a898 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/Reader2JAXB.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 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; + +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); + return JAXBContextHelper.createReturnValue(context.getTargetDataType(), result); + } catch (Exception e) { + throw new TransformationException(e); + } + } + + @Override + public Class getSourceType() { + return Reader.class; + } + + @Override + public Class getTargetType() { + return Object.class; + } + + @Override + public int getWeight() { + return 30; + } + + @Override + public String getTargetDataBinding() { + return JAXBDataBinding.NAME; + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/XMLStreamReader2JAXB.java b/tags/java/sca/1.0-RC1b/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/XMLStreamReader2JAXB.java new file mode 100755 index 0000000000..d74a777fa1 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/XMLStreamReader2JAXB.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.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; + +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(); + Object result = unmarshaller.unmarshal(source); + source.close(); + return JAXBContextHelper.createReturnValue(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/tags/java/sca/1.0-RC1b/modules/databinding-jaxb/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.DataBinding b/tags/java/sca/1.0-RC1b/modules/databinding-jaxb/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.DataBinding new file mode 100644 index 0000000000..58d6123373 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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;type=javax.xml.bind.JAXBElement,name=jaxb diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-jaxb/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer b/tags/java/sca/1.0-RC1b/modules/databinding-jaxb/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer new file mode 100644 index 0000000000..d3efc9e0d7 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-jaxb/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.jaxb.JAXB2Node;source=javax.xml.bind.JAXBElement,target=org.w3c.dom.Node,weight=30 +org.apache.tuscany.sca.databinding.jaxb.Node2JAXB;source=org.w3c.dom.Node,target=javax.xml.bind.JAXBElement,weight=30 +org.apache.tuscany.sca.databinding.jaxb.Reader2JAXB;source=java.io.Reader,target=javax.xml.bind.JAXBElement,weight=30 +org.apache.tuscany.sca.databinding.jaxb.XMLStreamReader2JAXB;source=javax.xml.stream.XMLStreamReader,target=javax.xml.bind.JAXBElement,weight=10 \ No newline at end of file diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-jaxb/src/main/resources/META-INF/services/org.apache.tuscany.sca.interfacedef.java.introspect.JavaInterfaceVisitor b/tags/java/sca/1.0-RC1b/modules/databinding-jaxb/src/main/resources/META-INF/services/org.apache.tuscany.sca.interfacedef.java.introspect.JavaInterfaceVisitor new file mode 100644 index 0000000000..28ce24b63a --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-jaxb/src/main/resources/META-INF/services/org.apache.tuscany.sca.interfacedef.java.introspect.JavaInterfaceVisitor @@ -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.jaxb.JAXWSJavaInterfaceProcessor diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBDataBindingTestCase.java b/tags/java/sca/1.0-RC1b/modules/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBDataBindingTestCase.java new file mode 100644 index 0000000000..b121e2c99f --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBDataBindingTestCase.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.databinding.jaxb; + +import java.lang.annotation.Annotation; + +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.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; + +/** + * + */ +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, Annotation)}. + */ + public final void testIntrospect() { + DataType dataType = new DataTypeImpl(JAXBElement.class, null); + boolean yes = binding.introspect(dataType, null); + 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, null); + 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, null); + 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, null); + 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); + 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); + 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); + assertTrue(copy instanceof USAddress); + assertEquals("San Jose", (copy).getCity()); + + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBExceptionHandlerTestCase.java b/tags/java/sca/1.0-RC1b/modules/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBExceptionHandlerTestCase.java new file mode 100644 index 0000000000..9cf40ee9a6 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBExceptionHandlerTestCase.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.databinding.jaxb; + +import javax.xml.namespace.QName; + +import junit.framework.TestCase; + +import org.apache.tuscany.databinding.jaxb.fault.InvalidSymbolFault; +import org.apache.tuscany.databinding.jaxb.fault.InvalidSymbolFault_Exception; +import org.apache.tuscany.sca.databinding.jaxb.JAXBDataBinding; +import org.apache.tuscany.sca.databinding.jaxb.JAXBExceptionHandler; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; +import org.apache.tuscany.sca.interfacedef.util.XMLType; + +/** + * Test case for JAXBExceptionHandler + */ +public class JAXBExceptionHandlerTestCase extends TestCase { + private static final QName ELEMENT = new QName("http://www.example.com/stock", "InvalidSymbolFault"); + private JAXBExceptionHandler handler; + + /** + * @see junit.framework.TestCase#setUp() + */ + @Override + protected void setUp() throws Exception { + super.setUp(); + this.handler = new JAXBExceptionHandler(); + } + + public void testGetFaultType() { + DataType exType = new DataTypeImpl(InvalidSymbolFault_Exception.class, XMLType.UNKNOWN); + DataType dataType = handler.getFaultType(exType); + assertEquals(InvalidSymbolFault.class, dataType.getPhysical()); + assertEquals(ELEMENT, ((XMLType) dataType.getLogical()).getElementName()); + assertEquals(JAXBDataBinding.NAME, dataType.getDataBinding()); + } + + public void testCreate() { + DataType execType = new DataTypeImpl(InvalidSymbolFault_Exception.class, XMLType.UNKNOWN); + DataType faultType = handler.getFaultType(execType); + InvalidSymbolFault fault = new InvalidSymbolFault(); + fault.setMessage("ABC"); + fault.setSymbol("IBM0"); + DataType exType = new DataTypeImpl(InvalidSymbolFault_Exception.class, faultType); + Exception ex = handler.createException(exType, "Invalid symbol", fault, null); + assertTrue(ex instanceof InvalidSymbolFault_Exception); + InvalidSymbolFault_Exception exception = (InvalidSymbolFault_Exception)ex; + assertEquals("Invalid symbol", exception.getMessage()); + assertSame(fault, exception.getFaultInfo()); + } + + public void testGetFaultInfo() { + InvalidSymbolFault fault = new InvalidSymbolFault(); + fault.setMessage("ABC"); + fault.setSymbol("IBM0"); + InvalidSymbolFault_Exception exception = new InvalidSymbolFault_Exception("Invalid symbol", fault); + Object faultInfo = handler.getFaultInfo(exception); + assertSame(fault, faultInfo); + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBTestCase.java b/tags/java/sca/1.0-RC1b/modules/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBTestCase.java new file mode 100755 index 0000000000..05f112aff3 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBTestCase.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.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; + +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(); + 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(); + 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(); + 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(); + 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(); + 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/tags/java/sca/1.0-RC1b/modules/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBWrapperHandlerTestCase.java b/tags/java/sca/1.0-RC1b/modules/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBWrapperHandlerTestCase.java new file mode 100644 index 0000000000..563d6232b1 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBWrapperHandlerTestCase.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.databinding.jaxb; + +import java.util.List; + +import javax.xml.bind.JAXBElement; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.databinding.jaxb.JAXBWrapperHandler; + +import com.example.ipo.jaxb.ObjectFactory; +import com.example.ipo.jaxb.PurchaseOrderType; + +/** + * Test case for JAXBExceptionHandler + */ +public class JAXBWrapperHandlerTestCase extends TestCase { + // private static final QName ELEMENT = new QName("http://www.example.com/IPO", "purchaseOrder"); + 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); + // JAXBElement jaxbElement = handler.create(element, null); + } + + public void testSetChild() { + ObjectFactory factory = new ObjectFactory(); + PurchaseOrderType po = factory.createPurchaseOrderType(); + JAXBElement wrapper = factory.createPurchaseOrder(po); + handler.setChild(wrapper, 2, null, "Comment"); + } + + public void testGetChildren() { + ObjectFactory factory = new ObjectFactory(); + PurchaseOrderType po = factory.createPurchaseOrderType(); + po.setComment("Comment"); + JAXBElement wrapper = factory.createPurchaseOrder(po); + List children = handler.getChildren(wrapper, null, null); + assertNotNull(children); + assertEquals(4, children.size()); + assertEquals("Comment", children.get(2)); + assertNull(children.get(0)); + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXWSJavaInterfaceProcessorTestCase.java b/tags/java/sca/1.0-RC1b/modules/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXWSJavaInterfaceProcessorTestCase.java new file mode 100644 index 0000000000..83abdc29f5 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXWSJavaInterfaceProcessorTestCase.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.databinding.jaxb; + +import javax.jws.WebService; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.databinding.jaxb.JAXWSJavaInterfaceProcessor; +import org.apache.tuscany.sca.interfacedef.impl.InterfaceImpl; +import org.apache.tuscany.sca.interfacedef.java.JavaInterface; + +/** + * + */ +public class JAXWSJavaInterfaceProcessorTestCase extends TestCase { + private JAXWSJavaInterfaceProcessor interfaceProcessor; + + /** + * @see junit.framework.TestCase#setUp() + */ + @Override + protected void setUp() throws Exception { + super.setUp(); + interfaceProcessor = new JAXWSJavaInterfaceProcessor(); + } + + /** + * Test method for + * {@link org.apache.tuscany.sca.databinding.jaxb.JAXWSJavaInterfaceProcessor#visitInterface(JavaInterface)}. + */ + public final void testProcessor() throws Exception { + JavaInterface contract = new MockJavaInterfaceImpl(); + contract.setJavaClass(WebServiceInterfaceWithoutAnnotation.class); + + interfaceProcessor.visitInterface(contract); + assertFalse(contract.isRemotable()); + + contract.setJavaClass(WebServiceInterfaceWithAnnotation.class); + interfaceProcessor.visitInterface(contract); + assertTrue(contract.isRemotable()); + } + + @WebService + private static interface WebServiceInterfaceWithAnnotation { + + } + + private static interface WebServiceInterfaceWithoutAnnotation { + + } + + private class MockJavaInterfaceImpl extends InterfaceImpl implements JavaInterface { + private Class javaClass; + + public Class getCallbackClass() { + // TODO Auto-generated method stub + return null; + } + + public Class getJavaClass() { + // TODO Auto-generated method stub + return javaClass; + } + + public String getName() { + // TODO Auto-generated method stub + return null; + } + + public void setCallbackClass(Class callbackClass) { + // TODO Auto-generated method stub + + } + + public void setJavaClass(Class javaClass) { + this.javaClass = javaClass; + } + + public void setName(String className) { + // TODO Auto-generated method stub + + } + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/fault/InvalidSymbolFault.java b/tags/java/sca/1.0-RC1b/modules/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/fault/InvalidSymbolFault.java new file mode 100644 index 0000000000..fd21d72337 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/fault/InvalidSymbolFault.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.databinding.jaxb.fault; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; + +/** + *

+ * Java class for anonymous complex type. + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "", propOrder = {"message", "symbol"}) +@XmlRootElement(name = "InvalidSymbolFault") +public class InvalidSymbolFault { + + @XmlElement(required = true) + protected String message; + @XmlElement(required = true) + protected String symbol; + + /** + * Gets the value of the message property. + * + * @return possible object is {@link String } + */ + public String getMessage() { + return message; + } + + /** + * Sets the value of the message property. + * + * @param value allowed object is {@link String } + */ + public void setMessage(String value) { + this.message = value; + } + + /** + * Gets the value of the symbol property. + * + * @return possible object is {@link String } + */ + public String getSymbol() { + return symbol; + } + + /** + * Sets the value of the symbol property. + * + * @param value allowed object is {@link String } + */ + public void setSymbol(String value) { + this.symbol = value; + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/fault/InvalidSymbolFault_Exception.java b/tags/java/sca/1.0-RC1b/modules/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/fault/InvalidSymbolFault_Exception.java new file mode 100644 index 0000000000..e78889aee0 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/fault/InvalidSymbolFault_Exception.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.databinding.jaxb.fault; + +import javax.xml.ws.WebFault; + +/** + * This class was generated by the JAXWS SI. JAX-WS RI 2.1-02/02/2007 09:55 + * AM(vivekp)-FCS Generated source version: 2.1 + */ +@WebFault(name = "InvalidSymbolFault", targetNamespace = "http://www.example.com/stock") +public class InvalidSymbolFault_Exception extends Exception { + private static final long serialVersionUID = -4618497501663457633L; + + /** + * 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/tags/java/sca/1.0-RC1b/modules/databinding-jaxb/src/test/resources/ipo.xsd b/tags/java/sca/1.0-RC1b/modules/databinding-jaxb/src/test/resources/ipo.xsd new file mode 100755 index 0000000000..241ec15d36 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/databinding-json/.ruleset b/tags/java/sca/1.0-RC1b/modules/databinding-json/.ruleset new file mode 100644 index 0000000000..e615e93a4b --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-json/.ruleset @@ -0,0 +1,172 @@ + + + PMD Plugin preferences rule set + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-json/LICENSE.txt b/tags/java/sca/1.0-RC1b/modules/databinding-json/LICENSE.txt new file mode 100644 index 0000000000..d645695673 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-json/LICENSE.txt @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, 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/tags/java/sca/1.0-RC1b/modules/databinding-json/NOTICE.txt b/tags/java/sca/1.0-RC1b/modules/databinding-json/NOTICE.txt new file mode 100644 index 0000000000..d83ebbe236 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-json/NOTICE.txt @@ -0,0 +1,14 @@ +${pom.name} +Copyright (c) 2005 - 2006 The Apache Software Foundation + +Apache Tuscany is an effort undergoing incubation at The Apache Software +Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is +required of all newly accepted projects until a further review indicates that +the infrastructure, communications, and decision making process have stabilized +in a manner consistent with other successful ASF projects. While incubation +status is not necessarily a reflection of the completeness or stability of the +code, it does indicate that the project has yet to be fully endorsed by the ASF. + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-json/pom.xml b/tags/java/sca/1.0-RC1b/modules/databinding-json/pom.xml new file mode 100644 index 0000000000..39ba5dec4c --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-json/pom.xml @@ -0,0 +1,76 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.0-incubating + ../pom.xml + + tuscany-databinding-json + Apache Tuscany SCA Data Binding for JSON + + + + org.apache.tuscany.sca + tuscany-core-spi + 1.0-incubating + + + org.apache.tuscany.sca + tuscany-databinding + 1.0-incubating + + + + org.codehaus.jettison + jettison + 1.0-RC2 + compile + + + + org.apache.ws.commons.axiom + axiom-api + 1.2.5 + + + xerces + xercesImpl + + + + + + org.apache.ws.commons.axiom + axiom-impl + 1.2.5 + runtime + + + + junit + junit + 4.1 + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/JSON2String.java b/tags/java/sca/1.0-RC1b/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/JSON2String.java new file mode 100644 index 0000000000..9723a8ba69 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/JSON2String.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; + +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.json.JSONObject; + +/** + * @version $Rev$ $Date$ + */ +public class JSON2String extends BaseTransformer implements + PullTransformer { + + @Override + protected Class getSourceType() { + return JSONObject.class; + } + + @Override + protected Class getTargetType() { + return String.class; + } + + public String transform(JSONObject source, TransformationContext context) { + try { + return source.toString(); + } catch (Exception e) { + throw new TransformationException(e); + } + } + + @Override + public int getWeight() { + return 500; + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/JSON2XMLStreamReader.java b/tags/java/sca/1.0-RC1b/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/JSON2XMLStreamReader.java new file mode 100644 index 0000000000..b55bd2b652 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/JSON2XMLStreamReader.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.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 JSONObject.class; + } + + @Override + protected Class getTargetType() { + return XMLStreamReader.class; + } + + public XMLStreamReader transform(JSONObject source, TransformationContext context) { + try { + return new BadgerFishXMLStreamReader(source); + } catch (Exception e) { + throw new TransformationException(e); + } + } + + @Override + public int getWeight() { + return 500; + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/JSONDataBinding.java b/tags/java/sca/1.0-RC1b/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/JSONDataBinding.java new file mode 100644 index 0000000000..a00b8fe3d0 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/JSONDataBinding.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.json; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.databinding.impl.BaseDataBinding; +import org.codehaus.jettison.json.JSONObject; + +/** + * JAXB DataBinding + */ +public class JSONDataBinding extends BaseDataBinding { + public static final String NAME = JSONObject.class.getName(); + public static final String[] ALIASES = new String[] {"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, ALIASES, JSONObject.class); + } + + @SuppressWarnings("unchecked") + @Override + public Object copy(Object arg) { + try { + JSONObject src = (JSONObject)arg; + return new JSONObject(src.toString()); + } catch (Exception e) { + throw new IllegalArgumentException(e); + } + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/String2JSON.java b/tags/java/sca/1.0-RC1b/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/String2JSON.java new file mode 100644 index 0000000000..3e7d074be3 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/String2JSON.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; + +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.json.JSONObject; + +/** + * @version $Rev$ $Date$ + */ +public class String2JSON extends BaseTransformer implements + PullTransformer { + + @Override + protected Class getSourceType() { + return String.class; + } + + @Override + protected Class getTargetType() { + return JSONObject.class; + } + + public JSONObject transform(String source, TransformationContext context) { + try { + return new JSONObject(source); + } catch (Exception e) { + throw new TransformationException(e); + } + } + + @Override + public int getWeight() { + return 500; + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/XMLStreamReader2JSON.java b/tags/java/sca/1.0-RC1b/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/XMLStreamReader2JSON.java new file mode 100644 index 0000000000..76f94c7b28 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/XMLStreamReader2JSON.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.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.codehaus.jettison.badgerfish.BadgerFishXMLStreamWriter; +import org.codehaus.jettison.json.JSONObject; + +/** + * @version $Rev$ $Date$ + */ +public class XMLStreamReader2JSON extends BaseTransformer implements + PullTransformer { + + @Override + protected Class getSourceType() { + return XMLStreamReader.class; + } + + @Override + protected Class getTargetType() { + return JSONObject.class; + } + + public JSONObject 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(); + return new JSONObject(writer.toString()); + } catch (Exception e) { + throw new TransformationException(e); + } + } + + @Override + public int getWeight() { + return 500; + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/XMLStreamSerializer.java b/tags/java/sca/1.0-RC1b/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/XMLStreamSerializer.java new file mode 100644 index 0000000000..26987cbb28 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/XMLStreamSerializer.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.databinding.json; + +import javax.xml.namespace.NamespaceContext; +import javax.xml.stream.XMLStreamConstants; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +/** + * The XMLStreamSerializer pulls events from the XMLStreamReader and dumps into the XMLStreamWriter + */ +public class XMLStreamSerializer implements XMLStreamConstants { + public static final String NAMESPACE_PREFIX = "ns"; + private static int namespaceSuffix; + + /* + * The behavior of the serializer is such that it returns when it encounters the starting element for the second + * time. The depth variable tracks the depth of the serilizer and tells it when to return. Note that it is assumed + * that this serialization starts on an Element. + */ + + /** + * Field depth + */ + private int depth; + + /** + * Generates a unique namespace prefix that is not in the scope of the NamespaceContext + * + * @param nsCtxt + * @return string + */ + private String generateUniquePrefix(NamespaceContext nsCtxt) { + String prefix = NAMESPACE_PREFIX + namespaceSuffix++; + // null should be returned if the prefix is not bound! + while (nsCtxt.getNamespaceURI(prefix) != null) { + prefix = NAMESPACE_PREFIX + namespaceSuffix++; + } + + return prefix; + } + + /** + * Method serialize. + * + * @param node + * @param writer + * @throws XMLStreamException + */ + public void serialize(XMLStreamReader node, XMLStreamWriter writer) throws XMLStreamException { + serializeNode(node, writer); + } + + /** + * @param reader + * @param writer + * @throws XMLStreamException + */ + protected void serializeAttributes(XMLStreamReader reader, XMLStreamWriter writer) throws XMLStreamException { + int count = reader.getAttributeCount(); + String prefix; + String namespaceName; + String writerPrefix; + for (int i = 0; i < count; i++) { + prefix = reader.getAttributePrefix(i); + namespaceName = reader.getAttributeNamespace(i); + /* + * Due to parser implementations returning null as the namespace URI (for the empty namespace) we need to + * make sure that we deal with a namespace name that is not null. The best way to work around this issue is + * to set the namespace uri to "" if it is null + */ + if (namespaceName == null) { + namespaceName = ""; + } + + writerPrefix = writer.getNamespaceContext().getPrefix(namespaceName); + + if (!"".equals(namespaceName)) { + // prefix has already being declared but this particular + // attrib has a + // no prefix attached. So use the prefix provided by the + // writer + if (writerPrefix != null && (prefix == null || prefix.equals(""))) { + writer.writeAttribute(writerPrefix, namespaceName, reader.getAttributeLocalName(i), reader + .getAttributeValue(i)); + + // writer prefix is available but different from the + // current + // prefix of the attrib. We should be decalring the new + // prefix + // as a namespace declaration + } else if (prefix != null && !"".equals(prefix) && !prefix.equals(writerPrefix)) { + writer.writeNamespace(prefix, namespaceName); + writer.writeAttribute(prefix, namespaceName, reader.getAttributeLocalName(i), reader + .getAttributeValue(i)); + + // prefix is null (or empty), but the namespace name is + // valid! it has not + // being written previously also. So we need to generate + // a prefix + // here + } else if (prefix == null || prefix.equals("")) { + prefix = generateUniquePrefix(writer.getNamespaceContext()); + writer.writeNamespace(prefix, namespaceName); + writer.writeAttribute(prefix, namespaceName, reader.getAttributeLocalName(i), reader + .getAttributeValue(i)); + } else { + writer.writeAttribute(prefix, namespaceName, reader.getAttributeLocalName(i), reader + .getAttributeValue(i)); + } + } else { + // empty namespace is equal to no namespace! + writer.writeAttribute(reader.getAttributeLocalName(i), reader.getAttributeValue(i)); + } + + } + } + + /** + * Method serializeCData. + * + * @param reader + * @param writer + * @throws XMLStreamException + */ + protected void serializeCData(XMLStreamReader reader, XMLStreamWriter writer) throws XMLStreamException { + writer.writeCData(reader.getText()); + } + + /** + * Method serializeComment. + * + * @param reader + * @param writer + * @throws XMLStreamException + */ + protected void serializeComment(XMLStreamReader reader, XMLStreamWriter writer) throws XMLStreamException { + writer.writeComment(reader.getText()); + } + + /** + * @param reader + * @param writer + * @throws XMLStreamException + */ + protected void serializeElement(XMLStreamReader reader, XMLStreamWriter writer) throws XMLStreamException { + String prefix = reader.getPrefix(); + String nameSpaceName = reader.getNamespaceURI(); + if (nameSpaceName != null) { + String writerPrefix = writer.getPrefix(nameSpaceName); + if (writerPrefix != null) { + writer.writeStartElement(nameSpaceName, reader.getLocalName()); + } else { + if (prefix != null) { + writer.writeStartElement(prefix, reader.getLocalName(), nameSpaceName); + writer.writeNamespace(prefix, nameSpaceName); + writer.setPrefix(prefix, nameSpaceName); + } else { + // [rfeng] We need to set default NS 1st before calling writeStateElement + writer.setDefaultNamespace(nameSpaceName); + writer.writeStartElement(nameSpaceName, reader.getLocalName()); + writer.writeDefaultNamespace(nameSpaceName); + } + } + } else { + writer.writeStartElement(reader.getLocalName()); + } + + // add the namespaces + int count = reader.getNamespaceCount(); + String namespacePrefix; + for (int i = 0; i < count; i++) { + namespacePrefix = reader.getNamespacePrefix(i); + // [rfeng] The following is commented out to allow to default ns + // if (namespacePrefix != null && namespacePrefix.length() == 0) { + // continue; + // } + + serializeNamespace(namespacePrefix, reader.getNamespaceURI(i), writer); + } + + // add attributes + serializeAttributes(reader, writer); + + } + + /** + * Method serializeEndElement. + * + * @param writer + * @throws XMLStreamException + */ + protected void serializeEndElement(XMLStreamWriter writer) throws XMLStreamException { + writer.writeEndElement(); + } + + /** + * Method serializeNamespace. + * + * @param prefix + * @param uri + * @param writer + * @throws XMLStreamException + */ + private void serializeNamespace(String prefix, String uri, XMLStreamWriter writer) throws XMLStreamException { + String prefix1 = writer.getPrefix(uri); + if (prefix1 == null) { + writer.writeNamespace(prefix, uri); + writer.setPrefix(prefix, uri); + } + } + + /** + * Method serializeNode. + * + * @param reader + * @param writer + * @throws XMLStreamException + */ + protected void serializeNode(XMLStreamReader reader, XMLStreamWriter writer) throws XMLStreamException { + // TODO We get the StAXWriter at this point and uses it hereafter + // assuming that this is the only entry point + // to this class. + // If there can be other classes calling methodes of this we might + // need to change methode signatures to + // OMOutputer + while (true) { + int event = reader.getEventType(); + if (event == START_ELEMENT) { + serializeElement(reader, writer); + depth++; + } else if (event == ATTRIBUTE) { + serializeAttributes(reader, writer); + } else if (event == CHARACTERS) { + serializeText(reader, writer); + } else if (event == COMMENT) { + serializeComment(reader, writer); + } else if (event == CDATA) { + serializeCData(reader, writer); + } else if (event == END_ELEMENT) { + serializeEndElement(writer); + depth--; + } else if (event == START_DOCUMENT) { + depth++; // if a start document is found then increment + writer.writeStartDocument(); + // the depth + } else if (event == END_DOCUMENT) { + if (depth != 0) { + depth--; // for the end document - reduce the depth + } + writer.writeEndDocument(); + } + if (depth == 0) { + break; + } + if (reader.hasNext()) { + reader.next(); + } else { + break; + } + } + } + + /** + * @param reader + * @param writer + * @throws XMLStreamException + */ + protected void serializeText(XMLStreamReader reader, XMLStreamWriter writer) throws XMLStreamException { + writer.writeCharacters(reader.getText()); + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/axiom/JSON2OMElement.java b/tags/java/sca/1.0-RC1b/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/axiom/JSON2OMElement.java new file mode 100644 index 0000000000..a26540e77d --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/axiom/JSON2OMElement.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.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.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 JSONObject.class; + } + + @Override + protected Class getTargetType() { + return OMElement.class; + } + + public OMElement transform(JSONObject source, TransformationContext context) { + try { + 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(source); + OMNamespace namespace = factory.createOMNamespace(ns, ""); + return factory.createOMElement(ds, name, namespace); + } catch (Exception e) { + throw new TransformationException(e); + } + } + + @Override + public int getWeight() { + return 500; + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/axiom/JSONBadgerfishDataSource.java b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/axiom/JSONDataSource.java b/tags/java/sca/1.0-RC1b/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/axiom/JSONDataSource.java new file mode 100644 index 0000000000..50086550a3 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-json/src/main/java/org/apache/tuscany/sca/databinding/json/axiom/JSONDataSource.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.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. + */ + +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/tags/java/sca/1.0-RC1b/modules/databinding-json/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.DataBinding b/tags/java/sca/1.0-RC1b/modules/databinding-json/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.DataBinding new file mode 100644 index 0000000000..49c1010f0c --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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;type=org.codehaus.jettison.json.JSONObject,name=json \ No newline at end of file diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-json/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer b/tags/java/sca/1.0-RC1b/modules/databinding-json/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer new file mode 100644 index 0000000000..a6e3f63418 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-json/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer @@ -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 classes for the transformers +org.apache.tuscany.sca.databinding.json.JSON2XMLStreamReader;source=org.codehaus.jettison.json.JSONObject,target=javax.xml.stream.XMLStreamReader,weight=500 +org.apache.tuscany.sca.databinding.json.XMLStreamReader2JSON;source=javax.xml.stream.XMLStreamReader,target=org.codehaus.jettison.json.JSONObject,weight=500 +org.apache.tuscany.sca.databinding.json.axiom.JSON2OMElement;source=org.codehaus.jettison.json.JSONObject,target=org.apache.axiom.om.OMElement,weight=500 diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-json/src/test/java/org/apache/tuscany/sca/databinding/json/JSONTransformerTestCase.java b/tags/java/sca/1.0-RC1b/modules/databinding-json/src/test/java/org/apache/tuscany/sca/databinding/json/JSONTransformerTestCase.java new file mode 100644 index 0000000000..761b8ac897 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-json/src/test/java/org/apache/tuscany/sca/databinding/json/JSONTransformerTestCase.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.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.JSON2XMLStreamReader; +import org.apache.tuscany.sca.databinding.json.XMLStreamReader2JSON; +import org.apache.tuscany.sca.databinding.json.XMLStreamSerializer; +import org.apache.tuscany.sca.databinding.json.axiom.JSON2OMElement; +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.codehaus.jettison.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 = t1.transform(reader, null); + Assert.assertNotNull(json); + + // Cannot round-trip as we hit a bug in Jettison + /* + 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 = t1.transform(json, null); + assertEquals(jsonObject.getString("name"), "John"); + assertEquals(jsonObject.getInt("age"), 25); + JSON2String t2 = new JSON2String(); + String str = t2.transform(jsonObject, null); + assertEquals(json, str); + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-json/src/test/resources/ipo.xsd b/tags/java/sca/1.0-RC1b/modules/databinding-json/src/test/resources/ipo.xsd new file mode 100644 index 0000000000..5a493e1746 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/databinding-saxon/LICENSE.txt b/tags/java/sca/1.0-RC1b/modules/databinding-saxon/LICENSE.txt new file mode 100644 index 0000000000..d645695673 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-saxon/LICENSE.txt @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, 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/tags/java/sca/1.0-RC1b/modules/databinding-saxon/NOTICE.txt b/tags/java/sca/1.0-RC1b/modules/databinding-saxon/NOTICE.txt new file mode 100644 index 0000000000..d83ebbe236 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-saxon/NOTICE.txt @@ -0,0 +1,14 @@ +${pom.name} +Copyright (c) 2005 - 2006 The Apache Software Foundation + +Apache Tuscany is an effort undergoing incubation at The Apache Software +Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is +required of all newly accepted projects until a further review indicates that +the infrastructure, communications, and decision making process have stabilized +in a manner consistent with other successful ASF projects. While incubation +status is not necessarily a reflection of the completeness or stability of the +code, it does indicate that the project has yet to be fully endorsed by the ASF. + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-saxon/mvn-install-saxon.sh b/tags/java/sca/1.0-RC1b/modules/databinding-saxon/mvn-install-saxon.sh new file mode 100755 index 0000000000..523b0c58be --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-saxon/mvn-install-saxon.sh @@ -0,0 +1,37 @@ +#!/bin/sh + +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Download Saxon B 8.9, unzip, and install into local Maven repos + +cd /tmp +wget http://prdownloads.sourceforge.net/saxon/saxonb8-9j.zip + +unzip saxonb8-9j.zip + +mvn install:install-file -DgroupId=net.sf.saxon -DartifactId=saxon -Dversion=8.9 -Dpackaging=jar -Dfile=/tmp/saxon8.jar +mvn install:install-file -DgroupId=net.sf.saxon -DartifactId=saxon-dom -Dversion=8.9 -Dpackaging=jar -Dfile=/tmp/saxon8-dom.jar + +#mvn install:install-file -DgroupId=net.sf.saxon -DartifactId=saxon-ant -Dversion=8.9 -Dpackaging=jar -Dfile=/tmp/saxon8-ant.jar +#mvn install:install-file -DgroupId=net.sf.saxon -DartifactId=saxon-dom4j -Dversion=8.9 -Dpackaging=jar -Dfile=/tmp/saxon8-dom4j.jar +#mvn install:install-file -DgroupId=net.sf.saxon -DartifactId=saxon-jdom -Dversion=8.9 -Dpackaging=jar -Dfile=/tmp/saxon8-jdom.jar +#mvn install:install-file -DgroupId=net.sf.saxon -DartifactId=saxon-sql -Dversion=8.9 -Dpackaging=jar -Dfile=/tmp/saxon8-sql.jar +#mvn install:install-file -DgroupId=net.sf.saxon -DartifactId=saxon-xom -Dversion=8.9 -Dpackaging=jar -Dfile=/tmp/saxon8-xom.jar +#mvn install:install-file -DgroupId=net.sf.saxon -DartifactId=saxon-xpath -Dversion=8.9 -Dpackaging=jar -Dfile=/tmp/saxon8-xpath.jar +#mvn install:install-file -DgroupId=net.sf.saxon -DartifactId=saxon-xqj -Dversion=8.9 -Dpackaging=jar -Dfile=/tmp/saxon8-xqj.jar + diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-saxon/pom.xml b/tags/java/sca/1.0-RC1b/modules/databinding-saxon/pom.xml new file mode 100644 index 0000000000..71b4e0b6e5 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-saxon/pom.xml @@ -0,0 +1,76 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.0-incubating + ../pom.xml + + tuscany-databinding-saxon + Apache Tuscany SCA Data Binding for Saxon + + + + org.apache.tuscany.sca + tuscany-core-spi + 1.0-incubating + + + + org.apache.tuscany.sca + tuscany-databinding + 1.0-incubating + + + + net.sf.saxon + saxon + 8.7 + + + + net.sf.saxon + saxon-dom + 8.7 + + + + org.apache.tuscany.sdo + tuscany-sdo-lib + 1.0-incubating + + + + org.apache.tuscany.sdo + tuscany-sdo-impl + 1.0-incubating + + + + junit + junit + 4.1 + test + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/DataObject2NodeInfoTransformer.java b/tags/java/sca/1.0-RC1b/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/DataObject2NodeInfoTransformer.java new file mode 100644 index 0000000000..ee8ab88592 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/DataObject2NodeInfoTransformer.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.databinding.saxon; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; + +import javax.xml.transform.Source; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerConfigurationException; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.TransformerFactoryConfigurationError; +import javax.xml.transform.dom.DOMResult; +import javax.xml.transform.stream.StreamSource; + +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 commonj.sdo.DataObject; +import commonj.sdo.helper.XMLHelper; +import commonj.sdo.impl.HelperProvider; + +/** + * Transforms SDO DataObject-s to NodeInfo objects needed by Saxon parser + * @version $Rev$ $Date$ + * 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 + */ +public class DataObject2NodeInfoTransformer extends BaseTransformer implements + PullTransformer { + + private Node2NodeInfoTransformer node2NodeInfoTransformer; + + public DataObject2NodeInfoTransformer(Node2NodeInfoTransformer node2NodeInfoTransformer) { + this.node2NodeInfoTransformer = node2NodeInfoTransformer; + } + + public NodeInfo transform(DataObject source, TransformationContext context) { + XMLHelper helper = HelperProvider.INSTANCE.xmlHelper(); + 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()); + } + + DOMResult domResult = new DOMResult(); + + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + try { + helper.save(source, null, name, baos); + baos.flush(); + baos.close(); + } catch (IOException e) { + throw new TransformationException(e); + } + + ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); + Source src = new StreamSource(bais); + + try { + Transformer transformer = TransformerFactory.newInstance().newTransformer(); + transformer.transform(src, domResult); + } catch (TransformerConfigurationException e) { + throw new TransformationException(e); + } catch (TransformerFactoryConfigurationError e) { + throw new TransformationException(e); + } catch (TransformerException e) { + throw new TransformationException(e); + } + + return node2NodeInfoTransformer.transform(domResult.getNode(), context); + } + + @Override + protected Class getSourceType() { + return DataObject.class; + } + + @Override + protected Class getTargetType() { + return NodeInfo.class; + } + + @Override + public int getWeight() { + return 10; + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/Node2NodeInfoTransformer.java b/tags/java/sca/1.0-RC1b/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/Node2NodeInfoTransformer.java new file mode 100644 index 0000000000..6ef06eacc1 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/Node2NodeInfoTransformer.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.saxon; + +import javax.xml.transform.dom.DOMSource; + +import net.sf.saxon.Configuration; +import net.sf.saxon.event.Builder; +import net.sf.saxon.om.DocumentInfo; +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.w3c.dom.Node; + +/** + * Transforms DOM Node-s to NodeInfo objects needed by Saxon parser + * @version $Rev$ $Date$ + * Any namespaces that are defined are deleted, because otherwise + * the SaxonB parser does not work + */ +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(); + } + DocumentInfo docInfo = null; + try { + docInfo = (DocumentInfo)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/tags/java/sca/1.0-RC1b/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/NodeInfo2DataObjectTransformer.java b/tags/java/sca/1.0-RC1b/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/NodeInfo2DataObjectTransformer.java new file mode 100644 index 0000000000..3f86f27de2 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/NodeInfo2DataObjectTransformer.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.databinding.saxon; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; + +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerConfigurationException; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.TransformerFactoryConfigurationError; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; + +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.impl.BaseTransformer; +import org.w3c.dom.Document; + +import commonj.sdo.DataObject; +import commonj.sdo.helper.XMLHelper; + +/** + * Transforms NodeInfo objects to SDO DataObject-s + * @version $Rev$ $Date$ + * 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) + */ +public class NodeInfo2DataObjectTransformer extends BaseTransformer implements + PullTransformer { + + private NodeInfo2NodeTransformer nodeInfo2NodeTransformer; + + public NodeInfo2DataObjectTransformer(NodeInfo2NodeTransformer nodeInfo2NodeTransformer) { + this.nodeInfo2NodeTransformer = nodeInfo2NodeTransformer; + } + + @Override + protected Class getSourceType() { + return NodeInfo.class; + } + + @Override + protected Class getTargetType() { + return DataObject.class; + } + + @Override + public int getWeight() { + return 10 + nodeInfo2NodeTransformer.getWeight(); + } + + public DataObject transform(NodeInfo source, TransformationContext context) { + Document doc = (Document)nodeInfo2NodeTransformer.transform(source, context); + + return produceResult(doc); + } + + private DataObject produceResult(Document doc) { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + StreamResult streamResult = new StreamResult(baos); + try { + Transformer transformer = TransformerFactory.newInstance().newTransformer(); + transformer.transform(new DOMSource(doc), streamResult); + } catch (TransformerConfigurationException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (TransformerFactoryConfigurationError e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (TransformerException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + try { + baos.flush(); + baos.close(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + DataObject resultingObject = XMLHelper.INSTANCE.load(new String(baos.toByteArray())).getRootObject(); + + return resultingObject; + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/NodeInfo2NodeTransformer.java b/tags/java/sca/1.0-RC1b/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/NodeInfo2NodeTransformer.java new file mode 100644 index 0000000000..1808b8d926 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/NodeInfo2NodeTransformer.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.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 DataObject-s + * @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/tags/java/sca/1.0-RC1b/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/Object2ValueTransformer.java b/tags/java/sca/1.0-RC1b/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/Object2ValueTransformer.java new file mode 100644 index 0000000000..d5f512968a --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/Object2ValueTransformer.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.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; + +/** + * 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 int getWeight() { + return 10000; + } + + public Value transform(Object source, TransformationContext context) { + return new ObjectValue(source); + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/SaxonDataBindingHelper.java b/tags/java/sca/1.0-RC1b/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/SaxonDataBindingHelper.java new file mode 100644 index 0000000000..bebd706d49 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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 meaningfull 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/tags/java/sca/1.0-RC1b/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/SaxonNodeDataBinding.java b/tags/java/sca/1.0-RC1b/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/SaxonNodeDataBinding.java new file mode 100644 index 0000000000..779a8f3712 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/SaxonNodeDataBinding.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 java.lang.annotation.Annotation; + +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.util.XMLType; + +/** + * Represents data binding for parameters of type NodeInfo + * @version $Rev$ $Date$ + * The NodeInfo type is the type accepted by the Saxon XQuery processor for + * all XML - based content (i.e. not strings and simple types) + */ +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, Annotation[] annotations) { + if (super.introspect(type, annotations)) { + type.setLogical(XMLType.UNKNOWN); + return true; + } else { + return false; + } + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/SaxonValueDataBinding.java b/tags/java/sca/1.0-RC1b/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/SaxonValueDataBinding.java new file mode 100644 index 0000000000..43e1929a66 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/SaxonValueDataBinding.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.saxon; + +import java.lang.annotation.Annotation; + +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.util.XMLType; + +/** + * Represents data binding for parameters of type Value + * @version $Rev$ $Date$ + * The Value type is the type accepted by the Saxon XQuery processor for + * all simple types and strings + */ +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, Annotation[] annotations) { + if (super.introspect(type, annotations)) { + type.setLogical(XMLType.UNKNOWN); + return true; + } else { + return false; + } + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/SimpleType2ValueTransformer.java b/tags/java/sca/1.0-RC1b/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/SimpleType2ValueTransformer.java new file mode 100644 index 0000000000..52b612e5e4 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/SimpleType2ValueTransformer.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.saxon; + +import java.math.BigDecimal; +import java.math.BigInteger; + +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/tags/java/sca/1.0-RC1b/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/Value2ObjectTransformer.java b/tags/java/sca/1.0-RC1b/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/Value2ObjectTransformer.java new file mode 100644 index 0000000000..dae0836613 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/Value2ObjectTransformer.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.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; + +/** + * 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 int getWeight() { + return 10000; + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/Value2SimpleTypeTransformer.java b/tags/java/sca/1.0-RC1b/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/Value2SimpleTypeTransformer.java new file mode 100644 index 0000000000..5f799a94de --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/module/SaxonDataBindingModuleActivator.java b/tags/java/sca/1.0-RC1b/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/module/SaxonDataBindingModuleActivator.java new file mode 100644 index 0000000000..73203b9d9b --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-saxon/src/main/java/org/apache/tuscany/sca/databinding/saxon/module/SaxonDataBindingModuleActivator.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.saxon.module; + +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.ModuleActivator; +import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint; +import org.apache.tuscany.sca.databinding.TransformerExtensionPoint; +import org.apache.tuscany.sca.databinding.saxon.DataObject2NodeInfoTransformer; +import org.apache.tuscany.sca.databinding.saxon.Node2NodeInfoTransformer; +import org.apache.tuscany.sca.databinding.saxon.NodeInfo2DataObjectTransformer; +import org.apache.tuscany.sca.databinding.saxon.NodeInfo2NodeTransformer; +import org.apache.tuscany.sca.databinding.saxon.Object2ValueTransformer; +import org.apache.tuscany.sca.databinding.saxon.SaxonNodeDataBinding; +import org.apache.tuscany.sca.databinding.saxon.SaxonValueDataBinding; +import org.apache.tuscany.sca.databinding.saxon.SimpleType2ValueTransformer; +import org.apache.tuscany.sca.databinding.saxon.Value2ObjectTransformer; +import org.apache.tuscany.sca.databinding.saxon.Value2SimpleTypeTransformer; + +/** + * This class activates the value and node info data bindings as well as several transformers + * @version $Rev$ $Date$ + */ +public class SaxonDataBindingModuleActivator implements ModuleActivator { + + public Object[] getExtensionPoints() { + return null; + } + + public void start(ExtensionPointRegistry registry) { + + DataBindingExtensionPoint dataBindings = registry.getExtensionPoint(DataBindingExtensionPoint.class); + dataBindings.addDataBinding(new SaxonNodeDataBinding()); + dataBindings.addDataBinding(new SaxonValueDataBinding()); + + TransformerExtensionPoint transformers = registry.getExtensionPoint(TransformerExtensionPoint.class); + Node2NodeInfoTransformer node2NodeInfoTransformer = new Node2NodeInfoTransformer(); + transformers.addTransformer(node2NodeInfoTransformer); + NodeInfo2NodeTransformer nodeInfo2NodeTransformer = new NodeInfo2NodeTransformer(); + transformers.addTransformer(nodeInfo2NodeTransformer); + transformers.addTransformer(new Object2ValueTransformer()); + transformers.addTransformer(new Value2ObjectTransformer()); + transformers.addTransformer(new SimpleType2ValueTransformer()); + transformers.addTransformer(new Value2SimpleTypeTransformer()); + transformers.addTransformer(new NodeInfo2DataObjectTransformer(nodeInfo2NodeTransformer)); + transformers.addTransformer(new DataObject2NodeInfoTransformer(node2NodeInfoTransformer)); + } + + public void stop(ExtensionPointRegistry registry) { + // TODO Auto-generated method stub + + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-saxon/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator b/tags/java/sca/1.0-RC1b/modules/databinding-saxon/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator new file mode 100644 index 0000000000..a06e29e8a4 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-saxon/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 for Spring module +org.apache.tuscany.sca.databinding.saxon.module.SaxonDataBindingModuleActivator \ No newline at end of file diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-sdo-axiom/.checkstyle b/tags/java/sca/1.0-RC1b/modules/databinding-sdo-axiom/.checkstyle new file mode 100644 index 0000000000..c7b30ffd5e --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-sdo-axiom/.checkstyle @@ -0,0 +1,25 @@ + + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-sdo-axiom/.ruleset b/tags/java/sca/1.0-RC1b/modules/databinding-sdo-axiom/.ruleset new file mode 100644 index 0000000000..27b9ab847c --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-sdo-axiom/.ruleset @@ -0,0 +1,191 @@ + + + + + PMD Plugin preferences rule set + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-sdo-axiom/DISCLAIMER b/tags/java/sca/1.0-RC1b/modules/databinding-sdo-axiom/DISCLAIMER new file mode 100644 index 0000000000..d68a410903 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-sdo-axiom/DISCLAIMER @@ -0,0 +1,8 @@ +Apache Tuscany is an effort undergoing incubation at The Apache Software +Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is +required of all newly accepted projects until a further review indicates that +the infrastructure, communications, and decision making process have stabilized +in a manner consistent with other successful ASF projects. While incubation +status is not necessarily a reflection of the completeness or stability of the +code, it does indicate that the project has yet to be fully endorsed by the ASF. + diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-sdo-axiom/LICENSE b/tags/java/sca/1.0-RC1b/modules/databinding-sdo-axiom/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/databinding-sdo-axiom/NOTICE b/tags/java/sca/1.0-RC1b/modules/databinding-sdo-axiom/NOTICE new file mode 100644 index 0000000000..94481d6cfa --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-sdo-axiom/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2007 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-sdo-axiom/pom.xml b/tags/java/sca/1.0-RC1b/modules/databinding-sdo-axiom/pom.xml new file mode 100644 index 0000000000..c5ca3f7ea6 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-sdo-axiom/pom.xml @@ -0,0 +1,131 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.0-incubating + ../pom.xml + + tuscany-databinding-sdo-axiom + Apache Tuscany SCA Data Binding for SDO/AXIOM + + + + org.apache.tuscany.sca + tuscany-databinding + 1.0-incubating + + + + org.apache.tuscany.sca + tuscany-databinding-sdo + 1.0-incubating + + + + org.apache.ws.commons.axiom + axiom-api + 1.2.5 + + + xerces + xercesImpl + + + + + + org.apache.ws.commons.axiom + axiom-impl + 1.2.5 + runtime + + + + xerces + xercesImpl + 2.8.1 + runtime + + + + + + + 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.0-incubating + + + 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 + + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-sdo-axiom/src/main/java/org/apache/tuscany/sca/databinding/sdo2om/AxiomHelper.java b/tags/java/sca/1.0-RC1b/modules/databinding-sdo-axiom/src/main/java/org/apache/tuscany/sca/databinding/sdo2om/AxiomHelper.java new file mode 100644 index 0000000000..8695d096c2 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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 expection 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/tags/java/sca/1.0-RC1b/modules/databinding-sdo-axiom/src/main/java/org/apache/tuscany/sca/databinding/sdo2om/DataObject2OMElement.java b/tags/java/sca/1.0-RC1b/modules/databinding-sdo-axiom/src/main/java/org/apache/tuscany/sca/databinding/sdo2om/DataObject2OMElement.java new file mode 100644 index 0000000000..ef6b5b0bf2 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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); + 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 + public Class getSourceType() { + return DataObject.class; + } + + @Override + public Class getTargetType() { + return OMElement.class; + } + + @Override + public int getWeight() { + return 10; + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-sdo-axiom/src/main/java/org/apache/tuscany/sca/databinding/sdo2om/DataObjectSerializer.java b/tags/java/sca/1.0-RC1b/modules/databinding-sdo-axiom/src/main/java/org/apache/tuscany/sca/databinding/sdo2om/DataObjectSerializer.java new file mode 100644 index 0000000000..36b775b123 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-sdo-axiom/src/main/java/org/apache/tuscany/sca/databinding/sdo2om/DataObjectSerializer.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.databinding.sdo2om; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import javax.xml.namespace.NamespaceContext; +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sdo.impl.AttributeImpl; +import org.apache.tuscany.sdo.impl.ReferenceImpl; +import org.apache.tuscany.sdo.api.SDOUtil; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EDataType; +import org.eclipse.emf.ecore.EReference; +import org.eclipse.emf.ecore.EStructuralFeature; +import org.eclipse.emf.ecore.util.ExtendedMetaData; + +import commonj.sdo.DataObject; +import commonj.sdo.Property; +import commonj.sdo.Sequence; +import commonj.sdo.Type; +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.XMLDocument; +import commonj.sdo.helper.XSDHelper; + +public class DataObjectSerializer { + private static final String ELEMENT_TEXT = "Text Element"; + + // static final String ELEMENT_TEXT = "Element Text"; + private static final QName XSI_TYPE_QNAME = new QName("http://www.w3.org/2001/XMLSchema-instance", "type", "xsi"); + + private Map declaredNamespaceMap = new HashMap(); + + private NameSpaceContextImpl namespaceContext = new NameSpaceContextImpl(); + + private DataObject rootDataObject; + + private String rootElementName; + + private String rootElementURI; + + private XMLStreamWriter xmlWriter; + + private XSDHelper xsdHelper; + + public DataObjectSerializer(DataObject rootObject, + XMLStreamWriter xmlWriter, + HelperContext helperCtx, + TransformationContext context) { + this.xmlWriter = xmlWriter; + this.rootDataObject = rootObject; + this.xsdHelper = helperCtx.getXSDHelper(); + this.rootElementName = xsdHelper.getLocalName(rootObject.getType()); + this.rootElementURI = rootDataObject.getType().getURI(); + + if (context != null) { + DataType dataType = context.getTargetDataType(); + Object targetQName = dataType == null ? null : dataType.getLogical(); + if (targetQName instanceof QName) { + QName name = (QName)targetQName; + this.rootElementName = name.getLocalPart(); + this.rootElementURI = name.getNamespaceURI(); + } + } + + } + + // private void serializeNamespace(String prefix, String URI, + // XMLStreamWriter writer) throws XMLStreamException { + // String prefix1 = writer.getPrefix(URI); + // if (prefix1 == null) { + // writer.writeNamespace(prefix, URI); + // writer.setPrefix(prefix, URI); + // } + // } + + public DataObjectSerializer(XMLDocument sourceDocument, XMLStreamWriter xmlWriter, HelperContext helperCtx) { + this.xmlWriter = xmlWriter; + this.rootDataObject = sourceDocument.getRootObject(); + this.rootElementName = sourceDocument.getRootElementName(); + this.rootElementURI = sourceDocument.getRootElementURI(); + this.xsdHelper = helperCtx.getXSDHelper(); + } + + protected class NameSpaceContextImpl implements NamespaceContext { + private int counter; + + private Map prefixToNamespaceMapping = new HashMap(); + + public NameSpaceContextImpl() { + prefixToNamespaceMapping.put("xml", "http://www.w3.org/XML/1998/namespace"); + prefixToNamespaceMapping.put("xmlns", "http://www.w3.org/2000/xmlns/"); + prefixToNamespaceMapping.put("xsi", "http://www.w3.org/2001/XMLSchema-instance"); + } + + public synchronized QName createQName(String nsURI, String name) { + String prefix = nsURI != null ? (String)getPrefix(nsURI) : null; + if (prefix == null && nsURI != null && !nsURI.equals("")) { + prefix = "p" + (counter++); + } + if (prefix == null) { + prefix = ""; + } + if (nsURI != null) { + prefixToNamespaceMapping.put(prefix, nsURI); + declaredNamespaceMap.put(prefix, nsURI); + } + return new QName(nsURI, name, prefix); + } + + public String getNamespaceURI(String prefix) { + if (prefix == null) { + throw new IllegalArgumentException("Prefix is null"); + } + + String ns = prefixToNamespaceMapping.get(prefix); + if (ns != null) { + return ns; + } else { + return null; + } + } + + public String getPrefix(String nsURI) { + if (nsURI == null) { + throw new IllegalArgumentException("Namespace is null"); + } + for (Iterator i = prefixToNamespaceMapping.entrySet().iterator(); i.hasNext();) { + Map.Entry entry = (Map.Entry)i.next(); + if (entry.getValue().equals(nsURI)) { + return (String)entry.getKey(); + } + } + return null; + } + + public Iterator getPrefixes(String nsURI) { + List prefixList = new ArrayList(); + for (Iterator i = prefixToNamespaceMapping.entrySet().iterator(); i.hasNext();) { + Map.Entry entry = (Map.Entry)i.next(); + if (entry.getValue().equals(nsURI)) { + prefixList.add(entry.getKey()); + } + } + return prefixList.iterator(); + } + + public void registerMapping(String prefix, String nsURI) { + prefixToNamespaceMapping.put(prefix, nsURI); + } + + public void removeMapping(String prefix) { + prefixToNamespaceMapping.remove(prefix); + } + } + + protected static class NameValuePair implements Map.Entry { + private Object key; + + private Object value; + + public NameValuePair(Object key, Object value) { + this.key = key; + this.value = value; + } + + public Object getKey() { + return key; + } + + public Object getValue() { + return value; + } + + public Object setValue(Object value) { + Object v = this.value; + this.value = value; + return v; + } + + } + + private static boolean isTransient(Property property, Object type) { + // HACK: We need some SDOUtil extension to understand a property is + // derived + EStructuralFeature feature = (EStructuralFeature)property; + if (ExtendedMetaData.INSTANCE.getGroup(feature) != null) { + return false; + } + feature = ExtendedMetaData.INSTANCE.getAffiliation((EClass)type, feature); + if (feature != null && feature != property) { + return false; + } + if (property instanceof ReferenceImpl) { + ReferenceImpl r = (ReferenceImpl)property; + if (r.isTransient()) { + return true; + } + EReference opposite = r.getEOpposite(); + if (opposite != null && opposite.isContainment()) { + return true; + } + } else if (property instanceof AttributeImpl) { + AttributeImpl a = (AttributeImpl)property; + if (a.isTransient()) { + return true; + } + EDataType d = (EDataType)a.getEType(); + if (!d.isSerializable()) { + return true; + } + } + return false; + } + + private void addListValue(List propertyList, + List children, + Property property, + List objList) throws XMLStreamException { + if (objList != null) { + for (int j = 0; j < objList.size(); j++) { + Object object = objList.get(j); + addSingleValue(propertyList, children, property, object); + } + } + } + + private void addProperty(List propertyList, + List children, + Property property, + Object value, + DataObject dataObject) throws XMLStreamException { + + if (property.isMany() && property.getContainingType().isOpen() && value instanceof Sequence) { + addSequenceValue(propertyList, children, (Sequence)value); + } else if (SDOUtil.isMany(property, dataObject) && value instanceof List) { + addListValue(propertyList, children, property, (List)value); + } else { + // Complex Type + addSingleValue(propertyList, children, property, value); + } + } + + private void addSequenceValue(List elements, List children, Sequence seq) + throws XMLStreamException { + if (seq != null && seq.size() > 0) { + for (int j = 0; j < seq.size(); j++) { + Object o = seq.getValue(j); + Property p = seq.getProperty(j); + addSingleValue(elements, children, p, o); + } + } + } + + private void addSingleValue(List propertyList, + List children, + Property property, + Object value) throws XMLStreamException { + String uri = xsdHelper.getNamespaceURI(property); + String name = xsdHelper.getLocalName(property); + QName qname = namespaceContext.createQName(uri, name); + Type propertyType = property.getType(); + + if (property.getName().equals("value") && uri == null && name.equals(":0")) { + propertyList.add(new NameValuePair(ELEMENT_TEXT, value.toString())); + } else if (value == null) { + NameValuePair entry = new NameValuePair(qname, null); + propertyList.add(entry); + } else if (propertyType.isDataType()) { + NameValuePair entry = new NameValuePair(qname, SDOUtil.convertToString(propertyType, value)); + propertyList.add(entry); + } else { + children.add((DataObject)value); + } + } + + private void registerNamespace(String prefix, String uri) { + if (!uri.equals(namespaceContext.getNamespaceURI(prefix))) { + namespaceContext.registerMapping(prefix, uri); + declaredNamespaceMap.put(prefix, uri); + } + } + + public void serialize() throws XMLStreamException { + xmlWriter.setNamespaceContext(namespaceContext); + writeDataObject(rootDataObject, rootElementName, rootElementURI); + xmlWriter.flush(); + } + + private void writeDataObject(DataObject obj, String elementName, String elementURI) throws XMLStreamException { + List elementList = new ArrayList(); + List children = new ArrayList(); + List attributes = new ArrayList(); + + String typeName; + QName realTypeName = null; + + if (elementName != null) { + realTypeName = namespaceContext.createQName(elementURI, elementName); + String typeQName = realTypeName.getPrefix() + ":" + realTypeName.getLocalPart(); + declaredNamespaceMap.put(realTypeName.getPrefix(), realTypeName.getNamespaceURI()); + attributes.add(new NameValuePair(XSI_TYPE_QNAME, typeQName)); + registerNamespace(XSI_TYPE_QNAME.getPrefix(), XSI_TYPE_QNAME.getNamespaceURI()); + } else { + + typeName = xsdHelper.getLocalName(obj.getContainmentProperty()); + realTypeName = namespaceContext.createQName(obj.getType().getURI(), typeName); + registerNamespace(realTypeName.getPrefix(), realTypeName.getNamespaceURI()); + } + + registerNamespace(realTypeName.getPrefix(), realTypeName.getNamespaceURI()); + + if (obj.getType().isSequenced()) { + Sequence sequence = obj.getSequence(); + for (int i = 0; i < sequence.size(); i++) { + Property property = sequence.getProperty(i); + Object value = sequence.getValue(i); + if (property == null) { + elementList.add(new NameValuePair(ELEMENT_TEXT, value)); + } else { + addProperty(elementList, children, property, value, obj); + } + } + + // Attributes are not in the sequence + List properties = obj.getInstanceProperties(); + for (Iterator i = properties.iterator(); i.hasNext();) { + Property property = (Property)i.next(); + if (xsdHelper.isAttribute(property) && obj.isSet(property) && !isTransient(property, obj.getType())) { + Object value = obj.get(property); + QName name = + namespaceContext.createQName(xsdHelper.getNamespaceURI(property), xsdHelper + .getLocalName(property)); + attributes.add(new NameValuePair(name, SDOUtil.convertToString(property.getType(), value))); + } + } + } else { + Iterator i = obj.getInstanceProperties().iterator(); + while (i.hasNext()) { + Property p = (Property)i.next(); + if (obj.isSet(p) && !isTransient(p, obj.getType())) { + Object value = obj.get(p); + if (xsdHelper.isAttribute(p)) { + QName name = + namespaceContext.createQName(xsdHelper.getNamespaceURI(p), xsdHelper.getLocalName(p)); + attributes.add(new NameValuePair(name, SDOUtil.convertToString(p.getType(), value))); + } else { + addProperty(elementList, children, p, value, obj); + } + } + } + } + + String prefix = realTypeName.getPrefix(); + String nameSpaceName = realTypeName.getNamespaceURI(); + + if (nameSpaceName != null) { + String writerPrefix = xmlWriter.getPrefix(nameSpaceName); + if (writerPrefix != null) { + xmlWriter.writeStartElement(nameSpaceName, realTypeName.getLocalPart()); + } else { + if (prefix != null) { + xmlWriter.writeStartElement(prefix, realTypeName.getLocalPart(), nameSpaceName); + xmlWriter.writeNamespace(prefix, nameSpaceName); + xmlWriter.setPrefix(prefix, nameSpaceName); + } else { + xmlWriter.writeStartElement(nameSpaceName, realTypeName.getLocalPart()); + xmlWriter.writeDefaultNamespace(nameSpaceName); + xmlWriter.setDefaultNamespace(nameSpaceName); + } + } + } else { + xmlWriter.writeStartElement(realTypeName.getLocalPart()); + } + + for (NameValuePair pair : attributes) { + QName name = (QName)pair.getKey(); + assert namespaceContext.getPrefix(name.getPrefix()).equals(name.getNamespaceURI()); + xmlWriter.writeAttribute(name.getPrefix(), name.getNamespaceURI(), name.getLocalPart(), (String)pair + .getValue()); + } + + for (NameValuePair pair : elementList) { + if (ELEMENT_TEXT.equals(pair.getKey().toString())) { + xmlWriter.writeCharacters((String)pair.getValue()); + } else { + QName name = (QName)pair.getKey(); + xmlWriter.writeStartElement(name.getPrefix(), name.getLocalPart(), name.getNamespaceURI()); + xmlWriter.writeCharacters((String)pair.getValue()); + xmlWriter.writeEndElement(); + } + } + + for (DataObject child : children) { + writeDataObject(child, null, null); + } + xmlWriter.writeEndElement(); + + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-sdo-axiom/src/main/java/org/apache/tuscany/sca/databinding/sdo2om/SDODataSource.java b/tags/java/sca/1.0-RC1b/modules/databinding-sdo-axiom/src/main/java/org/apache/tuscany/sca/databinding/sdo2om/SDODataSource.java new file mode 100644 index 0000000000..f461a80029 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-sdo-axiom/src/main/java/org/apache/tuscany/sca/databinding/sdo2om/SDODataSource.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.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.XMLStreamHelper; +import org.apache.tuscany.sdo.api.SDOUtil; + +import commonj.sdo.DataObject; +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.XMLDocument; + +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/tags/java/sca/1.0-RC1b/modules/databinding-sdo-axiom/src/main/java/org/apache/tuscany/sca/databinding/sdo2om/XMLDocument2OMElement.java b/tags/java/sca/1.0-RC1b/modules/databinding-sdo-axiom/src/main/java/org/apache/tuscany/sca/databinding/sdo2om/XMLDocument2OMElement.java new file mode 100644 index 0000000000..1f3384efd8 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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); + 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 + public Class getSourceType() { + return XMLDocument.class; + } + + @Override + public Class getTargetType() { + return OMElement.class; + } + + @Override + public int getWeight() { + return 10; + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-sdo-axiom/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer b/tags/java/sca/1.0-RC1b/modules/databinding-sdo-axiom/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer new file mode 100644 index 0000000000..1d25db2b96 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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=1000 +org.apache.tuscany.sca.databinding.sdo2om.XMLDocument2OMElement;source=commonj.sdo.helper.XMLDocument,target=org.apache.axiom.om.OMElement,weight=1000 diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-sdo-axiom/src/test/java/org/apache/tuscany/sca/databinding/sdo2om/DataObject2OMElementTestCase.java b/tags/java/sca/1.0-RC1b/modules/databinding-sdo-axiom/src/test/java/org/apache/tuscany/sca/databinding/sdo2om/DataObject2OMElementTestCase.java new file mode 100644 index 0000000000..d3a1c3f656 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-sdo-axiom/src/test/java/org/apache/tuscany/sca/databinding/sdo2om/DataObject2OMElementTestCase.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.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; + +/** + * + */ +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/tags/java/sca/1.0-RC1b/modules/databinding-sdo-axiom/src/test/java/org/apache/tuscany/sca/databinding/sdo2om/SDOTransformerTestCaseBase.java b/tags/java/sca/1.0-RC1b/modules/databinding-sdo-axiom/src/test/java/org/apache/tuscany/sca/databinding/sdo2om/SDOTransformerTestCaseBase.java new file mode 100644 index 0000000000..f5182f465c --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-sdo-axiom/src/test/java/org/apache/tuscany/sca/databinding/sdo2om/SDOTransformerTestCaseBase.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.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 + */ +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/tags/java/sca/1.0-RC1b/modules/databinding-sdo-axiom/src/test/java/org/apache/tuscany/sca/databinding/sdo2om/XMLDocument2OMElementTestCase.java b/tags/java/sca/1.0-RC1b/modules/databinding-sdo-axiom/src/test/java/org/apache/tuscany/sca/databinding/sdo2om/XMLDocument2OMElementTestCase.java new file mode 100644 index 0000000000..e141e27098 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-sdo-axiom/src/test/java/org/apache/tuscany/sca/databinding/sdo2om/XMLDocument2OMElementTestCase.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.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; + +/** + * + */ +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/tags/java/sca/1.0-RC1b/modules/databinding-sdo-axiom/src/test/resources/ipo.xsd b/tags/java/sca/1.0-RC1b/modules/databinding-sdo-axiom/src/test/resources/ipo.xsd new file mode 100644 index 0000000000..241ec15d36 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/databinding-sdo-axiom/src/test/resources/stock.xsd b/tags/java/sca/1.0-RC1b/modules/databinding-sdo-axiom/src/test/resources/stock.xsd new file mode 100644 index 0000000000..a0a6717371 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-sdo-axiom/src/test/resources/stock.xsd @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-sdo/.checkstyle b/tags/java/sca/1.0-RC1b/modules/databinding-sdo/.checkstyle new file mode 100644 index 0000000000..c7b30ffd5e --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-sdo/.checkstyle @@ -0,0 +1,25 @@ + + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-sdo/.ruleset b/tags/java/sca/1.0-RC1b/modules/databinding-sdo/.ruleset new file mode 100644 index 0000000000..27b9ab847c --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-sdo/.ruleset @@ -0,0 +1,191 @@ + + + + + PMD Plugin preferences rule set + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-sdo/DISCLAIMER b/tags/java/sca/1.0-RC1b/modules/databinding-sdo/DISCLAIMER new file mode 100644 index 0000000000..d68a410903 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-sdo/DISCLAIMER @@ -0,0 +1,8 @@ +Apache Tuscany is an effort undergoing incubation at The Apache Software +Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is +required of all newly accepted projects until a further review indicates that +the infrastructure, communications, and decision making process have stabilized +in a manner consistent with other successful ASF projects. While incubation +status is not necessarily a reflection of the completeness or stability of the +code, it does indicate that the project has yet to be fully endorsed by the ASF. + diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-sdo/LICENSE b/tags/java/sca/1.0-RC1b/modules/databinding-sdo/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/databinding-sdo/NOTICE b/tags/java/sca/1.0-RC1b/modules/databinding-sdo/NOTICE new file mode 100644 index 0000000000..94481d6cfa --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-sdo/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2007 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-sdo/pom.xml b/tags/java/sca/1.0-RC1b/modules/databinding-sdo/pom.xml new file mode 100755 index 0000000000..49f82220d0 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-sdo/pom.xml @@ -0,0 +1,119 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.0-incubating + ../pom.xml + + tuscany-databinding-sdo + Apache Tuscany SCA Data Binding for SDO + + + + org.apache.tuscany.sca + tuscany-core-spi + 1.0-incubating + + + org.apache.tuscany.sca + tuscany-databinding + 1.0-incubating + + + + org.apache.tuscany.sca + tuscany-implementation-java-xml + 1.0-incubating + + + org.apache.tuscany.sdo + tuscany-sdo-lib + 1.0-incubating + + + org.apache.tuscany.sdo + tuscany-sdo-impl + 1.0-incubating + + + + + + + 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.0-incubating + + + 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 + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/DataObject2String.java b/tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/DataObject2String.java new file mode 100755 index 0000000000..51f378ba27 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/DataObject2String.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 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) { + try { + HelperContext helperContext = SDOContextHelper.getHelperContext(context); + XMLHelper xmlHelper = helperContext.getXMLHelper(); + QName elementName = SDOContextHelper.getElement(context.getSourceDataType()); + return xmlHelper.save(source, elementName.getNamespaceURI(), elementName.getLocalPart()); + } catch (Exception e) { + throw new TransformationException(e); + } + } + + @Override + public Class getSourceType() { + return DataObject.class; + } + + @Override + public Class getTargetType() { + return String.class; + } + + @Override + public int getWeight() { + return 40; + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/DataObject2XMLStreamReader.java b/tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/DataObject2XMLStreamReader.java new file mode 100755 index 0000000000..4f91764ffd --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/DataObject2XMLStreamReader.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.sdo; + +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.XMLStreamHelper; +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; + +public class DataObject2XMLStreamReader extends BaseTransformer implements + PullTransformer { + + public XMLStreamReader transform(DataObject source, TransformationContext context) { + try { + HelperContext helperContext = SDOContextHelper.getHelperContext(context); + XMLStreamHelper streamHelper = SDOUtil.createXMLStreamHelper(helperContext); + QName elementName = SDOContextHelper.getElement(context.getSourceDataType()); + XMLHelper xmlHelper = helperContext.getXMLHelper(); + XMLDocument document = + 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 + public Class getSourceType() { + return DataObject.class; + } + + @Override + public Class getTargetType() { + return XMLStreamReader.class; + } + + @Override + public int getWeight() { + return 10; + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/ImportSDO.java b/tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/ImportSDO.java new file mode 100644 index 0000000000..30a3e1c3a9 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/ImportSDOProcessor.java b/tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/ImportSDOProcessor.java new file mode 100755 index 0000000000..98fcc9e462 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/ImportSDOProcessor.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.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.URI; +import java.net.URL; + +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 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 { + + public ImportSDOProcessor(ModelFactoryExtensionPoint modelFactories) { + super(); + } + + 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) throws ContributionResolveException { + String factoryName = importSDO.getFactoryClassName(); + if (factoryName != null) { + //FIXME The classloader should be passed in + ClassLoader cl = Thread.currentThread().getContextClassLoader(); + try { + Class factoryClass = cl.loadClass(factoryName); + register(factoryClass, importSDO.getHelperContext()); + } catch (Exception e) { + throw new ContributionResolveException(e); + } + importSDO.setUnresolved(false); + } + } + + 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) throws ContributionResolveException { + String location = importSDO.getSchemaLocation(); + if (location != null) { + try { + URL wsdlURL = null; + URI uri = URI.create(location); + if (uri.isAbsolute()) { + wsdlURL = uri.toURL(); + } + //FIXME The classloader should be passed in + wsdlURL = Thread.currentThread().getContextClassLoader().getResource(location); + if (null == wsdlURL) { + ContributionResolveException loaderException = new ContributionResolveException( + "WSDL location error"); + throw loaderException; + } + InputStream xsdInputStream = wsdlURL.openStream(); + try { + XSDHelper xsdHelper = importSDO.getHelperContext().getXSDHelper(); + xsdHelper.define(xsdInputStream, wsdlURL.toExternalForm()); + } finally { + xsdInputStream.close(); + } + } catch (IOException e) { + throw new ContributionResolveException(e); + } + importSDO.setUnresolved(false); + } + } + + 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); + importWSDL(importSDO); + if (!importSDO.isUnresolved()) { + resolver.addModel(importSDO); + } + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOContextHelper.java b/tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOContextHelper.java new file mode 100644 index 0000000000..37979401d8 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOContextHelper.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.databinding.sdo; + +import java.lang.reflect.Method; +import java.util.List; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.databinding.DataBinding; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +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.Type; +import commonj.sdo.helper.HelperContext; +import commonj.sdo.impl.HelperProvider; + +/** + * Helper class to get TypeHelper from the context + */ +public final class SDOContextHelper { + private SDOContextHelper() { + } + + public static HelperContext getHelperContext(TransformationContext context) { + if (context == null) { + return getDefaultHelperContext(); + } + + HelperContext helperContext = (HelperContext)context.getMetadata().get(HelperContext.class.getName()); + if (helperContext != null) { + return helperContext; + } + helperContext = SDOUtil.createHelperContext(); + + boolean found = false; + Operation op = context.getSourceOperation(); + if (op != null) { + found = register(helperContext, op.getInputType()) || found; + found = register(helperContext, op.getOutputType()) || found; + } else { + found = register(helperContext, context.getSourceDataType()) || found; + } + + op = context.getTargetOperation(); + if (op != null) { + found = register(helperContext, op.getInputType()) || found; + found = register(helperContext, op.getOutputType()) || found; + } else { + found = register(helperContext, context.getTargetDataType()) || found; + } + + if (!found) { + helperContext = getDefaultHelperContext(); + } + + context.getMetadata().put(HelperContext.class.getName(), helperContext); + return helperContext; + + } + + /** + * @param helperContext + * @param dataType + * @return + */ + private static boolean register(HelperContext helperContext, DataType dataType) { + if (dataType == null) { + return false; + } + String db = dataType.getDataBinding(); + boolean found = false; + if (DataBinding.IDL_INPUT.equals(db) || DataBinding.IDL_OUTPUT.equals(db) + || DataBinding.IDL_FAULT.equals(db) + || SDODataBinding.NAME.equals(db)) { + Class javaType = dataType.getPhysical(); + found = register(helperContext, javaType); + if (dataType.getLogical() instanceof DataType) { + DataType logical = (DataType)dataType.getLogical(); + found = register(helperContext, logical.getPhysical()) || found; + } + if (dataType.getLogical() instanceof List) { + List types = (List)dataType.getLogical(); + for (Object type : types) { + if (type instanceof DataType) { + found = register(helperContext, ((DataType)type)) || found; + } + } + } + } + return found; + } + + /** + * FIXME: [rfeng] This is a hack to get the factory out a SDO class + * @param helperContext + * @param javaType + */ + + private static boolean register(HelperContext helperContext, Class javaType) { + try { + Type type = helperContext.getTypeHelper().getType(javaType); + if (type != null && (!type.isDataType())) { + Method method = type.getClass().getMethod("getEPackage", new Class[] {}); + Object factory = method.invoke(type, new Object[] {}); + method = factory.getClass().getMethod("register", new Class[] {HelperContext.class}); + method.invoke(factory, new Object[] {helperContext}); + return true; + } + return false; + } catch (Exception e) { + throw new TransformationException(e); + } + } + + public static HelperContext getDefaultHelperContext() { + // SDOUtil.createHelperContext(); + return HelperProvider.getDefaultContext(); + } + + public static QName getElement(DataType dataType) { + Object logical = dataType.getLogical(); + QName elementName = SDODataBinding.ROOT_ELEMENT; + if (logical instanceof XMLType) { + XMLType xmlType = (XMLType)logical; + QName element = xmlType.getElementName(); + if (element != null) { + elementName = element; + } + } + return elementName; + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDODataBinding.java b/tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDODataBinding.java new file mode 100644 index 0000000000..a526ece68d --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDODataBinding.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.databinding.sdo; + +import java.lang.annotation.Annotation; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.databinding.ExceptionHandler; +import org.apache.tuscany.sca.databinding.SimpleTypeMapper; +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.util.XMLType; + +import commonj.sdo.DataObject; +import commonj.sdo.Type; +import commonj.sdo.helper.CopyHelper; +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.XMLDocument; +import commonj.sdo.impl.HelperProvider; + +/** + * SDO Databinding + * + * @version $Reve$ $Date$ + */ +public class SDODataBinding extends BaseDataBinding { + public static final String NAME = DataObject.class.getName(); + public static final String[] ALIASES = new String[] {"sdo"}; + + public static final String ROOT_NAMESPACE = "commonj.sdo"; + public static final QName ROOT_ELEMENT = new QName(ROOT_NAMESPACE, "dataObject"); + + private WrapperHandler wrapperHandler; + + public SDODataBinding() { + super(NAME, ALIASES, DataObject.class); + wrapperHandler = new SDOWrapperHandler(); + } + + @Override + public boolean introspect(DataType dataType, Annotation[] annotations) { + Class javaType = dataType.getPhysical(); + HelperContext context = HelperProvider.getDefaultContext(); + // FIXME: Need a better to test dynamic SDO + if (DataObject.class.isAssignableFrom(javaType)) { + // Dynamic SDO + dataType.setDataBinding(getName()); + dataType.setLogical(XMLType.UNKNOWN); + return true; + } + // FIXME: We need to access HelperContext + Type type = context.getTypeHelper().getType(javaType); + if (type == null) { + return false; + } + if (type.isDataType()) { + // FIXME: Ignore simple types? + return false; + } + String namespace = type.getURI(); + String name = context.getXSDHelper().getLocalName(type); + QName xmlType = new QName(namespace, name); + dataType.setDataBinding(getName()); + dataType.setLogical(new XMLType(null, xmlType)); + return true; + } + + @Override + public WrapperHandler getWrapperHandler() { + return wrapperHandler; + } + + @Override + public SimpleTypeMapper getSimpleTypeMapper() { + return new SDOSimpleTypeMapper(); + } + + @Override + public Object copy(Object arg) { + HelperContext context = HelperProvider.getDefaultContext(); + 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); + } + } + + @Override + public ExceptionHandler getExceptionHandler() { + return new SDOExceptionHandler(); + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOExceptionHandler.java b/tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOExceptionHandler.java new file mode 100644 index 0000000000..5c23240b19 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOExceptionHandler.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.databinding.sdo; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; +import java.lang.reflect.Method; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.databinding.ExceptionHandler; +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.Type; +import commonj.sdo.helper.HelperContext; +import commonj.sdo.impl.HelperProvider; + +/** + * SDO implementation of ExceptionHandler + * + * @version $Rev$ $Date$ + */ +public class SDOExceptionHandler implements ExceptionHandler { + private static final Class[] EMPTY_CLASS_ARRAY = new Class[0]; + + // FIXME: Need a way to pass in the HelperContext + private HelperContext helperContext = HelperProvider.getDefaultContext(); + + /** + *
    + *
  • WrapperException(String message, FaultBean faultInfo)
    + * A constructor where WrapperException is replaced with the name of the + * generated wrapper exception and FaultBean is replaced by the name of the + * generated fault bean. + *
  • WrapperException(String message, FaultBean faultInfo, Throwable + * cause)
    + * A constructor whereWrapperException is replaced with the name of the + * generated wrapper exception and FaultBean is replaced by the name of the + * generated fault bean. The last argument, cause, may be used to convey + * protocol specific fault information + *
+ */ + public Exception createException(DataType exceptionType, String message, Object faultInfo, Throwable cause) { + Class exceptionClass = exceptionType.getPhysical(); + DataType faultBeanType = exceptionType.getLogical(); + Class faultBeanClass = faultBeanType.getPhysical(); + try { + Constructor constructor = + exceptionClass.getConstructor(new Class[] {String.class, faultBeanClass, Throwable.class}); + return (Exception)constructor.newInstance(new Object[] {message, faultInfo, cause}); + } catch (Throwable e) { + throw new IllegalArgumentException(e); + } + } + + public Object getFaultInfo(Exception exception) { + if (exception == null) { + return null; + } + try { + Method method = exception.getClass().getMethod("getFaultInfo", EMPTY_CLASS_ARRAY); + return method.invoke(exception, (Object[])null); + } catch (Throwable e) { + throw new IllegalArgumentException(e); + } + } + + public DataType getFaultType(DataType exceptionDataType) { + Class exceptionType = exceptionDataType.getPhysical(); + Class faultBeanClass = null; + try { + Method method = exceptionType.getMethod("getFaultInfo", EMPTY_CLASS_ARRAY); + faultBeanClass = method.getReturnType(); + } catch (NoSuchMethodException e) { + faultBeanClass = null; + } + if (faultBeanClass == null) { + return null; + } + + QName faultElement = null; + try { + Field field = exceptionType.getField("FAULT_ELEMENT"); + faultElement = (QName)field.get(null); + } catch (NoSuchFieldException e) { + // Fall back to type inspection + Type type = helperContext.getTypeHelper().getType(faultBeanClass); + if (type != null && !type.isDataType()) { + String ns = type.getURI(); + String name = helperContext.getXSDHelper().getLocalName(type); + faultElement = new QName(ns, name); + } + } catch (Throwable e) { + // Ignore + } + if (faultElement == null) { + return null; + } + DataType faultType = + new DataTypeImpl(SDODataBinding.NAME, faultBeanClass, new XMLType(faultElement, null)); + return faultType; + + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOSimpleTypeMapper.java b/tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOSimpleTypeMapper.java new file mode 100644 index 0000000000..f2b01a7e4e --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOSimpleTypeMapper.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.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 + */ +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); + 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); + TypeHelper typeHelper = helperContext.getTypeHelper(); + type = typeHelper.getType(typeName.getNamespaceURI(), typeName.getLocalPart()); + } + return SDOUtil.convertToString(type, obj); + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOWrapperHandler.java b/tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOWrapperHandler.java new file mode 100644 index 0000000000..822d97eaf7 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOWrapperHandler.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.sdo; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.WrapperHandler; +import org.apache.tuscany.sca.interfacedef.DataType; +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.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 + */ +public class SDOWrapperHandler implements WrapperHandler { + + /** + * @see org.apache.tuscany.sca.databinding.WrapperHandler#create(ElementInfo, TransformationContext) + */ + public Object create(ElementInfo element, TransformationContext context) { + DataObject wrapper = null; + HelperContext helperContext = SDOContextHelper.getHelperContext(context); + Type sdoType = getSDOType(helperContext, element); + if (sdoType != null) { + DataFactory dataFactory = helperContext.getDataFactory(); + return dataFactory.create(sdoType); + } + return null; + } + + /** + * @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; + wrapperDO.set(i, value); + } + + @SuppressWarnings("unchecked") + public List getChildren(Object wrapper, List childElements, TransformationContext context) { + 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(org.apache.tuscany.sca.interfacedef.util.ElementInfo, List, org.apache.tuscany.sca.databinding.TransformationContext) + */ + public DataType getWrapperType(ElementInfo element, List childElements, TransformationContext context) { + // FIXME: [rfeng] Temporarily disable the wrapping support for SDO to work around a few issues + // in the WSDL-less story + if (true) { + return null; + } + HelperContext helperContext = SDOContextHelper.getHelperContext(context); + Type sdoType = getSDOType(helperContext, element); + if (sdoType != null) { + // Check if child elements matches + for (ElementInfo child : childElements) { + if (sdoType.getProperty(child.getQName().getLocalPart()) == null) { + return null; + } + } + 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, org.apache.tuscany.sca.interfacedef.util.ElementInfo, java.util.List, org.apache.tuscany.sca.databinding.TransformationContext) + */ + public boolean isInstance(Object wrapper, + ElementInfo element, + List childElements, + TransformationContext context) { + HelperContext helperContext = SDOContextHelper.getHelperContext(context); + Type sdoType = getSDOType(helperContext, element); + if (sdoType != null) { + return sdoType.isInstance(wrapper); + } + return false; + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/String2DataObject.java b/tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/String2DataObject.java new file mode 100755 index 0000000000..bc212d7351 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/String2DataObject.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.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) { + try { + HelperContext helperContext = SDOContextHelper.getHelperContext(context); + XMLHelper xmlHelper = helperContext.getXMLHelper(); + return xmlHelper.load(source).getRootObject(); + } catch (Exception e) { + throw new TransformationException(e); + } + } + + @Override + public Class getSourceType() { + return String.class; + } + + @Override + public Class getTargetType() { + return DataObject.class; + } + + @Override + public int getWeight() { + return 50; + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/XMLDocument2String.java b/tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/XMLDocument2String.java new file mode 100644 index 0000000000..c43aa40452 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/XMLDocument2String.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 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) { + try { + HelperContext helperContext = SDOContextHelper.getHelperContext(context); + XMLHelper xmlHelper = helperContext.getXMLHelper(); + StringWriter writer = new StringWriter(); + xmlHelper.save(source, writer, null); + return writer.toString(); + } catch (Exception e) { + throw new TransformationException(e); + } + } + + @Override + public Class getSourceType() { + return XMLDocument.class; + } + + @Override + public Class getTargetType() { + return String.class; + } + + @Override + public int getWeight() { + return 40; + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/XMLDocument2XMLStreamReader.java b/tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/XMLDocument2XMLStreamReader.java new file mode 100755 index 0000000000..50b257176c --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/XMLDocument2XMLStreamReader.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.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.XMLStreamHelper; +import org.apache.tuscany.sdo.api.SDOUtil; + +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) { + try { + HelperContext helperContext = SDOContextHelper.getHelperContext(context); + XMLStreamHelper streamHelper = SDOUtil.createXMLStreamHelper(helperContext); + return streamHelper.createXMLStreamReader(source); + } catch (XMLStreamException e) { + throw new TransformationException(e); + } + } + + @Override + public Class getSourceType() { + return XMLDocument.class; + } + + @Override + public Class getTargetType() { + return XMLStreamReader.class; + } + + @Override + public int getWeight() { + return 10; + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/XMLStreamReader2DataObject.java b/tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/XMLStreamReader2DataObject.java new file mode 100755 index 0000000000..df13aa3489 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/XMLStreamReader2DataObject.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.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.XMLStreamHelper; +import org.apache.tuscany.sdo.api.SDOUtil; + +import commonj.sdo.DataObject; +import commonj.sdo.helper.HelperContext; + +public class XMLStreamReader2DataObject extends BaseTransformer implements + PullTransformer { + + public DataObject transform(XMLStreamReader source, TransformationContext context) { + try { + HelperContext helperContext = SDOContextHelper.getHelperContext(context); + XMLStreamHelper streamHelper = SDOUtil.createXMLStreamHelper(helperContext); + // The XMLStreamHelper requires that the reader is posistioned 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 + public Class getTargetType() { + return DataObject.class; + } + + @Override + public Class getSourceType() { + return XMLStreamReader.class; + } + + @Override + public int getWeight() { + return 15; + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/XMLStreamReader2XMLDocument.java b/tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/XMLStreamReader2XMLDocument.java new file mode 100755 index 0000000000..75bb6dad74 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/XMLStreamReader2XMLDocument.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 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.XMLStreamHelper; +import org.apache.tuscany.sdo.api.SDOUtil; + +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.XMLDocument; + +public class XMLStreamReader2XMLDocument extends BaseTransformer implements + PullTransformer { + + public XMLDocument transform(XMLStreamReader source, TransformationContext context) { + try { + HelperContext helperContext = SDOContextHelper.getHelperContext(context); + XMLStreamHelper streamHelper = SDOUtil.createXMLStreamHelper(helperContext); + XMLDocument target = streamHelper.load(source); + source.close(); + return target; + } catch (Exception e) { + throw new TransformationException(e); + } + } + + @Override + public Class getTargetType() { + return XMLDocument.class; + } + + @Override + public Class getSourceType() { + return XMLStreamReader.class; + } + + @Override + public int getWeight() { + return 15; + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor b/tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor new file mode 100644 index 0000000000..ffe8b895b8 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor @@ -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.sdo.ImportSDOProcessor;qname=http://tuscany.apache.org/xmlns/sca/databinding/sdo/1.0#import.sdo,model=org.apache.tuscany.sca.databinding.sdo.ImportSDO diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.DataBinding b/tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.DataBinding new file mode 100644 index 0000000000..afd00b552c --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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;type=commonj.sdo.DataObject,name=sdo \ No newline at end of file diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer b/tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer new file mode 100644 index 0000000000..00c8e642a4 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer @@ -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. + +# Implementation classes for the transformers +org.apache.tuscany.sca.databinding.sdo.DataObject2String;source=commonj.sdo.DataObject,target=java.lang.String,weight=40 +org.apache.tuscany.sca.databinding.sdo.DataObject2XMLStreamReader;source=commonj.sdo.DataObject,target=javax.xml.stream.XMLStreamReader,weight=10 +org.apache.tuscany.sca.databinding.sdo.XMLDocument2String;source=commonj.sdo.helper.XMLDocument,target=java.lang.String,weight=40 +org.apache.tuscany.sca.databinding.sdo.String2DataObject;source=java.lang.String,target=commonj.sdo.DataObject,weight=50 +org.apache.tuscany.sca.databinding.sdo.XMLDocument2XMLStreamReader;source=commonj.sdo.helper.XMLDocument,target=javax.xml.stream.XMLStreamReader,weight=10 +org.apache.tuscany.sca.databinding.sdo.XMLStreamReader2DataObject;source=javax.xml.stream.XMLStreamReader,target=commonj.sdo.DataObject,weight=15 +org.apache.tuscany.sca.databinding.sdo.XMLStreamReader2XMLDocument;source=javax.xml.stream.XMLStreamReader,target=commonj.sdo.helper.XMLDocument,weight=15 diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/test/java/com/example/stock/sdo/fault/InvalidSymbolFault_Exception.java b/tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/test/java/com/example/stock/sdo/fault/InvalidSymbolFault_Exception.java new file mode 100644 index 0000000000..c5d87d2c3c --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/test/java/com/example/stock/sdo/fault/InvalidSymbolFault_Exception.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 com.example.stock.sdo.fault; + +import javax.xml.namespace.QName; + +import com.example.stock.sdo.InvalidSymbolFault; + +/** + * Hand-crafted java exception for SDO fault + * + */ +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/tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/DataObject2StringTestCase.java b/tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/DataObject2StringTestCase.java new file mode 100644 index 0000000000..3665434cee --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/DataObject2StringTestCase.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 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; + +/** + * + */ +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/tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/DataObject2XMLStreamReaderTestCase.java b/tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/DataObject2XMLStreamReaderTestCase.java new file mode 100644 index 0000000000..369912f115 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/DataObject2XMLStreamReaderTestCase.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.databinding.sdo; + +import javax.xml.stream.XMLStreamConstants; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +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; + +/** + * + */ +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; + } + } + new XMLStreamReader2DataObject().transform(reader, reversedContext); + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/ImportSDOProcessorTestCase.java b/tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/ImportSDOProcessorTestCase.java new file mode 100755 index 0000000000..10bea0a30d --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/ImportSDOProcessorTestCase.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.io.StringReader; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +import junit.framework.TestCase; + +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); + loader.resolve(importSDO, new TestModelResolver()); + assertTrue(inited); + } + + @Override + protected void setUp() throws Exception { + loader = new ImportSDOProcessor(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/tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDODataBindingTestCase.java b/tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDODataBindingTestCase.java new file mode 100644 index 0000000000..a41dc585d9 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDODataBindingTestCase.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.sdo; + +import javax.xml.namespace.QName; + +import junit.framework.TestCase; + +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 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; + +/** + * + */ +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() { + DataType dataType = new DataTypeImpl(DataObject.class, null); + boolean yes = binding.introspect(dataType, null); + 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, null); + 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, null); + 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); + 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); + 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); + 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/tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDOExceptionHandlerTestCase.java b/tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDOExceptionHandlerTestCase.java new file mode 100644 index 0000000000..62069acaaa --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDOExceptionHandlerTestCase.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 junit.framework.TestCase; + +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.stock.sdo.InvalidSymbolFault; +import com.example.stock.sdo.StockFactory; +import com.example.stock.sdo.fault.InvalidSymbolFault_Exception; +import commonj.sdo.impl.HelperProvider; + +/** + * Test case for SDOExceptionHandler + */ +public class SDOExceptionHandlerTestCase extends TestCase { + // FIXME: Tuscany SDO impl uses _._type for anonymouse type, by the SDO + // spec, it should be same as the + // enclosing element/attribute name + private SDOExceptionHandler handler; + + /** + * @see junit.framework.TestCase#setUp() + */ + @Override + protected void setUp() throws Exception { + super.setUp(); + this.handler = new SDOExceptionHandler(); + StockFactory.INSTANCE.register(HelperProvider.getDefaultContext()); + } + + public void testGetFaultType() { + DataType execType = new DataTypeImpl(InvalidSymbolFault_Exception.class, XMLType.UNKNOWN); + DataType dataType = handler.getFaultType(execType); + assertEquals(InvalidSymbolFault.class, dataType.getPhysical()); + assertEquals(InvalidSymbolFault_Exception.FAULT_ELEMENT, ((XMLType) dataType.getLogical()).getElementName()); + assertEquals(SDODataBinding.NAME, dataType.getDataBinding()); + } + + public void testCreate() { + DataType execType = new DataTypeImpl(InvalidSymbolFault_Exception.class, XMLType.UNKNOWN); + DataType faultType = handler.getFaultType(execType); + InvalidSymbolFault fault = StockFactory.INSTANCE.createInvalidSymbolFault(); + fault.setMessage("ABC"); + fault.setSymbol("IBM0"); + DataType exType = new DataTypeImpl(InvalidSymbolFault_Exception.class, faultType); + Exception ex = handler.createException(exType, "Invalid symbol", fault, null); + assertTrue(ex instanceof InvalidSymbolFault_Exception); + InvalidSymbolFault_Exception exception = (InvalidSymbolFault_Exception)ex; + assertEquals("Invalid symbol", exception.getMessage()); + assertSame(fault, exception.getFaultInfo()); + } + + public void testGetFaultInfo() { + InvalidSymbolFault fault = StockFactory.INSTANCE.createInvalidSymbolFault(); + fault.setMessage("ABC"); + fault.setSymbol("IBM0"); + InvalidSymbolFault_Exception exception = new InvalidSymbolFault_Exception("Invalid symbol", fault); + Object faultInfo = handler.getFaultInfo(exception); + assertSame(fault, faultInfo); + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDOTransformerTestCaseBase.java b/tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDOTransformerTestCaseBase.java new file mode 100644 index 0000000000..f5c26bf9f5 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDOTransformerTestCaseBase.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.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 + */ +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/tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDOWrapperHandlerTestCase.java b/tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDOWrapperHandlerTestCase.java new file mode 100644 index 0000000000..799e0c2388 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDOWrapperHandlerTestCase.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 java.util.List; + +import javax.xml.namespace.QName; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.interfacedef.util.ElementInfo; +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")); + List children = handler.getChildren(document, null, null); + 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")); + List children = handler.getChildren(document, null, null); + 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); + DataObject wrapper = (DataObject) handler.create(element, null); + assertNotNull(wrapper); + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/TestModelResolver.java b/tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/TestModelResolver.java new file mode 100644 index 0000000000..ce04f5be3f --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/XMLDocument2XMLStreamReaderTestCase.java b/tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/XMLDocument2XMLStreamReaderTestCase.java new file mode 100644 index 0000000000..78bc62eb3a --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/XMLDocument2XMLStreamReaderTestCase.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 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; + +/** + * + */ +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/tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/test/resources/ipo.xsd b/tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/test/resources/ipo.xsd new file mode 100755 index 0000000000..241ec15d36 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/test/resources/model/sca-core.xsd b/tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/test/resources/model/sca-core.xsd new file mode 100755 index 0000000000..56c6977254 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/test/resources/model/sca-core.xsd @@ -0,0 +1,233 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/test/resources/model/sca-implementation-mock.xsd b/tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/test/resources/model/sca-implementation-mock.xsd new file mode 100755 index 0000000000..bbaf58f00c --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/test/resources/model/sca-implementation-mock.xsd @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/test/resources/stock.xsd b/tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/test/resources/stock.xsd new file mode 100644 index 0000000000..a0a6717371 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/test/resources/stock.xsd @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/test/resources/wrapper.xml b/tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/test/resources/wrapper.xml new file mode 100644 index 0000000000..2526629409 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/test/resources/wrapper.xml @@ -0,0 +1,27 @@ + + + + message + symbol + message1 + symbol1 + symbol2 + diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/test/resources/wrapper.xsd b/tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/test/resources/wrapper.xsd new file mode 100644 index 0000000000..ea4dc5f7f3 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-sdo/src/test/resources/wrapper.xsd @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-xmlbeans/.ruleset b/tags/java/sca/1.0-RC1b/modules/databinding-xmlbeans/.ruleset new file mode 100644 index 0000000000..e615e93a4b --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-xmlbeans/.ruleset @@ -0,0 +1,172 @@ + + + PMD Plugin preferences rule set + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-xmlbeans/LICENSE.txt b/tags/java/sca/1.0-RC1b/modules/databinding-xmlbeans/LICENSE.txt new file mode 100755 index 0000000000..d645695673 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-xmlbeans/LICENSE.txt @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, 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/tags/java/sca/1.0-RC1b/modules/databinding-xmlbeans/NOTICE.txt b/tags/java/sca/1.0-RC1b/modules/databinding-xmlbeans/NOTICE.txt new file mode 100644 index 0000000000..d83ebbe236 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-xmlbeans/NOTICE.txt @@ -0,0 +1,14 @@ +${pom.name} +Copyright (c) 2005 - 2006 The Apache Software Foundation + +Apache Tuscany is an effort undergoing incubation at The Apache Software +Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is +required of all newly accepted projects until a further review indicates that +the infrastructure, communications, and decision making process have stabilized +in a manner consistent with other successful ASF projects. While incubation +status is not necessarily a reflection of the completeness or stability of the +code, it does indicate that the project has yet to be fully endorsed by the ASF. + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-xmlbeans/pom.xml b/tags/java/sca/1.0-RC1b/modules/databinding-xmlbeans/pom.xml new file mode 100644 index 0000000000..6279fd5ed1 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-xmlbeans/pom.xml @@ -0,0 +1,111 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.0-incubating + ../pom.xml + + tuscany-databinding-xmlbeans + Apache Tuscany SCA Data Binding for XmlBeans + + + + org.apache.tuscany.sca + tuscany-core-spi + 1.0-incubating + + + org.apache.tuscany.sca + tuscany-databinding + 1.0-incubating + + + + org.apache.xmlbeans + xmlbeans + 2.3.0 + compile + + + junit + junit + 4.2 + + + + + + + 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-test-sources + + + + + + + + run + + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-xmlbeans/src/main/java/org/apache/tuscany/sca/databinding/xmlbeans/Node2XmlObject.java b/tags/java/sca/1.0-RC1b/modules/databinding-xmlbeans/src/main/java/org/apache/tuscany/sca/databinding/xmlbeans/Node2XmlObject.java new file mode 100755 index 0000000000..4130dcb4df --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-xmlbeans/src/main/java/org/apache/tuscany/sca/databinding/xmlbeans/Node2XmlObject.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.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; + +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 + public Class getTargetType() { + return XmlObject.class; + } + + @Override + public Class getSourceType() { + return Node.class; + } + + @Override + public int getWeight() { + return 30; + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-xmlbeans/src/main/java/org/apache/tuscany/sca/databinding/xmlbeans/XMLBeansDataBinding.java b/tags/java/sca/1.0-RC1b/modules/databinding-xmlbeans/src/main/java/org/apache/tuscany/sca/databinding/xmlbeans/XMLBeansDataBinding.java new file mode 100644 index 0000000000..eaf4fb4902 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-xmlbeans/src/main/java/org/apache/tuscany/sca/databinding/xmlbeans/XMLBeansDataBinding.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.xmlbeans; + +import org.apache.tuscany.sca.databinding.impl.BaseDataBinding; +import org.apache.xmlbeans.XmlObject; + +/** + * XMLBeans DataBinding + */ +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 Object copy(Object object) { + return ((XmlObject) object).copy(); + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-xmlbeans/src/main/java/org/apache/tuscany/sca/databinding/xmlbeans/XMLStreamReader2XmlObject.java b/tags/java/sca/1.0-RC1b/modules/databinding-xmlbeans/src/main/java/org/apache/tuscany/sca/databinding/xmlbeans/XMLStreamReader2XmlObject.java new file mode 100755 index 0000000000..a4f32c5cb1 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-xmlbeans/src/main/java/org/apache/tuscany/sca/databinding/xmlbeans/XMLStreamReader2XmlObject.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.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; + +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 + public Class getTargetType() { + return XmlObject.class; + } + + @Override + public Class getSourceType() { + return XMLStreamReader.class; + } + + @Override + public int getWeight() { + return 10; + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-xmlbeans/src/main/java/org/apache/tuscany/sca/databinding/xmlbeans/XmlObject2Node.java b/tags/java/sca/1.0-RC1b/modules/databinding-xmlbeans/src/main/java/org/apache/tuscany/sca/databinding/xmlbeans/XmlObject2Node.java new file mode 100755 index 0000000000..800fae9780 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-xmlbeans/src/main/java/org/apache/tuscany/sca/databinding/xmlbeans/XmlObject2Node.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 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; + +@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 + public Class getSourceType() { + return XmlObject.class; + } + + @Override + public Class getTargetType() { + return Node.class; + } + + @Override + public int getWeight() { + return 30; + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-xmlbeans/src/main/java/org/apache/tuscany/sca/databinding/xmlbeans/XmlObject2XMLStreamReader.java b/tags/java/sca/1.0-RC1b/modules/databinding-xmlbeans/src/main/java/org/apache/tuscany/sca/databinding/xmlbeans/XmlObject2XMLStreamReader.java new file mode 100755 index 0000000000..4fd961c52e --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-xmlbeans/src/main/java/org/apache/tuscany/sca/databinding/xmlbeans/XmlObject2XMLStreamReader.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.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; + +public class XmlObject2XMLStreamReader extends BaseTransformer implements PullTransformer { + // private XmlOptions options; + + public XMLStreamReader transform(XmlObject source, TransformationContext context) { + return source.newXMLStreamReader(); + } + + @Override + public Class getSourceType() { + return XmlObject.class; + } + + @Override + public Class getTargetType() { + return XMLStreamReader.class; + } + + @Override + public int getWeight() { + return 10; + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-xmlbeans/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.DataBinding b/tags/java/sca/1.0-RC1b/modules/databinding-xmlbeans/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.DataBinding new file mode 100644 index 0000000000..907d06559a --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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;type=org.apache.xmlbeans.XmlObject,name=xmlbeans \ No newline at end of file diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-xmlbeans/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer b/tags/java/sca/1.0-RC1b/modules/databinding-xmlbeans/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer new file mode 100644 index 0000000000..392b2c9389 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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=30 +org.apache.tuscany.sca.databinding.xmlbeans.XmlObject2Node;source=org.apache.xmlbeans.XmlObject,target=org.w3c.dom.Node,weight=30 +org.apache.tuscany.sca.databinding.xmlbeans.XmlObject2XMLStreamReader;source=org.apache.xmlbeans.XmlObject,target=javax.xml.stream.XMLStreamReader,weight=10 +org.apache.tuscany.sca.databinding.xmlbeans.XMLStreamReader2XmlObject;source=javax.xml.stream.XMLStreamReader,target=org.apache.xmlbeans.XmlObject,weight=10 diff --git a/tags/java/sca/1.0-RC1b/modules/databinding-xmlbeans/src/test/java/org/apache/tuscany/sca/databinding/xmlbeans/XmlObjectTestCase.java b/tags/java/sca/1.0-RC1b/modules/databinding-xmlbeans/src/test/java/org/apache/tuscany/sca/databinding/xmlbeans/XmlObjectTestCase.java new file mode 100755 index 0000000000..3b62a99021 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-xmlbeans/src/test/java/org/apache/tuscany/sca/databinding/xmlbeans/XmlObjectTestCase.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.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; + +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/tags/java/sca/1.0-RC1b/modules/databinding-xmlbeans/src/test/resources/ipo.xsd b/tags/java/sca/1.0-RC1b/modules/databinding-xmlbeans/src/test/resources/ipo.xsd new file mode 100755 index 0000000000..5a493e1746 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/databinding-xmlbeans/src/test/resources/ipo.xsdconfig b/tags/java/sca/1.0-RC1b/modules/databinding-xmlbeans/src/test/resources/ipo.xsdconfig new file mode 100755 index 0000000000..a397182672 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding-xmlbeans/src/test/resources/ipo.xsdconfig @@ -0,0 +1,21 @@ + + + + + com.example.ipo.xmlbeans + + + diff --git a/tags/java/sca/1.0-RC1b/modules/databinding/.checkstyle b/tags/java/sca/1.0-RC1b/modules/databinding/.checkstyle new file mode 100644 index 0000000000..c7b30ffd5e --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding/.checkstyle @@ -0,0 +1,25 @@ + + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/databinding/.pmd b/tags/java/sca/1.0-RC1b/modules/databinding/.pmd new file mode 100644 index 0000000000..2db10d6a6a --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding/.pmd @@ -0,0 +1,20 @@ + + +truefalse \ No newline at end of file diff --git a/tags/java/sca/1.0-RC1b/modules/databinding/.ruleset b/tags/java/sca/1.0-RC1b/modules/databinding/.ruleset new file mode 100644 index 0000000000..ba9b5ce886 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding/.ruleset @@ -0,0 +1,190 @@ + + + + PMD Plugin preferences rule set + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tags/java/sca/1.0-RC1b/modules/databinding/DISCLAIMER b/tags/java/sca/1.0-RC1b/modules/databinding/DISCLAIMER new file mode 100644 index 0000000000..d68a410903 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding/DISCLAIMER @@ -0,0 +1,8 @@ +Apache Tuscany is an effort undergoing incubation at The Apache Software +Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is +required of all newly accepted projects until a further review indicates that +the infrastructure, communications, and decision making process have stabilized +in a manner consistent with other successful ASF projects. While incubation +status is not necessarily a reflection of the completeness or stability of the +code, it does indicate that the project has yet to be fully endorsed by the ASF. + diff --git a/tags/java/sca/1.0-RC1b/modules/databinding/LICENSE b/tags/java/sca/1.0-RC1b/modules/databinding/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/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/tags/java/sca/1.0-RC1b/modules/databinding/NOTICE b/tags/java/sca/1.0-RC1b/modules/databinding/NOTICE new file mode 100644 index 0000000000..94481d6cfa --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2007 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/tags/java/sca/1.0-RC1b/modules/databinding/pom.xml b/tags/java/sca/1.0-RC1b/modules/databinding/pom.xml new file mode 100644 index 0000000000..99818cf999 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding/pom.xml @@ -0,0 +1,51 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.0-incubating + ../pom.xml + + tuscany-databinding + Apache Tuscany SCA DataBinding Framework + + + + org.apache.tuscany.sca + tuscany-interface + 1.0-incubating + + + + stax + stax-api + 1.0.1 + + + + org.codehaus.woodstox + wstx-asl + 3.2.1 + runtime + + + diff --git a/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DataBinding.java b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DataBinding.java new file mode 100644 index 0000000000..34313fdae0 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DataBinding.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; + +import java.lang.annotation.Annotation; + +import org.apache.tuscany.sca.interfacedef.DataType; + +/** + * DataBinding represents a data representation, for example, SDO, JAXB and AXIOM + */ +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(); + + /** + * Get the aliases for the databinding + * + * @return An array of aliases + */ + String[] getAliases(); + + /** + * Introspect and populate information to a DataType model + * + * @param dataType The data type to be introspected + * @param annotations The java annotations + * @return true if the databinding has recognized the given data type + */ + boolean introspect(DataType dataType, Annotation[] annotations); + + /** + * Introspect the data to figure out the corresponding data type + * + * @param value The object to be checked + * @return The DataType or null if the java type is not supported by this databinding + */ + DataType introspect(Object value); + + /** + * Provide a WrapperHandler for this databinding + * @return A wrapper handler which can handle wrapping/wrapping for this databinding + */ + WrapperHandler getWrapperHandler(); + + /** + * Make a copy of the object for "pass-by-value" semantics + * @param source object to copy + * @return copy of the object passed in as argument + */ + Object copy(Object object); + + /** + * Get the type mapper for simple types + * @return The databinding-specific simple type mapper + */ + SimpleTypeMapper getSimpleTypeMapper(); + + /** + * Get the handler that can handle exceptions/faults in the + * databinding-specific way + * + * @return An instance of the exception handler + */ + ExceptionHandler getExceptionHandler(); +} diff --git a/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DataBindingExtensionPoint.java b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DataBindingExtensionPoint.java new file mode 100644 index 0000000000..205843e2be --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DataBindingExtensionPoint.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; + +import java.lang.annotation.Annotation; + +import org.apache.tuscany.sca.interfacedef.DataType; + +/** + * An extension point for data binding extensions. + */ +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 annotations The java annotations + * @return A DataType representing the java type or null if no databinding + * recognizes the java type + */ + boolean introspectType(DataType dataType, Annotation[] annotations); + + /** + * Introspect the java class to figure out what DataType supports it + * + * @param DataType The initial data type + * @param annotations The java annotations + * @param boolean Should be set to true if DataType parm represents an Exception + * @return A DataType representing the java type or null if no databinding + * recognizes the java type + */ + boolean introspectType(DataType dataType, Annotation[] annotations, boolean isFaultType); + + /** + * Introspect the value to figure out the corresponding DataType + * + * @param value The object value + * @return A DataType representing the value or null if no databinding + * recognizes the value + */ + DataType introspectType(Object value); +} diff --git a/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DataPipe.java b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DataPipe.java new file mode 100755 index 0000000000..69a0e4510a --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DataPipe.java @@ -0,0 +1,44 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.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 + */ +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/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DataPipeTransformer.java b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DataPipeTransformer.java new file mode 100644 index 0000000000..4486117d31 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DataPipeTransformer.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; + +/** + * Data pipe allows a data source pushes data into its sink and pipe the data into its result + * + */ +public interface DataPipeTransformer extends Transformer { + + public DataPipe newInstance(); +} diff --git a/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DefaultDataBindingExtensionPoint.java b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DefaultDataBindingExtensionPoint.java new file mode 100644 index 0000000000..c44487acdc --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DefaultDataBindingExtensionPoint.java @@ -0,0 +1,254 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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.annotation.Annotation; +import java.lang.ref.WeakReference; +import java.lang.reflect.Constructor; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.tuscany.sca.databinding.impl.ServiceConfigurationUtil; +import org.apache.tuscany.sca.databinding.javabeans.JavaBeansDataBinding; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; + +/** + * The default implementation of a data binding extension point. + * + * @version $Rev$ $Date$ + */ +public class DefaultDataBindingExtensionPoint implements DataBindingExtensionPoint { + private final Map bindings = new HashMap(); + private boolean loadedDataBindings; + + public DefaultDataBindingExtensionPoint() { + } + + 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) { + bindings.put(dataBinding.getName().toLowerCase(), dataBinding); + String[] aliases = dataBinding.getAliases(); + if (aliases != null) { + for (String alias : aliases) { + bindings.put(alias.toLowerCase(), dataBinding); + } + } + } + + public DataBinding removeDataBinding(String id) { + if (id == null) { + return null; + } + DataBinding dataBinding = bindings.remove(id.toLowerCase()); + if (dataBinding != null) { + String[] aliases = dataBinding.getAliases(); + if (aliases != null) { + for (String alias : aliases) { + bindings.remove(alias.toLowerCase()); + } + } + } + return dataBinding; + } + + /** + * Dynamically load data bindings declared under META-INF/services + */ + private void loadDataBindings() { + if (loadedDataBindings) + return; + + // Get the databinding service declarations + ClassLoader classLoader = DataBinding.class.getClassLoader(); + List dataBindingDeclarations; + try { + dataBindingDeclarations = + ServiceConfigurationUtil.getServiceClassNames(classLoader, DataBinding.class.getName()); + } catch (IOException e) { + throw new IllegalStateException(e); + } + + // Load data bindings + for (String dataBindingDeclaration : dataBindingDeclarations) { + Map attributes = ServiceConfigurationUtil.parseServiceDeclaration(dataBindingDeclaration); + String className = attributes.get("class"); + String type = attributes.get("type"); + String name = attributes.get("name"); + + // Create a data binding wrapper and register it + DataBinding dataBinding = new LazyDataBinding(type, name, classLoader, className); + addDataBinding(dataBinding); + } + + loadedDataBindings = true; + } + + /** + * A data binding facade allowing data bindings to be lazily loaded and + * initialized. + */ + private static class LazyDataBinding implements DataBinding { + + private String name; + private String[] aliases; + private WeakReference classLoader; + private String className; + private DataBinding dataBinding; + + private LazyDataBinding(String type, String name, ClassLoader classLoader, String className) { + this.name = type; + if (name != null) { + this.aliases = new String[] {name}; + } + this.classLoader = new WeakReference(classLoader); + this.className = className; + } + + /** + * Load and instantiate the data binding class. + * + * @return The data binding. + */ + @SuppressWarnings("unchecked") + private DataBinding getDataBinding() { + if (dataBinding == null) { + try { + Class dataBindingClass = + (Class)Class.forName(className, true, classLoader.get()); + Constructor constructor = dataBindingClass.getConstructor(); + dataBinding = constructor.newInstance(); + } catch (Exception e) { + throw new IllegalStateException(e); + } + } + return dataBinding; + } + + public Object copy(Object object) { + return getDataBinding().copy(object); + } + + public String[] getAliases() { + return aliases; + } + + public ExceptionHandler getExceptionHandler() { + return getDataBinding().getExceptionHandler(); + } + + public String getName() { + return name; + } + + public SimpleTypeMapper getSimpleTypeMapper() { + return getDataBinding().getSimpleTypeMapper(); + } + + public WrapperHandler getWrapperHandler() { + return getDataBinding().getWrapperHandler(); + } + + public boolean introspect(DataType dataType, Annotation[] annotations) { + return getDataBinding().introspect(dataType, annotations); + } + + public DataType introspect(Object value) { + return getDataBinding().introspect(value); + } + } + + //FIXME The following methods should not be on the extension point + // they should be on a separate class + public boolean introspectType(DataType dataType, Annotation[] annotations) { + return introspectType(dataType, annotations, false); + } + + // + // Leverage the DataBinding ExceptionHandler to calculate the DataType of an exception DataType + // + public boolean introspectType(DataType dataType, Annotation[] annotations, boolean isException) { + loadDataBindings(); + for (DataBinding binding : bindings.values()) { + // 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 (isException) { + // Next look to see if the DB's exceptionHandler handles this exception + ExceptionHandler excHandler = binding.getExceptionHandler(); + if (excHandler != null) { + // Assymetric to have the introspect() methods set the DataBindings themselves + // whereas we're setting it ourselves here. + DataType faultType = excHandler.getFaultType(dataType); + if (faultType != null) { + dataType.setDataBinding(binding.getName()); + dataType.setLogical(faultType); + return true; + } + } + } else { + if (binding.introspect(dataType, annotations)) { + return true; + } + } + } + } + // FIXME: Should we honor the databinding from operation/interface + // level? + Class physical = dataType.getPhysical(); + if (physical == Object.class) { + return false; + } + dataType.setDataBinding(JavaBeansDataBinding.NAME); + return false; + } + + public DataType introspectType(Object value) { + loadDataBindings(); + DataType dataType = null; + for (DataBinding binding : bindings.values()) { + // 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); + } + if (dataType != null) { + return dataType; + } + } + return new DataTypeImpl(JavaBeansDataBinding.NAME, value.getClass(), value.getClass()); + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DefaultTransformerExtensionPoint.java b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DefaultTransformerExtensionPoint.java new file mode 100755 index 0000000000..8a5392aebc --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DefaultTransformerExtensionPoint.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.databinding; + +import java.io.IOException; +import java.lang.ref.WeakReference; +import java.lang.reflect.Constructor; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import org.apache.tuscany.sca.databinding.impl.DirectedGraph; +import org.apache.tuscany.sca.databinding.impl.ServiceConfigurationUtil; + +/** + * @version $Rev$ $Date$ + */ +public class DefaultTransformerExtensionPoint implements TransformerExtensionPoint { + private boolean loadedTransformers; + + private final DirectedGraph graph = new DirectedGraph(); + + public DefaultTransformerExtensionPoint() { + } + + public void addTransformer(String sourceType, String resultType, int weight, Transformer transformer) { + graph.addEdge(sourceType, resultType, transformer, weight); + } + + public void addTransformer(Transformer transformer) { + graph.addEdge(transformer.getSourceDataBinding(), + transformer.getTargetDataBinding(), + transformer, + transformer.getWeight()); + } + + 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 void loadTransformers() { + if (loadedTransformers) { + return; + } + loadTransformers(PullTransformer.class); + loadTransformers(PushTransformer.class); + loadedTransformers = true; + } + + /** + * Dynamically load transformers registered under META-INF/services. + * + * @param transformerClass + */ + private void loadTransformers(Class transformerClass) { + + // Get the transformer service declarations + ClassLoader classLoader = transformerClass.getClassLoader(); + List transformerDeclarations; + try { + transformerDeclarations = ServiceConfigurationUtil.getServiceClassNames(classLoader, transformerClass.getName()); + } catch (IOException e) { + throw new IllegalStateException(e); + } + + // Load transformers + for (String transformerDeclaration: transformerDeclarations) { + Map attributes = ServiceConfigurationUtil.parseServiceDeclaration(transformerDeclaration); + String className = attributes.get("class"); + String source = attributes.get("source"); + String target = attributes.get("target"); + int weight = Integer.valueOf(attributes.get("weight")); + + // Create a transformer wrapper and register it + Transformer transformer; + if (transformerClass == PullTransformer.class) { + transformer = new LazyPullTransformer(source, target, weight, classLoader, className); + } else { + transformer = new LazyPushTransformer(source, target, weight, classLoader, className); + } + addTransformer(transformer); + } + } + + /** + * 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 WeakReference classLoader; + private String className; + private PullTransformer transformer; + + public LazyPullTransformer(String source, String target, int weight, ClassLoader classLoader, String className) { + this.source = source; + this.target = target; + this.weight = weight; + this.classLoader = new WeakReference(classLoader); + this.className = className; + } + + /** + * Load and instantiate the transformer class. + * + * @return The transformer. + */ + @SuppressWarnings("unchecked") + private PullTransformer getTransformer() { + if (transformer == null) { + try { + Class> transformerClass = + (Class>)Class.forName(className, true, classLoader.get()); + 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); + } + + } + + /** + * 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 WeakReference classLoader; + private String className; + private PushTransformer transformer; + + public LazyPushTransformer(String source, String target, int weight, ClassLoader classLoader, String className) { + this.source = source; + this.target = target; + this.weight = weight; + this.classLoader = new WeakReference(classLoader); + this.className = className; + } + + /** + * Load and instantiate the transformer class. + * + * @return The transformer. + */ + @SuppressWarnings("unchecked") + private PushTransformer getTransformer() { + if (transformer == null) { + try { + Class> transformerClass = + (Class>)Class.forName(className, true, classLoader.get()); + 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); + } + + } + + + //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(); + 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/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/ExceptionHandler.java b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/ExceptionHandler.java new file mode 100644 index 0000000000..131e8a3114 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/ExceptionHandler.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; + +import org.apache.tuscany.sca.interfacedef.DataType; + +/** + * ExceptionHandler provides databinding-specific logic for exception handling + * + * @version $Rev$ $Date$ + */ +public interface ExceptionHandler { + /** + * Create an exception to wrap the fault data + * + * @param exceptionType The DataType for the exception + * @param message The error message + * @param faultInfo The databinding-specific fault data + * @param cause The protocol-specific error + * @return An instance of java exception to represent the fault + */ + Exception createException(DataType exceptionType, String message, Object faultInfo, Throwable cause); + + /** + * Retrieve the fault info from a java exception + * + * @param exception The databinding-specific java exception that represents + * the fault data + * @return The databinding-specific fault data + */ + Object getFaultInfo(Exception exception); + + /** + * Introspect an exception class to figure out the fault data type + * + * @param exceptionDataType The exception class + * @return The data type for the fault + */ + DataType getFaultType(DataType exceptionDataType); +} diff --git a/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/Mediator.java b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/Mediator.java new file mode 100755 index 0000000000..168a1052b3 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/Mediator.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; + +import java.util.Map; + +import org.apache.tuscany.sca.interfacedef.DataType; + +/** + * This interface will be used as a Tuscany system service to perform data mediations + * + * Mediate the data from one type to the other one + * + */ +public interface Mediator { + + /** + * Mediate the data from the source type to the target type + * @param source The data to be mediated + * @param sourceDataType Data type for the source data + * @param targetDataType Data type for the target data + * @param context + * @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); + + /** + * Get the DataBindings used by this mediator. + * @return + */ + DataBindingExtensionPoint getDataBindings(); + + /** + * Get the Transformers used by this mediator. + * @return + */ + TransformerExtensionPoint getTransformers(); +} diff --git a/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/PullTransformer.java b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/PullTransformer.java new file mode 100644 index 0000000000..feed87e45f --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/PullTransformer.java @@ -0,0 +1,36 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.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 + */ +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/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/PushTransformer.java b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/PushTransformer.java new file mode 100644 index 0000000000..80e5e4f0a3 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/PushTransformer.java @@ -0,0 +1,34 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding; + +/** + * A transformer that pushes data from its source into the sink + * + * @param + * @param + */ +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/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/SimpleTypeMapper.java b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/SimpleTypeMapper.java new file mode 100644 index 0000000000..70ea431d57 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/SimpleTypeMapper.java @@ -0,0 +1,44 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.databinding; + +import javax.xml.namespace.QName; + +/** + * Type Mapper between XML schema simple data types and java objects + */ +public interface SimpleTypeMapper { + /** + * Parse the XML lexical representation into a java object + * @param simpleType The XSD simple type + * @param value the XML lexical representation + * @param context The context of the transformation + * @return A java object for the XML value + */ + Object toJavaObject(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/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/TransformationContext.java b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/TransformationContext.java new file mode 100755 index 0000000000..27818dc24f --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/TransformationContext.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; + +import java.util.Map; + +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.Operation; + +/** + * Context for data transformation + * + */ +public interface TransformationContext { + + Operation getSourceOperation(); + void setSourceOperation(Operation sourceOperation); + Operation getTargetOperation(); + 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 + */ + ClassLoader getClassLoader(); + + /** + * Get a map of metadata + * + * @return + */ + Map getMetadata(); + +} diff --git a/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/TransformationException.java b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/TransformationException.java new file mode 100755 index 0000000000..8d2b36482d --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/TransformationException.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; + + +/** + * Reports problems during data transformation + */ +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/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/Transformer.java b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/Transformer.java new file mode 100755 index 0000000000..062f087a15 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/Transformer.java @@ -0,0 +1,49 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding; + +/** + * A transformer provides the data transformation from source type to target type. The cost of the transformation is + * modeled as weight. + */ +public interface Transformer { + /** + * Get the source type that this transformer transforms data from. The type is used as the key when the transformer + * is registered with TransformerRegistry. + * + * @return A key indentifying the source type + */ + String getSourceDataBinding(); + + /** + * Get the target type that this transformer transforms data into. The type is used as the key when the transformer + * is registered with TransformerRegistry. + * + * @return A key indentifying the target type + */ + String getTargetDataBinding(); + + /** + * Get the cost of the transformation. The weight can be used to choose the most efficient path if there are more + * than one available from the source to the target. + * + * @return An integer representing the cost of the transformation + */ + int getWeight(); +} diff --git a/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/TransformerExtensionPoint.java b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/TransformerExtensionPoint.java new file mode 100755 index 0000000000..1abae06754 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/TransformerExtensionPoint.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; + +import java.util.List; + +/** + * An extension point for data transformer extensions. + */ +public interface TransformerExtensionPoint { + + /** + * Register a transformer + * + * @param sourceDataBinding + * @param targetDataBinding + * @param weight + * @param transformer + */ + void addTransformer(String sourceDataBinding, + String targetDataBinding, + int weight, + Transformer transformer); + + /** + * Register a transformer + * + * @param transformer + */ + void addTransformer(Transformer transformer); + + /** + * 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/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/WrapperHandler.java b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/WrapperHandler.java new file mode 100644 index 0000000000..379a967c9c --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/WrapperHandler.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; + +import java.util.List; + +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.util.ElementInfo; + +/** + * A contract for transformers to deal with wrapping/unwrapping for WSDL wrapper style operations + */ +public interface WrapperHandler { + /** + * Create a wrapper element + * + * @param element The XSD element + * @param context The transformation context + * @return An object representing the wrapper element + */ + T create(ElementInfo element, TransformationContext context); + + /** + * Get the data type for the wrapper + * @param element The wrapper element + * @param childElements A list of child elements + * @param context The transformation context + * @return The data type of the wrapper, null if it's not a wrapper type + */ + DataType getWrapperType(ElementInfo element, List childElements, TransformationContext context); + + /** + * Check if the given data is an instance of the wrapper + * @param wrapper + * @param element + * @param childElements + * @param context + * @return + */ + boolean isInstance(Object wrapper, + ElementInfo element, + List childElements, + TransformationContext context); + + /** + * Set child element for the wrapper + * + * @param wrapper The wrapper + * @param i The index + * @param childElement The XSD element + * @param value The value of the child + */ + void setChild(T wrapper, int i, ElementInfo childElement, Object value); + + /** + * Get a list of child elements from the wrapper + * @param wrapper + * @param childElements + * @param context + * @return child elements under the wrapper + */ + List getChildren(T wrapper, List childElements, TransformationContext context); + + // Object getChild(T wrapper, ElementInfo childElement, TransformationContext context); +} diff --git a/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/annotation/DataBinding.java b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/annotation/DataBinding.java new file mode 100644 index 0000000000..1d0e117d34 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/annotation/DataBinding.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.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 expected data types for an operation + * + * @version $Rev$ $Date$ + */ +@Target({TYPE, METHOD}) +@Retention(RUNTIME) +public @interface DataBinding { + + /** + * Returns the unique name of the data binding + * @return the unique name of the data binding + */ + String value(); + boolean wrapperStyle() default false; + +} diff --git a/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/annotation/DataType.java b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/annotation/DataType.java new file mode 100644 index 0000000000..2714391e75 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/annotation/DataType.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.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 unique name of the data binding + * @return the unique name of the data binding + */ + String value(); + + /** + * Additional attributes to further describe the data type + * @return + */ + String[] attributes() default {}; + +} diff --git a/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/BaseDataBinding.java b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/BaseDataBinding.java new file mode 100644 index 0000000000..0bc9d3c192 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/BaseDataBinding.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.impl; + +import java.lang.annotation.Annotation; + +import org.apache.tuscany.sca.databinding.DataBinding; +import org.apache.tuscany.sca.databinding.ExceptionHandler; +import org.apache.tuscany.sca.databinding.SimpleTypeMapper; +import org.apache.tuscany.sca.databinding.WrapperHandler; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; + +/** + * Base Implementation of DataBinding + * + * @version $Rev$ $Date$ + */ +public abstract class BaseDataBinding implements DataBinding { + + private Class baseType; + + private String name; + private String[] aliases; + + /** + * 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(), null, 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, null, baseType); + } + + /** + * Create a databinding with the name and base java type + * + * @param name The name of the databinding + * @param aliases The aliases of the databinding + * @param baseType The base java class or interface representing the + * databinding, for example, org.w3c.dom.Node + */ + protected BaseDataBinding(String name, String[] aliases, Class baseType) { + this.name = name; + this.baseType = baseType; + this.aliases = aliases; + } + + @SuppressWarnings("unchecked") + public boolean introspect(DataType type, Annotation[] annotations) { + assert type != null; + Class cls = type.getPhysical(); + if (baseType != null && baseType.isAssignableFrom(cls)) { + type.setDataBinding(getName()); + type.setLogical(baseType); + return true; + } + return false; + } + + public DataType introspect(Object value) { + if (value == null) { + return null; + } else { + DataType dataType = new DataTypeImpl(value.getClass(), value.getClass()); + if (introspect(dataType, 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 ExceptionHandler getExceptionHandler() { + return null; + } + + public Object copy(Object object) { + return object; + } + + public SimpleTypeMapper getSimpleTypeMapper() { + return new SimpleTypeMapperImpl(); + } + + public String[] getAliases() { + return aliases; + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/BaseTransformer.java b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/BaseTransformer.java new file mode 100644 index 0000000000..0efb7e41b5 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/DOMHelper.java b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/DOMHelper.java new file mode 100644 index 0000000000..65dd772708 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/DOMHelper.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.impl; + +import javax.xml.namespace.QName; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; + +/** + * Helper for DOM + */ +public final class DOMHelper { + private static DocumentBuilderFactory FACTORY; + + private DOMHelper() { + } + + public static Document newDocument() throws ParserConfigurationException { + return newDocumentBuilder().newDocument(); + } + + public static DocumentBuilder newDocumentBuilder() throws ParserConfigurationException { + init(); + return FACTORY.newDocumentBuilder(); + } + + /** + * + */ + private synchronized static 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); + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/DirectedGraph.java b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/DirectedGraph.java new file mode 100755 index 0000000000..6ecc1c6cd8 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/DirectedGraph.java @@ -0,0 +1,363 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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.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; + +/** + * Directed, weighted graph + * + * @param The type of vertex object + * @param The type of edge object + */ +public class DirectedGraph { + 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; + } + + } + + private final Map paths = 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 Vertex(V value) { + this.value = value; + } + + @Override + public String toString() { + return "(" + value + ")"; + } + + public V getValue() { + return value; + } + + public Map getOutEdges() { + return outEdges; + } + + } + + /** + * An Edge connects two vertices in one direction + */ + public final class Edge { + private Vertex sourceVertex; + + private Vertex targetVertex; + + private E value; + + private int weight; + + public Edge(Vertex source, Vertex target, E value, int weight) { + this.sourceVertex = source; + this.targetVertex = target; + this.value = value; + this.weight = weight; + } + + @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; + } + } + + 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) { + 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); + s.outEdges.put(t, edge); + } + + 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; + + } + + public Edge getEdge(Vertex source, Vertex target) { + return source.outEdges.get(target); + } + + public Edge getEdge(V source, V target) { + return getEdge(getVertex(source), getVertex(target)); + } + + /** + * Get the shortes 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); + if (paths.containsKey(pair)) { + return paths.get(pair); + } + + // HACK: To support same vertex + if (source == target) { + Path path = new Path(); + Edge edge = getEdge(source, target); + if (edge != null) { + path.addEdge(edge); + } + 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(); + while (!otherNodes.isEmpty()) { + Node nextNode = extractMin(otherNodes); + if (nextNode.vertex == target) { + Path path = getPath(nextNode); + paths.put(pair, path); // Cache it + return path; + } + nodesOnPath.add(nextNode); + for (Edge edge : nextNode.vertex.outEdges.values()) { + Node adjacentNode = nodes.get(edge.targetVertex); + if (nextNode.distance + edge.weight < adjacentNode.distance) { + adjacentNode.distance = nextNode.distance + edge.weight; + adjacentNode.previous = nextNode; + } + } + } + paths.put(pair, null); // 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 = 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); + } + } + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/Group2GroupTransformer.java b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/Group2GroupTransformer.java new file mode 100644 index 0000000000..d1dd6f28f0 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/Group2GroupTransformer.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.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 + */ +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/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/GroupDataBinding.java b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/GroupDataBinding.java new file mode 100644 index 0000000000..0cc87f8325 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/GroupDataBinding.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.impl; + +import java.lang.annotation.Annotation; +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; + +import org.apache.tuscany.sca.interfacedef.DataType; + +/** + * 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, null, GroupDataBinding.class); + this.markerTypes = types; + } + + @SuppressWarnings("unchecked") + @Override + public boolean introspect(DataType type, Annotation[] annotations) { + 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)); + type.setLogical(getLogical(cls, annotations)); + 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 annotations + * @return + */ + protected abstract Object getLogical(Class type, Annotation[] annotations); + +} diff --git a/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/Java2SimpleTypeTransformer.java b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/Java2SimpleTypeTransformer.java new file mode 100644 index 0000000000..50b5bf6e8d --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/Java2SimpleTypeTransformer.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.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 + */ +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/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/MediatorImpl.java b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/MediatorImpl.java new file mode 100644 index 0000000000..e995d17fd9 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/MediatorImpl.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.databinding.impl; + +import java.util.List; +import java.util.Map; + +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.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; + +/** + * Default Mediator implementation + */ +public class MediatorImpl implements Mediator { + + private DataBindingExtensionPoint dataBindings; + private TransformerExtensionPoint transformers; + + public MediatorImpl(DataBindingExtensionPoint dataBindings, TransformerExtensionPoint transformers) { + this.dataBindings = dataBindings; + this.transformers = transformers; + } + + @SuppressWarnings("unchecked") + public Object mediate(Object source, DataType sourceDataType, DataType targetDataType, Map metadata) { + if (sourceDataType == null || sourceDataType.getDataBinding() == null) { + sourceDataType = dataBindings.introspectType(source); + } + if (sourceDataType == 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 + ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); + TransformationContext context = new TransformationContextImpl(sourceType, targetType, classLoader, metadata); + 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) { + sourceDataType = dataBindings.introspectType(source); + } + 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"); + ex.setSourceDataBinding(sourceId); + ex.setTargetDataBinding(targetId); + throw ex; + } + return path; + } + + public DataBindingExtensionPoint getDataBindings() { + return dataBindings; + } + + public TransformerExtensionPoint getTransformers() { + return transformers; + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/PipedTransformer.java b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/PipedTransformer.java new file mode 100755 index 0000000000..e2db8c5834 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/PipedTransformer.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.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 Intermidate type + * @param Result type + */ +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/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/ServiceConfigurationUtil.java b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/ServiceConfigurationUtil.java new file mode 100644 index 0000000000..79e68a4f3b --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/ServiceConfigurationUtil.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.databinding.impl; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.URL; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.StringTokenizer; + +public class ServiceConfigurationUtil { + + /** + * Read the service name from a configuration file + * + * @param classLoader + * @param name The name of the service class + * @return A class name which extends/implements the service class + * @throws IOException + */ + public static List getServiceClassNames(ClassLoader classLoader, String name) throws IOException { + List classNames = new ArrayList(); + for (URL url: Collections.list(classLoader.getResources("META-INF/services/" + name))) { + InputStream is = url.openStream(); + BufferedReader reader = null; + try { + reader = new BufferedReader(new InputStreamReader(is)); + while (true) { + String line = reader.readLine(); + if (line == null) + break; + line = line.trim(); + if (!line.startsWith("#") && !"".equals(line)) { + classNames.add(line.trim()); + } + } + } finally { + if (reader != null) + reader.close(); + if (is != null) { + try { + is.close(); + } catch (IOException ioe) {} + } + } + } + return classNames; + } + + /** + * Parse a service declaration in the form class;attr=value,attr=value and + * return a map of attributes + * + * @param declaration + * @return a map of attributes + */ + public static Map parseServiceDeclaration(String declaration) { + Map attributes = new HashMap(); + StringTokenizer tokens = new StringTokenizer(declaration); + String className = tokens.nextToken(";"); + if (className != null) + attributes.put("class", className); + for (; tokens.hasMoreTokens(); ) { + String key = tokens.nextToken("=").substring(1); + if (key == null) + break; + String value = tokens.nextToken(",").substring(1); + if (value == null) + break; + attributes.put(key, value); + } + return attributes; + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/SimpleType2JavaTransformer.java b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/SimpleType2JavaTransformer.java new file mode 100644 index 0000000000..5d7776fa78 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/SimpleType2JavaTransformer.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.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 + */ +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 + public Class getTargetType() { + return Object.class; + } + + @Override + public int getWeight() { + // Cannot be used for imtermediate + 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/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/SimpleTypeMapperImpl.java b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/SimpleTypeMapperImpl.java new file mode 100644 index 0000000000..c36ebb04c5 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/SimpleTypeMapperImpl.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.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; + +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 (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/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/TransformationContextImpl.java b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/TransformationContextImpl.java new file mode 100755 index 0000000000..058b037703 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/TransformationContextImpl.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.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(); + //FIXME The classloader should be passed in + 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 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/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/XSDDataTypeConverter.java b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/XSDDataTypeConverter.java new file mode 100644 index 0000000000..310d1e6c00 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/XSDDataTypeConverter.java @@ -0,0 +1,943 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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 + */ +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/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/DOMNode2JavaBeanTransformer.java b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/DOMNode2JavaBeanTransformer.java new file mode 100644 index 0000000000..31a36f6fdd --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/DOMNode2JavaBeanTransformer.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 java.util.ArrayList; +import java.util.List; + +import org.w3c.dom.Document; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +/** + * Transformer to convert data from DOM Node to JavaBean + */ +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 List 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; + } + + @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 Class getSourceType() { + return Node.class; + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/Java2XMLMapperException.java b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/Java2XMLMapperException.java new file mode 100644 index 0000000000..050c4288c3 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/Java2XMLMapperException.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.javabeans; + +import javax.xml.namespace.QName; + +/** + * This exception is used to encapsulate and rethrow exceptions that arise out + * of converting JavaBean objects to XML + */ +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/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/JavaBean2DOMNodeTransformer.java b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/JavaBean2DOMNodeTransformer.java new file mode 100644 index 0000000000..056eea58d6 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/JavaBean2DOMNodeTransformer.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.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 + */ +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 Node createText(String textData) throws Java2XMLMapperException { + if (textData != null) { + return factory.createTextNode(textData); + } else { + Attr nil = factory.createAttributeNS("http://www.w3.org/2001/XMLSchema-instance", "xsi:nil"); + nil.setValue("true"); + return nil; + } + } + + @Override + public Class getTargetType() { + return Node.class; + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/JavaBean2XMLStreamReader.java b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/JavaBean2XMLStreamReader.java new file mode 100644 index 0000000000..a0a9493551 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/JavaBean2XMLStreamReader.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.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.BeanUtil; +import org.apache.tuscany.sca.databinding.xml.XMLDocumentStreamReader; + +public class JavaBean2XMLStreamReader extends BaseTransformer implements + PullTransformer { + + public XMLStreamReader transform(Object source, TransformationContext context) { + try { + return new XMLDocumentStreamReader(BeanUtil.getXMLStreamReader(source)); + } catch (Exception e) { + throw new TransformationException(e); + } + } + + @Override + public Class getSourceType() { + return Object.class; + } + + @Override + public Class getTargetType() { + return XMLStreamReader.class; + } + + @Override + public int getWeight() { + return 50; + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/JavaBean2XMLTransformer.java b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/JavaBean2XMLTransformer.java new file mode 100644 index 0000000000..1f64a6aa82 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/JavaBean2XMLTransformer.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.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; + +/** + * Transformer to convert data from a JavaBean object to xml + */ +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) { + + //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)) { + appendChild(parent, createText(mapper.toXMLLiteral(null, javaObject, context))); + } else if (javaType.isArray()) { + boolean arrayDone = false; + Object arrayObject = null; + for (int count = 0; !arrayDone; ++count) { + try { + arrayObject = Array.get(javaObject, count); + element = createElement(elementName); + appendChild(parent, element); + appendChildElements(element, + elementName, + javaType.getComponentType(), + arrayObject, + context); + } catch (ArrayIndexOutOfBoundsException e1) { + arrayDone = true; + } + } + } 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.getDeclaredMethods(); + String fieldName = null; + for (Method aMethod : methods) { + try { + if (Modifier.isPublic(aMethod.getModifiers()) && aMethod.getName().startsWith(GET) + && aMethod.getParameterTypes().length == 0) { + 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; + } + } + } + } + } + + @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; + } + + public abstract T createElement(QName qName) throws Java2XMLMapperException; + public abstract T createText(String textData) throws Java2XMLMapperException; + public abstract void appendChild(T parentElement, T childElement) throws Java2XMLMapperException; +} diff --git a/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/JavaBeansDataBinding.java b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/JavaBeansDataBinding.java new file mode 100644 index 0000000000..f7b684e227 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/JavaBeansDataBinding.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.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 org.apache.tuscany.sca.databinding.ExceptionHandler; +import org.apache.tuscany.sca.databinding.impl.BaseDataBinding; + +/** + * DataBinding for JavaBeans + */ +public class JavaBeansDataBinding extends BaseDataBinding { + /** + * 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 = Object.class.getName(); + + public JavaBeansDataBinding() { + super(NAME, Object.class); + } + + @Override + public Object copy(Object arg) { + if (arg == null) { + return null; + } + final Class clazz = arg.getClass(); + if (String.class == clazz || clazz.isPrimitive() + || Number.class.isAssignableFrom(clazz) + || Boolean.class.isAssignableFrom(clazz) + || Character.class.isAssignableFrom(clazz) + || Byte.class.isAssignableFrom(clazz)) { + // Immutable classes + return arg; + } + try { + if (arg instanceof Serializable) { + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + ObjectOutputStream oos = getObjectOutputStream(bos); + oos.writeObject(arg); + oos.close(); + bos.close(); + + ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray()); + ObjectInputStream ois = getObjectInputStream(bis, clazz.getClassLoader()); + Object objectCopy = ois.readObject(); + ois.close(); + bis.close(); + return objectCopy; + } else { + // return arg; + throw new IllegalArgumentException("Argument type '" + arg.getClass().getCanonicalName() + "' is not Serializable. " + + " Pass-by-value cannot be performed on this argument"); + } + } catch (Exception e) { + throw new IllegalArgumentException("Pass-by-value is not supported for the given object", e); + } + } + + @Override + public ExceptionHandler getExceptionHandler() { + return new JavaBeansExceptionHandler(); + } + + protected ObjectOutputStream getObjectOutputStream(OutputStream os) throws IOException { + return new ObjectOutputStream(os); + } + + protected ObjectInputStream getObjectInputStream(InputStream is, final ClassLoader cl) throws IOException { + ObjectInputStream ois = new ObjectInputStream(is) { + @Override + protected Class resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException { + try { + return Class.forName(desc.getName(), false, cl); + } catch (ClassNotFoundException e) { + return super.resolveClass(desc); + } + } + + }; + return ois; + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/JavaBeansExceptionHandler.java b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/JavaBeansExceptionHandler.java new file mode 100644 index 0000000000..8c704b6df2 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/JavaBeansExceptionHandler.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.javabeans; + +import org.apache.tuscany.sca.databinding.ExceptionHandler; +import org.apache.tuscany.sca.interfacedef.DataType; + +/** + * Simple excecption handler for the JavaBeans data binding. + */ +public class JavaBeansExceptionHandler implements ExceptionHandler { + + public Exception createException(DataType exceptionType, String message, Object faultInfo, Throwable cause) { + if (faultInfo instanceof Exception) { + return (Exception)faultInfo; + } + return null; + } + + public Object getFaultInfo(Exception exception) { + return exception; + } + + public DataType getFaultType(DataType exceptionDataType) { + // We only handle faults that have been explicitly associated with the + // JavaBeansDataBinding by the DefaultDataBindingExtensionPoint. + if (JavaBeansDataBinding.NAME.equals(exceptionDataType.getDataBinding())) { + return exceptionDataType; + } + return null; + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/SimpleJavaDataBinding.java b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/SimpleJavaDataBinding.java new file mode 100644 index 0000000000..1fe75f1de9 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/SimpleJavaDataBinding.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.javabeans; + +import java.lang.annotation.Annotation; + +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.util.XMLType; + +/** + * DataBinding for Java simple types + */ +public class SimpleJavaDataBinding extends BaseDataBinding { + public static final String NAME = "java:simpleType"; + + public SimpleJavaDataBinding() { + super(NAME, Object.class); + } + + @Override + public Object copy(Object arg) { + return arg; + } + + @Override + public boolean introspect(DataType type, Annotation[] annotations) { + 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) || XMLStringDataBinding.ALIASES[0].equals(db))) { + return false; + } + if (SimpleTypeMapperImpl.JAVA2XML.keySet().contains(cls)) { + type.setDataBinding(getName()); + type.setLogical(new XMLType(SimpleTypeMapperImpl.getXMLType(cls))); + return true; + } else { + return false; + } + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/XML2JavaBeanTransformer.java b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/XML2JavaBeanTransformer.java new file mode 100644 index 0000000000..76f51c4ef0 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/XML2JavaBeanTransformer.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.javabeans; + +import java.lang.reflect.Array; +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.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 + */ +public abstract class XML2JavaBeanTransformer extends BaseTransformer implements + PullTransformer { + + public static final String SET = "set"; + + protected SimpleTypeMapperImpl mapper; + + public XML2JavaBeanTransformer() { + this.mapper = new SimpleTypeMapperImpl(); + } + + @Override + public int getWeight() { + return JavaBeansDataBinding.HEAVY_WEIGHT; + } + + public Object transform(T source, TransformationContext context) { + XMLType xmlType = (XMLType) context.getSourceDataType().getLogical(); + return toJavaObject(xmlType.getTypeName(), getRootElement(source), context); + } + + public Object toJavaObject(QName xmlType, T xmlElement, TransformationContext context) { + if (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 { + List childElements = getChildElements(element); + if (childElements.size() == 1 && isTextElement(childElements.get(0))) { + return (L) mapper.toJavaObject(mapper.getXMLType(javaType).getQName(), + getText(childElements.get(0)), + context); + } else { + String fieldName = null; + try { + L javaInstance = javaType.newInstance(); + Map> arrayFields = new Hashtable>(); + Map> arraySetters = new Hashtable>(); + for (int count = 0; count < childElements.size(); ++count) { + if (!isTextElement(childElements.get(count))) { + fieldName = getElementName(childElements.get(count)); + try { + Field javaField = javaType.getField(fieldName); + setFieldValue(javaInstance, + javaField, + childElements.get(count), + arrayFields, + context); + + } catch (NoSuchFieldException e1) { + setFieldValueUsingSetter(javaType, + javaInstance, + fieldName, + childElements.get(count), + 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 List getChildElements(T parent) throws XML2JavaMapperException; + + public abstract String getElementName(T element) throws XML2JavaMapperException; + + public abstract boolean isTextElement(T element) throws XML2JavaMapperException; + + public abstract T getRootElement(T element) throws XML2JavaMapperException; + + @Override + public Class getTargetType() { + return Object.class; + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/XML2JavaMapperException.java b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/XML2JavaMapperException.java new file mode 100644 index 0000000000..b7dee262c0 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/XML2JavaMapperException.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.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. + */ +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/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/BeanUtil.java b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/BeanUtil.java new file mode 100644 index 0000000000..3c39c8d4cc --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/BeanUtil.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.databinding.xml; + +import java.beans.BeanInfo; +import java.beans.Introspector; +import java.beans.PropertyDescriptor; +import java.lang.reflect.Array; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.sca.databinding.impl.SimpleTypeMapperImpl; +import org.apache.tuscany.sca.interfacedef.util.TypeInfo; + +public final class BeanUtil { + private static final Object[] NULL = null; + private static int nsCount = 1; + + private static final SimpleTypeMapperImpl MAPPER = new SimpleTypeMapperImpl(); + + private BeanUtil() { + } + + 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); + } + } + + /** + * To Serilize Bean object this method is used, this will create an object + * array using given bean object + * + * @param beanObject + * @param beanName + */ + public static XMLStreamReader getXMLStreamReader(Object beanObject, QName beanName) { + try { + ClassLoader cl = beanObject.getClass().getClassLoader(); + if (cl == null) { + //FIXME Wouldn't it be better to use the current thread context + // classloader? + cl = ClassLoader.getSystemClassLoader(); + } + String beanNS = beanName.getNamespaceURI(); + String beanPrefix = beanName.getPrefix(); + BeanInfo beanInfo = Introspector.getBeanInfo(beanObject.getClass()); + PropertyDescriptor[] propDescs = beanInfo.getPropertyDescriptors(); + Map propertMap = new HashMap(); + for (int i = 0; i < propDescs.length; i++) { + PropertyDescriptor propDesc = propDescs[i]; + propertMap.put(propDesc.getName(), propDesc); + } + List properties = new ArrayList(propertMap.keySet()); + Collections.sort(properties); + List props = new ArrayList(); + for (int i = 0; i < properties.size(); i++) { + String property = properties.get(i); + PropertyDescriptor propDesc = propertMap.get(property); + if (propDesc == null) { + // JAM does bad thing so I need to add this + continue; + } + Class ptype = propDesc.getPropertyType(); + if ("class".equals(property)) { + continue; + } + if (isSimpleType(ptype)) { + Object value = propDesc.getReadMethod().invoke(beanObject, NULL); + NamedProperty prop = + new NamedProperty(new QName(beanNS, property, beanPrefix), getStringValue(value)); + props.add(prop); + } else if (ptype.isArray()) { + if (isSimpleType(ptype.getComponentType())) { + Object value = propDesc.getReadMethod().invoke(beanObject, NULL); + if (value != null) { + int i1 = Array.getLength(value); + for (int j = 0; j < i1; j++) { + Object o = Array.get(value, j); + NamedProperty prop = + new NamedProperty(new QName(beanNS, property, beanPrefix), getStringValue(o)); + props.add(prop); + } + } else { + NamedProperty prop = new NamedProperty(new QName(beanNS, property, beanPrefix), value); + props.add(prop); + } + + } else { + Object value[] = (Object[])propDesc.getReadMethod().invoke(beanObject, NULL); + if (value != null) { + for (int j = 0; j < value.length; j++) { + Object o = value[j]; + NamedProperty prop = + new NamedProperty(new QName(beanNS, property, beanPrefix), getStringValue(o)); + props.add(prop); + } + } else { + NamedProperty prop = new NamedProperty(new QName(beanNS, property, beanPrefix), value); + props.add(prop); + } + } + } else if (Collection.class.isAssignableFrom(ptype)) { + Object value = propDesc.getReadMethod().invoke(beanObject, NULL); + Collection objList = (Collection)value; + if (objList != null && objList.size() > 0) { + // this was given error , when the array.size = 0 + // and if the array contain simple type , then the + // ADBPullParser asked + // PullParser from That simpel type + for (Iterator j = objList.iterator(); j.hasNext();) { + Object o = j.next(); + if (isSimpleType(o.getClass())) { + NamedProperty prop = + new NamedProperty(new QName(beanNS, property, beanPrefix), getStringValue(o)); + props.add(prop); + } else { + NamedProperty prop = new NamedProperty(new QName(beanNS, property, beanPrefix), o); + props.add(prop); + } + } + + } else { + NamedProperty prop = new NamedProperty(new QName(beanNS, property, beanPrefix), value); + props.add(prop); + } + } else { + Object value = propDesc.getReadMethod().invoke(beanObject, NULL); + NamedProperty prop = new NamedProperty(new QName(beanNS, property, beanPrefix), value); + props.add(prop); + } + } + NamedProperty[] elements = new NamedProperty[props.size()]; + props.toArray(elements); + return new XMLFragmentStreamReaderImpl(beanName, elements, null); + } catch (Exception e) { + throw new IllegalArgumentException(e); + } + } + + /** + * to get the pull parser for a given bean object , generate the wrpper + * element using class name + * + * @param beanObject + */ + public static XMLStreamReader getXMLStreamReader(Object beanObject) { + String className = beanObject.getClass().getName(); + if (className.indexOf(".") > 0) { + className = className.substring(className.lastIndexOf('.') + 1, className.length()); + } + return getXMLStreamReader(beanObject, new QName(className)); + } + + /** + * increments the namespace counter and returns a new prefix + * + * @return unique prefix + */ + public static String getUniquePrefix() { + return "s" + nsCount++; + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/DOMDataBinding.java b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/DOMDataBinding.java new file mode 100644 index 0000000000..9e3d352ac8 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/DOMDataBinding.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.xml; + + +import java.lang.annotation.Annotation; + +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.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[] ALIASES = new String[] {"dom"}; + + 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, ALIASES, Node.class); + } + + @Override + public WrapperHandler getWrapperHandler() { + return new DOMWrapperHandler(); + } + + @Override + public Object copy(Object source) { + if (Node.class.isAssignableFrom(source.getClass())) { + Node nodeSource = (Node) source; + return nodeSource.cloneNode(true); + } + return super.copy(source); + } + + @Override + public boolean introspect(DataType type, Annotation[] annotations) { + if(Node.class.isAssignableFrom(type.getPhysical())) { + type.setLogical(new XMLType(ROOT_ELEMENT, null)); + return true; + } + return false; + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/DOMWrapperHandler.java b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/DOMWrapperHandler.java new file mode 100644 index 0000000000..849912dc80 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/DOMWrapperHandler.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.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.TransformationContext; +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.impl.DataTypeImpl; +import org.apache.tuscany.sca.interfacedef.util.ElementInfo; +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(ElementInfo element, TransformationContext context) { + try { + Document document = DOMHelper.newDocument(); + QName name = element.getQName(); + return DOMHelper.createElement(document, name); + } catch (ParserConfigurationException e) { + throw new TransformationException(e); + } + } + + 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, List childElements, TransformationContext context) { + assert wrapper != null; + 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(org.apache.tuscany.sca.interfacedef.util.ElementInfo, List, org.apache.tuscany.sca.databinding.TransformationContext) + */ + public DataType getWrapperType(ElementInfo element, List childElements, TransformationContext context) { + DataType wrapperType = + new DataTypeImpl(DOMDataBinding.NAME, Node.class, new XMLType(element)); + return wrapperType; + } + + public boolean isInstance(Object wrapperObj, + ElementInfo element, + List childElements, + TransformationContext context) { + 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/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/DOMXMLStreamReader.java b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/DOMXMLStreamReader.java new file mode 100644 index 0000000000..e377dd1d8b --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/DOMXMLStreamReader.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.xml; + +import static javax.xml.XMLConstants.DEFAULT_NS_PREFIX; +import static javax.xml.XMLConstants.XMLNS_ATTRIBUTE_NS_URI; + +import java.util.ArrayList; +import java.util.List; + +import javax.xml.namespace.QName; + +import org.w3c.dom.Attr; +import org.w3c.dom.CharacterData; +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; + +public class DOMXMLStreamReader extends XMLFragmentStreamReaderImpl { + private Element rootElement; + + public DOMXMLStreamReader(Node node) { + super(null); + switch (node.getNodeType()) { + case Node.DOCUMENT_NODE: + this.rootElement = ((Document)node).getDocumentElement(); + break; + case Node.ELEMENT_NODE: + this.rootElement = (Element)node; + break; + default: + throw new IllegalArgumentException("Illegal Node"); + } + String ns = rootElement.getNamespaceURI(); + String prefix = rootElement.getPrefix(); + String name = rootElement.getLocalName(); + elementQName = new QName(ns == null ? "" : ns, name, prefix == null ? "" : prefix); + } + + @Override + protected final NamedProperty[] getAttributes() { + if (attributes == null) { + List attributeList = new ArrayList(); + NamedNodeMap nodeMap = rootElement.getAttributes(); + for (int i = 0; i < nodeMap.getLength(); i++) { + Attr attr = (Attr)nodeMap.item(i); + String ns = attr.getNamespaceURI(); + String prefix = attr.getPrefix(); + if (!XMLNS_ATTRIBUTE_NS_URI.equals(ns)) { + QName attrName = new QName(ns == null ? "" : ns, attr.getLocalName(), prefix != null ? prefix : ""); + NamedProperty pair = new NamedProperty(attrName, attr.getValue()); + attributeList.add(pair); + } + } + attributes = new NamedProperty[attributeList.size()]; + attributeList.toArray(attributes); + } + return attributes; + } + + @Override + protected QName[] getNamespaces() { + List nsList = new ArrayList(); + NamedNodeMap nodeMap = rootElement.getAttributes(); + for (int i = 0; i < nodeMap.getLength(); i++) { + Attr attr = (Attr)nodeMap.item(i); + String ns = attr.getNamespaceURI(); + if (XMLNS_ATTRIBUTE_NS_URI.equals(ns)) { + String prefix = attr.getPrefix(); + if (prefix == null) { + // xmlns="http://ns" + nsList.add(new QName(attr.getValue(), "", DEFAULT_NS_PREFIX)); + } else { + // xmlns:ns="http://ns" + nsList.add(new QName(attr.getValue(), "", attr.getLocalName())); + } + } + } + QName[] nss = new QName[nsList.size()]; + nsList.toArray(nss); + return nss; + } + + @Override + protected NamedProperty[] getElements() { + if (elements == null) { + List elementList = new ArrayList(); + NodeList nodeList = rootElement.getChildNodes(); + for (int i = 0; i < nodeList.getLength(); i++) { + Node node = nodeList.item(i); + switch (node.getNodeType()) { + case Node.TEXT_NODE: + case Node.CDATA_SECTION_NODE: + NamedProperty pair = new NamedProperty(ELEMENT_TEXT, ((CharacterData)node).getData()); + elementList.add(pair); + break; + + case Node.ELEMENT_NODE: + Element element = (Element)node; + QName elementName = new QName(element.getNamespaceURI(), element.getLocalName()); + pair = new NamedProperty(elementName, new DOMXMLStreamReader(element)); + elementList.add(pair); + break; + } + } + elements = new NamedProperty[elementList.size()]; + elementList.toArray(elements); + } + return elements; + } +} diff --git a/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/DelegatingNamespaceContext.java b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/DelegatingNamespaceContext.java new file mode 100644 index 0000000000..40d5c07499 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/InputSource2Node.java b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/InputSource2Node.java new file mode 100644 index 0000000000..2a6094a76a --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/InputSource2Node.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 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 + */ +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/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/InputSource2SAX.java b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/InputSource2SAX.java new file mode 100644 index 0000000000..d842048d81 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/InputSource2SAX.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 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 + */ +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/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/InputStream2Node.java b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/InputStream2Node.java new file mode 100644 index 0000000000..2ec864fbbd --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/InputStream2Node.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.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 + */ +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/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/InputStream2SAX.java b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/InputStream2SAX.java new file mode 100644 index 0000000000..06b2521d47 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/InputStream2SAX.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.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 + */ +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/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/NameValueArrayStreamReader.java b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/NameValueArrayStreamReader.java new file mode 100644 index 0000000000..157a95025d --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/NameValuePairStreamReader.java b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/NameValuePairStreamReader.java new file mode 100644 index 0000000000..71af7519e7 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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 attribs 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/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/NamedProperty.java b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/NamedProperty.java new file mode 100644 index 0000000000..04d7d65a0d --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/NilElementStreamReader.java b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/NilElementStreamReader.java new file mode 100644 index 0000000000..abc4bf3785 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Node2OutputStream.java b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Node2OutputStream.java new file mode 100644 index 0000000000..3e20e0be70 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Node2OutputStream.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.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 + */ +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 + public Class getSourceType() { + return Node.class; + } + + @Override + public Class getTargetType() { + return OutputStream.class; + } + + @Override + public int getWeight() { + return 40; + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Node2SimpleJavaType.java b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Node2SimpleJavaType.java new file mode 100644 index 0000000000..f20cd4f901 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Node2SimpleJavaType.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.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 bject to OMElement + */ +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/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Node2String.java b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Node2String.java new file mode 100755 index 0000000000..b07e6eb955 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Node2String.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.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 + */ +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/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Node2Writer.java b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Node2Writer.java new file mode 100644 index 0000000000..2b26c11d50 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Node2Writer.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 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 + */ +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 + public Class getSourceType() { + return Node.class; + } + + @Override + public Class getTargetType() { + return Writer.class; + } + + @Override + public int getWeight() { + return 40; + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Node2XMLStreamReader.java b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Node2XMLStreamReader.java new file mode 100644 index 0000000000..e611b0d09d --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Node2XMLStreamReader.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 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 + */ +public class Node2XMLStreamReader extends BaseTransformer implements + PullTransformer { + + public XMLStreamReader transform(Node source, TransformationContext context) { + try { + DOMXMLStreamReader reader = new DOMXMLStreamReader(source); + return new XMLDocumentStreamReader(reader); + } catch (Exception e) { + throw new TransformationException(e); + } + } + + @Override + public Class getSourceType() { + return Node.class; + } + + @Override + public Class getTargetType() { + return XMLStreamReader.class; + } + + @Override + public int getWeight() { + return 40; + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Reader2Node.java b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Reader2Node.java new file mode 100644 index 0000000000..aa96877c02 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Reader2Node.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 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 + */ +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 + public Class getSourceType() { + return Reader.class; + } + + @Override + public Class getTargetType() { + return Node.class; + } + + @Override + public int getWeight() { + return 40; + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Reader2SAX.java b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Reader2SAX.java new file mode 100644 index 0000000000..bf8edc47f9 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Reader2SAX.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.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 + */ +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 + public Class getSourceType() { + return Reader.class; + } + + @Override + public Class getTargetType() { + return ContentHandler.class; + } + + @Override + public int getWeight() { + return 40; + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/SAX2DOM.java b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/SAX2DOM.java new file mode 100644 index 0000000000..6cdbc82d9d --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/SAX2DOM.java @@ -0,0 +1,244 @@ +/* + * 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 + */ +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/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/SAX2DOMPipe.java b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/SAX2DOMPipe.java new file mode 100644 index 0000000000..35c20c28c0 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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 + public Class getTargetType() { + return Node.class; + } + + @Override + public 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/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/SimpleJavaType2Node.java b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/SimpleJavaType2Node.java new file mode 100644 index 0000000000..486f1f256a --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/SimpleJavaType2Node.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.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 + */ +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/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Source2ResultTransformer.java b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Source2ResultTransformer.java new file mode 100755 index 0000000000..b502b5003f --- /dev/null +++ b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Source2ResultTransformer.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.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 + */ +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 + public Class getSourceType() { + return Source.class; + } + + @Override + public Class getTargetType() { + return Result.class; + } + + @Override + public int getWeight() { + return 40; + } + +} diff --git a/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/StAX2SAXAdapter.java b/tags/java/sca/1.0-RC1b/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/StAX2SAXAdapter.java new file mode 100644 index 0000000000..6257681091 --- /dev/null +++ b/tags/java/sca/1.0-RC1b/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: + *