From 522eefceb2951721c8a7514ad5a08d8c99fc7997 Mon Sep 17 00:00:00 2001 From: slaws Date: Tue, 18 Nov 2008 11:34:21 +0000 Subject: Equinox branch merge - revert the previous two changes r718541 and r718546 so we are back to the previous flat structure. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@718560 13f79535-47bb-0310-9956-ffa450edef68 --- java/sca/contrib/modules/binding-dwr/LICENSE | 205 ------ java/sca/contrib/modules/binding-dwr/NOTICE | 6 - java/sca/contrib/modules/binding-dwr/pom.xml | 95 --- .../apache/tuscany/sca/binding/dwr/DWRBinding.java | 31 - .../sca/binding/dwr/DWRBindingActivator.java | 56 -- .../apache/tuscany/sca/binding/dwr/DWRInvoker.java | 93 --- .../tuscany/sca/binding/dwr/DWRInvokerFactory.java | 67 -- .../apache/tuscany/sca/binding/dwr/DWRService.java | 81 --- .../apache/tuscany/sca/binding/dwr/DWRServlet.java | 247 ------- ...e.tuscany.sca.extension.helper.BindingActivator | 19 - java/sca/modules/api/LICENSE | 205 ++++++ java/sca/modules/api/NOTICE | 6 + java/sca/modules/api/pom.xml | 304 ++++++++ java/sca/modules/assembly-java-dsl/LICENSE | 205 ++++++ java/sca/modules/assembly-java-dsl/NOTICE | 6 + java/sca/modules/assembly-java-dsl/pom.xml | 56 ++ .../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 | 33 + .../sca/assembly/dsl/StockQuoteService.java | 24 + java/sca/modules/binding-dwr/LICENSE | 205 ++++++ java/sca/modules/binding-dwr/NOTICE | 6 + java/sca/modules/binding-dwr/pom.xml | 95 +++ .../apache/tuscany/sca/binding/dwr/DWRBinding.java | 31 + .../sca/binding/dwr/DWRBindingActivator.java | 56 ++ .../apache/tuscany/sca/binding/dwr/DWRInvoker.java | 93 +++ .../tuscany/sca/binding/dwr/DWRInvokerFactory.java | 67 ++ .../apache/tuscany/sca/binding/dwr/DWRService.java | 81 +++ .../apache/tuscany/sca/binding/dwr/DWRServlet.java | 247 +++++++ ...e.tuscany.sca.extension.helper.BindingActivator | 19 + java/sca/modules/binding-feed/LICENSE | 205 ++++++ java/sca/modules/binding-feed/NOTICE | 6 + java/sca/modules/binding-feed/pom.xml | 165 +++++ .../tuscany/sca/binding/feed/AtomBinding.java | 30 + .../sca/binding/feed/AtomBindingFactory.java | 35 + .../tuscany/sca/binding/feed/RSSBinding.java | 30 + .../sca/binding/feed/RSSBindingFactory.java | 35 + .../sca/binding/feed/collection/Collection.java | 72 ++ .../binding/feed/collection/MediaCollection.java | 55 ++ .../binding/feed/collection/NotFoundException.java | 45 ++ .../binding/feed/impl/AtomBindingFactoryImpl.java | 36 + .../sca/binding/feed/impl/AtomBindingImpl.java | 96 +++ .../binding/feed/impl/RSSBindingFactoryImpl.java | 36 + .../sca/binding/feed/impl/RSSBindingImpl.java | 101 +++ .../binding/feed/provider/AtomBindingInvoker.java | 345 +++++++++ .../feed/provider/AtomBindingProviderFactory.java | 74 ++ .../binding/feed/provider/AtomFeedEntryUtil.java | 117 +++ .../provider/AtomReferenceBindingProvider.java | 116 +++ .../feed/provider/AtomServiceBindingProvider.java | 87 +++ .../feed/provider/FeedBindingListenerServlet.java | 788 +++++++++++++++++++++ .../binding/feed/provider/RSSBindingInvoker.java | 91 +++ .../feed/provider/RSSBindingProviderFactory.java | 74 ++ .../feed/provider/RSSReferenceBindingProvider.java | 65 ++ .../feed/provider/RSSServiceBindingProvider.java | 85 +++ ...che.tuscany.sca.binding.feed.AtomBindingFactory | 19 + ...ache.tuscany.sca.binding.feed.RSSBindingFactory | 19 + ...ca.contribution.processor.StAXArtifactProcessor | 20 + ...che.tuscany.sca.provider.BindingProviderFactory | 20 + .../apache/tuscany/sca/binding/feed/Consumer.java | 35 + .../tuscany/sca/binding/feed/CustomerClient.java | 25 + .../sca/binding/feed/CustomerClientImpl.java | 97 +++ .../sca/binding/feed/CustomerCollectionImpl.java | 136 ++++ .../apache/tuscany/sca/binding/feed/Provider.java | 41 ++ .../tuscany/sca/binding/feed/Consumer.composite | 32 + .../tuscany/sca/binding/feed/Provider.composite | 33 + java/sca/modules/binding-gdata2-runtime/LICENSE | 205 ++++++ java/sca/modules/binding-gdata2-runtime/NOTICE | 6 + .../binding-gdata2-runtime/deployGdataToMaven.sh | 7 + java/sca/modules/binding-gdata2-runtime/pom.xml | 183 +++++ .../sca/binding/gdata/collection/Collection.java | 82 +++ .../binding/gdata/collection/MediaCollection.java | 55 ++ .../gdata/provider/GDataBindingInvoker.java | 510 +++++++++++++ .../provider/GDataBindingListenerServlet.java | 426 +++++++++++ .../provider/GDataBindingProviderFactory.java | 74 ++ .../provider/GDataReferenceBindingProvider.java | 125 ++++ .../provider/GDataServiceBindingProvider.java | 85 +++ ...che.tuscany.sca.provider.BindingProviderFactory | 19 + .../gdata/calendarconsumer/CalendarConsumer.java | 121 ++++ .../calendarconsumer/CalendarConsumerImpl.java | 55 ++ .../calendarconsumer/CalendarConsumerTest.java | 203 ++++++ .../binding/gdata/consumerprovider/Consumer.java | 36 + .../gdata/consumerprovider/CustomerClient.java | 25 + .../gdata/consumerprovider/CustomerClientImpl.java | 117 +++ .../consumerprovider/CustomerCollectionImpl.java | 116 +++ .../binding/gdata/consumerprovider/Provider.java | 34 + .../sca/binding/gdata/CalendarConsumer.composite | 32 + .../tuscany/sca/binding/gdata/Consumer.composite | 32 + .../tuscany/sca/binding/gdata/Provider.composite | 33 + java/sca/modules/binding-gdata2/LICENSE | 205 ++++++ java/sca/modules/binding-gdata2/NOTICE | 6 + java/sca/modules/binding-gdata2/pom.xml | 73 ++ .../tuscany/sca/binding/gdata/GDataBinding.java | 77 ++ .../sca/binding/gdata/GDataBindingFactory.java | 35 + .../gdata/GDataImplementationProcessor.java | 100 +++ .../gdata/impl/GDataBindingFactoryImpl.java | 36 + .../sca/binding/gdata/impl/GDataBindingImpl.java | 137 ++++ ...e.tuscany.sca.binding.gdata.GDataBindingFactory | 19 + ...ca.contribution.processor.StAXArtifactProcessor | 21 + java/sca/modules/core-spring/LICENSE | 205 ++++++ java/sca/modules/core-spring/NOTICE | 6 + java/sca/modules/core-spring/pom.xml | 126 ++++ .../spring/assembly/impl/BeanAssemblyFactory.java | 134 ++++ .../spring/assembly/impl/BeanComponentImpl.java | 233 ++++++ .../spring/assembly/impl/BeanReferenceImpl.java | 70 ++ .../sca/core/spring/context/ModelResolverImpl.java | 88 +++ .../sca/core/spring/context/SCADomainContext.java | 192 +++++ .../java/impl/BeanBaseJavaImplementationImpl.java | 211 ++++++ .../java/impl/BeanJavaImplementationFactory.java | 75 ++ .../java/impl/BeanJavaImplementationImpl.java | 175 +++++ .../java/impl/BeanJavaInterfaceContractImpl.java | 34 + .../java/impl/BeanJavaInterfaceFactory.java | 75 ++ .../java/impl/BeanJavaInterfaceImpl.java | 149 ++++ .../src/test/java/calculator/AddService.java | 30 + .../src/test/java/calculator/AddServiceImpl.java | 37 + .../src/test/java/calculator/CalculatorClient.java | 43 ++ .../test/java/calculator/CalculatorService.java | 36 + .../java/calculator/CalculatorServiceImpl.java | 73 ++ .../src/test/java/calculator/DivideService.java | 30 + .../test/java/calculator/DivideServiceImpl.java | 35 + .../src/test/java/calculator/MultiplyService.java | 30 + .../test/java/calculator/MultiplyServiceImpl.java | 35 + .../java/calculator/NestedCalculatorClient.java | 46 ++ .../src/test/java/calculator/SubtractService.java | 30 + .../test/java/calculator/SubtractServiceImpl.java | 35 + .../sca/core/spring/CalculatorTestCase.java | 56 ++ .../core/spring/NestedCalculatorTestCaseFIXME.java | 59 ++ .../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 ++ java/sca/modules/data-engine-helper/LICENSE | 205 ++++++ java/sca/modules/data-engine-helper/NOTICE | 6 + java/sca/modules/data-engine-helper/pom.xml | 142 ++++ .../engine/ConnectionInfoArtifactProcessor.java | 197 ++++++ .../tuscany/sca/data/engine/DataAccessEngine.java | 286 ++++++++ .../sca/data/engine/DataAccessEngineManager.java | 141 ++++ .../data/engine/MissingConfigFileException.java | 44 ++ .../sca/data/engine/config/ConnectionInfo.java | 47 ++ .../data/engine/config/ConnectionProperties.java | 78 ++ ...ataengine-helper-validation-messages.properties | 21 + java/sca/modules/implementation-bpel-jbpm/LICENSE | 251 +++++++ java/sca/modules/implementation-bpel-jbpm/NOTICE | 17 + java/sca/modules/implementation-bpel-jbpm/pom.xml | 140 ++++ ...cany.sca.provider.ImplementationProviderFactory | 22 + java/sca/modules/monitor-logging/LICENSE | 205 ++++++ java/sca/modules/monitor-logging/NOTICE | 6 + java/sca/modules/monitor-logging/pom.xml | 68 ++ .../logging/impl/DefaultLoggingMonitorImpl.java | 104 +++ .../monitor/logging/impl/MonitorFactoryImpl.java | 41 ++ .../org.apache.tuscany.sca.monitor.MonitorFactory | 18 + .../tuscany/sca/monitor/MonitorTestCase.java | 94 +++ .../tuscany-monitor-test-messages.properties | 24 + .../tuscany-monitor-test-messages_it.properties | 24 + 168 files changed, 13752 insertions(+), 900 deletions(-) delete mode 100644 java/sca/contrib/modules/binding-dwr/LICENSE delete mode 100644 java/sca/contrib/modules/binding-dwr/NOTICE delete mode 100644 java/sca/contrib/modules/binding-dwr/pom.xml delete mode 100644 java/sca/contrib/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRBinding.java delete mode 100644 java/sca/contrib/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRBindingActivator.java delete mode 100644 java/sca/contrib/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRInvoker.java delete mode 100644 java/sca/contrib/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRInvokerFactory.java delete mode 100644 java/sca/contrib/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRService.java delete mode 100644 java/sca/contrib/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRServlet.java delete mode 100644 java/sca/contrib/modules/binding-dwr/src/main/resources/META-INF/services/org.apache.tuscany.sca.extension.helper.BindingActivator create mode 100644 java/sca/modules/api/LICENSE create mode 100644 java/sca/modules/api/NOTICE create mode 100644 java/sca/modules/api/pom.xml create mode 100644 java/sca/modules/assembly-java-dsl/LICENSE create mode 100644 java/sca/modules/assembly-java-dsl/NOTICE create mode 100644 java/sca/modules/assembly-java-dsl/pom.xml create mode 100644 java/sca/modules/assembly-java-dsl/src/main/java/org/apache/tuscany/sca/assembly/dsl/AssemblyBuilder.java create mode 100644 java/sca/modules/assembly-java-dsl/src/main/java/org/apache/tuscany/sca/assembly/dsl/ComponentBuilder.java create mode 100644 java/sca/modules/assembly-java-dsl/src/main/java/org/apache/tuscany/sca/assembly/dsl/ComponentPropertyBuilder.java create mode 100644 java/sca/modules/assembly-java-dsl/src/main/java/org/apache/tuscany/sca/assembly/dsl/ComponentReferenceBuilder.java create mode 100644 java/sca/modules/assembly-java-dsl/src/main/java/org/apache/tuscany/sca/assembly/dsl/ComponentServiceBuilder.java create mode 100644 java/sca/modules/assembly-java-dsl/src/main/java/org/apache/tuscany/sca/assembly/dsl/CompositeBuilder.java create mode 100644 java/sca/modules/assembly-java-dsl/src/main/java/org/apache/tuscany/sca/assembly/dsl/impl/AssemblyBuilderImpl.java create mode 100644 java/sca/modules/assembly-java-dsl/src/main/java/org/apache/tuscany/sca/assembly/dsl/impl/ComponentBuilderImpl.java create mode 100644 java/sca/modules/assembly-java-dsl/src/main/java/org/apache/tuscany/sca/assembly/dsl/impl/ComponentPropertyBuilderImpl.java create mode 100644 java/sca/modules/assembly-java-dsl/src/main/java/org/apache/tuscany/sca/assembly/dsl/impl/ComponentReferenceBuilderImpl.java create mode 100644 java/sca/modules/assembly-java-dsl/src/main/java/org/apache/tuscany/sca/assembly/dsl/impl/ComponentServiceBuilderImpl.java create mode 100644 java/sca/modules/assembly-java-dsl/src/main/java/org/apache/tuscany/sca/assembly/dsl/impl/CompositeBuilderImpl.java create mode 100644 java/sca/modules/assembly-java-dsl/src/test/java/org/apache/tuscany/sca/assembly/dsl/AccountDataService.java create mode 100644 java/sca/modules/assembly-java-dsl/src/test/java/org/apache/tuscany/sca/assembly/dsl/AccountDataServiceImpl.java create mode 100644 java/sca/modules/assembly-java-dsl/src/test/java/org/apache/tuscany/sca/assembly/dsl/AccountService.java create mode 100644 java/sca/modules/assembly-java-dsl/src/test/java/org/apache/tuscany/sca/assembly/dsl/AccountServiceImpl.java create mode 100644 java/sca/modules/assembly-java-dsl/src/test/java/org/apache/tuscany/sca/assembly/dsl/BigBankBuilder.java create mode 100644 java/sca/modules/assembly-java-dsl/src/test/java/org/apache/tuscany/sca/assembly/dsl/BigBankBuilderTestCase.java create mode 100644 java/sca/modules/assembly-java-dsl/src/test/java/org/apache/tuscany/sca/assembly/dsl/StockQuoteService.java create mode 100644 java/sca/modules/binding-dwr/LICENSE create mode 100644 java/sca/modules/binding-dwr/NOTICE create mode 100644 java/sca/modules/binding-dwr/pom.xml create mode 100644 java/sca/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRBinding.java create mode 100644 java/sca/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRBindingActivator.java create mode 100644 java/sca/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRInvoker.java create mode 100644 java/sca/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRInvokerFactory.java create mode 100644 java/sca/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRService.java create mode 100644 java/sca/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRServlet.java create mode 100644 java/sca/modules/binding-dwr/src/main/resources/META-INF/services/org.apache.tuscany.sca.extension.helper.BindingActivator create mode 100644 java/sca/modules/binding-feed/LICENSE create mode 100644 java/sca/modules/binding-feed/NOTICE create mode 100644 java/sca/modules/binding-feed/pom.xml create mode 100644 java/sca/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/AtomBinding.java create mode 100644 java/sca/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/AtomBindingFactory.java create mode 100644 java/sca/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/RSSBinding.java create mode 100644 java/sca/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/RSSBindingFactory.java create mode 100644 java/sca/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/collection/Collection.java create mode 100644 java/sca/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/collection/MediaCollection.java create mode 100644 java/sca/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/collection/NotFoundException.java create mode 100644 java/sca/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/impl/AtomBindingFactoryImpl.java create mode 100644 java/sca/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/impl/AtomBindingImpl.java create mode 100644 java/sca/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/impl/RSSBindingFactoryImpl.java create mode 100644 java/sca/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/impl/RSSBindingImpl.java create mode 100644 java/sca/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/AtomBindingInvoker.java create mode 100644 java/sca/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/AtomBindingProviderFactory.java create mode 100644 java/sca/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/AtomFeedEntryUtil.java create mode 100644 java/sca/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/AtomReferenceBindingProvider.java create mode 100644 java/sca/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/AtomServiceBindingProvider.java create mode 100644 java/sca/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/FeedBindingListenerServlet.java create mode 100644 java/sca/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/RSSBindingInvoker.java create mode 100644 java/sca/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/RSSBindingProviderFactory.java create mode 100644 java/sca/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/RSSReferenceBindingProvider.java create mode 100644 java/sca/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/RSSServiceBindingProvider.java create mode 100644 java/sca/modules/binding-feed/src/main/resources/META-INF/services/org.apache.tuscany.sca.binding.feed.AtomBindingFactory create mode 100644 java/sca/modules/binding-feed/src/main/resources/META-INF/services/org.apache.tuscany.sca.binding.feed.RSSBindingFactory create mode 100644 java/sca/modules/binding-feed/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor create mode 100644 java/sca/modules/binding-feed/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory create mode 100644 java/sca/modules/binding-feed/src/test/java/org/apache/tuscany/sca/binding/feed/Consumer.java create mode 100644 java/sca/modules/binding-feed/src/test/java/org/apache/tuscany/sca/binding/feed/CustomerClient.java create mode 100644 java/sca/modules/binding-feed/src/test/java/org/apache/tuscany/sca/binding/feed/CustomerClientImpl.java create mode 100644 java/sca/modules/binding-feed/src/test/java/org/apache/tuscany/sca/binding/feed/CustomerCollectionImpl.java create mode 100644 java/sca/modules/binding-feed/src/test/java/org/apache/tuscany/sca/binding/feed/Provider.java create mode 100644 java/sca/modules/binding-feed/src/test/resources/org/apache/tuscany/sca/binding/feed/Consumer.composite create mode 100644 java/sca/modules/binding-feed/src/test/resources/org/apache/tuscany/sca/binding/feed/Provider.composite create mode 100644 java/sca/modules/binding-gdata2-runtime/LICENSE create mode 100644 java/sca/modules/binding-gdata2-runtime/NOTICE create mode 100755 java/sca/modules/binding-gdata2-runtime/deployGdataToMaven.sh create mode 100644 java/sca/modules/binding-gdata2-runtime/pom.xml create mode 100644 java/sca/modules/binding-gdata2-runtime/src/main/java/org/apache/tuscany/sca/binding/gdata/collection/Collection.java create mode 100644 java/sca/modules/binding-gdata2-runtime/src/main/java/org/apache/tuscany/sca/binding/gdata/collection/MediaCollection.java create mode 100644 java/sca/modules/binding-gdata2-runtime/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/GDataBindingInvoker.java create mode 100644 java/sca/modules/binding-gdata2-runtime/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/GDataBindingListenerServlet.java create mode 100644 java/sca/modules/binding-gdata2-runtime/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/GDataBindingProviderFactory.java create mode 100644 java/sca/modules/binding-gdata2-runtime/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/GDataReferenceBindingProvider.java create mode 100644 java/sca/modules/binding-gdata2-runtime/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/GDataServiceBindingProvider.java create mode 100644 java/sca/modules/binding-gdata2-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory create mode 100644 java/sca/modules/binding-gdata2-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/calendarconsumer/CalendarConsumer.java create mode 100644 java/sca/modules/binding-gdata2-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/calendarconsumer/CalendarConsumerImpl.java create mode 100644 java/sca/modules/binding-gdata2-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/calendarconsumer/CalendarConsumerTest.java create mode 100644 java/sca/modules/binding-gdata2-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/consumerprovider/Consumer.java create mode 100644 java/sca/modules/binding-gdata2-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/consumerprovider/CustomerClient.java create mode 100644 java/sca/modules/binding-gdata2-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/consumerprovider/CustomerClientImpl.java create mode 100644 java/sca/modules/binding-gdata2-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/consumerprovider/CustomerCollectionImpl.java create mode 100644 java/sca/modules/binding-gdata2-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/consumerprovider/Provider.java create mode 100644 java/sca/modules/binding-gdata2-runtime/src/test/resources/org/apache/tuscany/sca/binding/gdata/CalendarConsumer.composite create mode 100644 java/sca/modules/binding-gdata2-runtime/src/test/resources/org/apache/tuscany/sca/binding/gdata/Consumer.composite create mode 100644 java/sca/modules/binding-gdata2-runtime/src/test/resources/org/apache/tuscany/sca/binding/gdata/Provider.composite create mode 100644 java/sca/modules/binding-gdata2/LICENSE create mode 100644 java/sca/modules/binding-gdata2/NOTICE create mode 100644 java/sca/modules/binding-gdata2/pom.xml create mode 100644 java/sca/modules/binding-gdata2/src/main/java/org/apache/tuscany/sca/binding/gdata/GDataBinding.java create mode 100644 java/sca/modules/binding-gdata2/src/main/java/org/apache/tuscany/sca/binding/gdata/GDataBindingFactory.java create mode 100644 java/sca/modules/binding-gdata2/src/main/java/org/apache/tuscany/sca/binding/gdata/GDataImplementationProcessor.java create mode 100644 java/sca/modules/binding-gdata2/src/main/java/org/apache/tuscany/sca/binding/gdata/impl/GDataBindingFactoryImpl.java create mode 100644 java/sca/modules/binding-gdata2/src/main/java/org/apache/tuscany/sca/binding/gdata/impl/GDataBindingImpl.java create mode 100644 java/sca/modules/binding-gdata2/src/main/resources/META-INF/services/org.apache.tuscany.sca.binding.gdata.GDataBindingFactory create mode 100644 java/sca/modules/binding-gdata2/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor create mode 100644 java/sca/modules/core-spring/LICENSE create mode 100644 java/sca/modules/core-spring/NOTICE create mode 100644 java/sca/modules/core-spring/pom.xml create mode 100644 java/sca/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/assembly/impl/BeanAssemblyFactory.java create mode 100644 java/sca/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/assembly/impl/BeanComponentImpl.java create mode 100644 java/sca/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/assembly/impl/BeanReferenceImpl.java create mode 100644 java/sca/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/context/ModelResolverImpl.java create mode 100644 java/sca/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/context/SCADomainContext.java create mode 100644 java/sca/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/implementation/java/impl/BeanBaseJavaImplementationImpl.java create mode 100644 java/sca/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/implementation/java/impl/BeanJavaImplementationFactory.java create mode 100644 java/sca/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/implementation/java/impl/BeanJavaImplementationImpl.java create mode 100644 java/sca/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/implementation/java/impl/BeanJavaInterfaceContractImpl.java create mode 100644 java/sca/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/implementation/java/impl/BeanJavaInterfaceFactory.java create mode 100644 java/sca/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/implementation/java/impl/BeanJavaInterfaceImpl.java create mode 100644 java/sca/modules/core-spring/src/test/java/calculator/AddService.java create mode 100644 java/sca/modules/core-spring/src/test/java/calculator/AddServiceImpl.java create mode 100644 java/sca/modules/core-spring/src/test/java/calculator/CalculatorClient.java create mode 100644 java/sca/modules/core-spring/src/test/java/calculator/CalculatorService.java create mode 100644 java/sca/modules/core-spring/src/test/java/calculator/CalculatorServiceImpl.java create mode 100644 java/sca/modules/core-spring/src/test/java/calculator/DivideService.java create mode 100644 java/sca/modules/core-spring/src/test/java/calculator/DivideServiceImpl.java create mode 100644 java/sca/modules/core-spring/src/test/java/calculator/MultiplyService.java create mode 100644 java/sca/modules/core-spring/src/test/java/calculator/MultiplyServiceImpl.java create mode 100644 java/sca/modules/core-spring/src/test/java/calculator/NestedCalculatorClient.java create mode 100644 java/sca/modules/core-spring/src/test/java/calculator/SubtractService.java create mode 100644 java/sca/modules/core-spring/src/test/java/calculator/SubtractServiceImpl.java create mode 100644 java/sca/modules/core-spring/src/test/java/org/apache/tuscany/sca/core/spring/CalculatorTestCase.java create mode 100644 java/sca/modules/core-spring/src/test/java/org/apache/tuscany/sca/core/spring/NestedCalculatorTestCaseFIXME.java create mode 100644 java/sca/modules/core-spring/src/test/resources/org/apache/tuscany/sca/core/spring/Calculator.composite create mode 100644 java/sca/modules/core-spring/src/test/resources/org/apache/tuscany/sca/core/spring/InnerCalculator.composite create mode 100644 java/sca/modules/core-spring/src/test/resources/org/apache/tuscany/sca/core/spring/InnerOperations.composite create mode 100644 java/sca/modules/core-spring/src/test/resources/org/apache/tuscany/sca/core/spring/OuterCalculator.composite create mode 100644 java/sca/modules/data-engine-helper/LICENSE create mode 100644 java/sca/modules/data-engine-helper/NOTICE create mode 100644 java/sca/modules/data-engine-helper/pom.xml create mode 100644 java/sca/modules/data-engine-helper/src/main/java/org/apache/tuscany/sca/data/engine/ConnectionInfoArtifactProcessor.java create mode 100644 java/sca/modules/data-engine-helper/src/main/java/org/apache/tuscany/sca/data/engine/DataAccessEngine.java create mode 100644 java/sca/modules/data-engine-helper/src/main/java/org/apache/tuscany/sca/data/engine/DataAccessEngineManager.java create mode 100644 java/sca/modules/data-engine-helper/src/main/java/org/apache/tuscany/sca/data/engine/MissingConfigFileException.java create mode 100644 java/sca/modules/data-engine-helper/src/main/java/org/apache/tuscany/sca/data/engine/config/ConnectionInfo.java create mode 100644 java/sca/modules/data-engine-helper/src/main/java/org/apache/tuscany/sca/data/engine/config/ConnectionProperties.java create mode 100644 java/sca/modules/data-engine-helper/src/main/resources/dataengine-helper-validation-messages.properties create mode 100644 java/sca/modules/implementation-bpel-jbpm/LICENSE create mode 100644 java/sca/modules/implementation-bpel-jbpm/NOTICE create mode 100644 java/sca/modules/implementation-bpel-jbpm/pom.xml create mode 100644 java/sca/modules/implementation-bpel-jbpm/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.ImplementationProviderFactory create mode 100644 java/sca/modules/monitor-logging/LICENSE create mode 100644 java/sca/modules/monitor-logging/NOTICE create mode 100644 java/sca/modules/monitor-logging/pom.xml create mode 100644 java/sca/modules/monitor-logging/src/main/java/org/apache/tuscany/sca/monitor/logging/impl/DefaultLoggingMonitorImpl.java create mode 100644 java/sca/modules/monitor-logging/src/main/java/org/apache/tuscany/sca/monitor/logging/impl/MonitorFactoryImpl.java create mode 100644 java/sca/modules/monitor-logging/src/main/resources/META-INF/services/org.apache.tuscany.sca.monitor.MonitorFactory create mode 100644 java/sca/modules/monitor-logging/src/test/java/org/apache/tuscany/sca/monitor/MonitorTestCase.java create mode 100644 java/sca/modules/monitor-logging/src/test/resources/tuscany-monitor-test-messages.properties create mode 100644 java/sca/modules/monitor-logging/src/test/resources/tuscany-monitor-test-messages_it.properties diff --git a/java/sca/contrib/modules/binding-dwr/LICENSE b/java/sca/contrib/modules/binding-dwr/LICENSE deleted file mode 100644 index 8aa906c321..0000000000 --- a/java/sca/contrib/modules/binding-dwr/LICENSE +++ /dev/null @@ -1,205 +0,0 @@ - - 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/java/sca/contrib/modules/binding-dwr/NOTICE b/java/sca/contrib/modules/binding-dwr/NOTICE deleted file mode 100644 index fdfa0e9faa..0000000000 --- a/java/sca/contrib/modules/binding-dwr/NOTICE +++ /dev/null @@ -1,6 +0,0 @@ -${pom.name} -Copyright (c) 2005 - 2008 The Apache Software Foundation - -This product includes software developed by -The Apache Software Foundation (http://www.apache.org/). - diff --git a/java/sca/contrib/modules/binding-dwr/pom.xml b/java/sca/contrib/modules/binding-dwr/pom.xml deleted file mode 100644 index 19f98a4c23..0000000000 --- a/java/sca/contrib/modules/binding-dwr/pom.xml +++ /dev/null @@ -1,95 +0,0 @@ - - - - - 4.0.0 - - org.apache.tuscany.sca - tuscany-modules - 2.0-SNAPSHOT - ../pom.xml - - - tuscany-binding-dwr - Apache Tuscany SCA AJAX DWR Binding Extension - - - - - org.apache.tuscany.sca - tuscany-extension-helper - 2.0-SNAPSHOT - - - - org.apache.tuscany.sca - tuscany-host-http - 2.0-SNAPSHOT - - - - org.directwebremoting - dwr - 2.0.1 - - - - javax.servlet - servlet-api - 2.4 - provided - - - - junit - junit - 4.5 - test - - - - org.easymock - easymock - 2.2 - test - - - - - - - - - org.apache.felix - maven-bundle-plugin - - - - ${tuscany.version} - org.apache.tuscany.sca.binding.dwr - ${pom.name} - org.apache.tuscany.sca.binding.dwr* - - - - - - - diff --git a/java/sca/contrib/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRBinding.java b/java/sca/contrib/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRBinding.java deleted file mode 100644 index ae5cf327ab..0000000000 --- a/java/sca/contrib/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRBinding.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.sca.binding.dwr; - -/** - * The runtime representation of the SCDL - * - * @version $Rev$ $Date$ - */ -public class DWRBinding { - - // Empty as doesn't use any additional attributes or elements (yet). - -} diff --git a/java/sca/contrib/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRBindingActivator.java b/java/sca/contrib/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRBindingActivator.java deleted file mode 100644 index d14751f235..0000000000 --- a/java/sca/contrib/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRBindingActivator.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.sca.binding.dwr; - -import org.apache.tuscany.sca.assembly.Binding; -import org.apache.tuscany.sca.extension.helper.BindingActivator; -import org.apache.tuscany.sca.extension.helper.ComponentLifecycle; -import org.apache.tuscany.sca.extension.helper.InvokerFactory; -import org.apache.tuscany.sca.host.http.ServletHost; -import org.apache.tuscany.sca.runtime.RuntimeComponent; -import org.apache.tuscany.sca.runtime.RuntimeComponentReference; -import org.apache.tuscany.sca.runtime.RuntimeComponentService; - -/** - * The Binding Activator for the DWR Binding. - * - * @version $Rev$ $Date$ - */ -public class DWRBindingActivator implements BindingActivator{ - - private ServletHost servletHost; - - public DWRBindingActivator(ServletHost servletHost) { - this.servletHost = servletHost; - } - - public Class getBindingClass() { - return DWRBinding.class; - } - - public InvokerFactory createInvokerFactory(RuntimeComponent rc, RuntimeComponentReference rcr, Binding b, DWRBinding ab) { - return new DWRInvokerFactory(rc, rcr, b, ab, servletHost); - } - - public ComponentLifecycle createService(RuntimeComponent rc, RuntimeComponentService rcs, Binding b, DWRBinding ab) { - return new DWRService(rc, rcs, b, ab, servletHost); - } - -} diff --git a/java/sca/contrib/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRInvoker.java b/java/sca/contrib/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRInvoker.java deleted file mode 100644 index 24e6dbbcd4..0000000000 --- a/java/sca/contrib/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRInvoker.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.sca.binding.dwr; - -import java.util.Collection; - -import org.apache.tuscany.sca.core.invocation.MessageImpl; -import org.apache.tuscany.sca.interfacedef.Operation; -import org.apache.tuscany.sca.invocation.Invoker; -import org.apache.tuscany.sca.invocation.Message; -import org.directwebremoting.ScriptBuffer; -import org.directwebremoting.WebContext; -import org.directwebremoting.WebContextFactory; -import org.directwebremoting.proxy.dwr.Util; - -/** - * The invoker for a DWR Binding. - * - * @version $Rev$ $Date$ - */ -public class DWRInvoker implements Invoker { - - private String referenceFunction; - - public DWRInvoker(String referenceName, Operation operation) { - this.referenceFunction = referenceName + "." + operation.getName(); - } - - public Message invoke(Message requestMsg) { - - invoke((Object[])requestMsg.getBody()); - - // DWR references can not return anything - return new MessageImpl(); - } - - public void invoke(Object[] args) { - - // TODO: this only works if its the same thread as request - WebContext wctx = WebContextFactory.get(); - String currentPage = wctx.getCurrentPage(); - - // Get a DWR Util proxy for all the browsers on the current page: - Collection sessions = wctx.getScriptSessionsByPage(currentPage); - Util utilAll = new Util(sessions); - - ScriptBuffer referenceInvoke = getInvokeFragment(args, wctx); - - // add the reference call to the Util proxy which will cause DWR to - // asynchronously send it to be run on each active browser client - utilAll.addScript(referenceInvoke); - } - - /** - * Creates a fragment of JavaScript code to invoke the reference function - * Eg: ".(arg1, arg2,...);" - */ - protected ScriptBuffer getInvokeFragment(Object[] args, WebContext wctx) { - - ScriptBuffer sb = new ScriptBuffer(); - sb.appendScript(referenceFunction); - sb.appendScript("("); - if (args != null) { - for (int i = 0; i < args.length; i++) { - sb.appendData(args[i]); - if (i < (args.length - 1)) { - sb.appendScript(", "); - } - } - } - sb.appendScript(");"); - - return sb; - } - -} diff --git a/java/sca/contrib/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRInvokerFactory.java b/java/sca/contrib/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRInvokerFactory.java deleted file mode 100644 index 1d073c9ecf..0000000000 --- a/java/sca/contrib/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRInvokerFactory.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.sca.binding.dwr; - -import static org.apache.tuscany.sca.binding.dwr.DWRService.SERVLET_PATH; - -import org.apache.tuscany.sca.assembly.Binding; -import org.apache.tuscany.sca.extension.helper.ComponentLifecycle; -import org.apache.tuscany.sca.extension.helper.InvokerFactory; -import org.apache.tuscany.sca.host.http.ServletHost; -import org.apache.tuscany.sca.interfacedef.Operation; -import org.apache.tuscany.sca.invocation.Invoker; -import org.apache.tuscany.sca.runtime.RuntimeComponent; -import org.apache.tuscany.sca.runtime.RuntimeComponentReference; - -/** - * InvokerFactory for the DWRBinding. - * - * @version $Rev$ $Date$ - */ -public class DWRInvokerFactory implements InvokerFactory, ComponentLifecycle { - - private Binding binding; - private ServletHost servletHost; - - public DWRInvokerFactory(RuntimeComponent rc, RuntimeComponentReference rcr, Binding b, DWRBinding ab, ServletHost servletHost) { - this.binding = b; - this.servletHost = servletHost; - } - - public Invoker createInvoker(Operation operation) { - return new DWRInvoker(binding.getName(), operation); - } - - public void start() { - - DWRServlet servlet = (DWRServlet) servletHost.getServletMapping(SERVLET_PATH); - if (servlet == null) { - servlet = new DWRServlet(); - servletHost.addServletMapping(SERVLET_PATH, servlet); - } - - servlet.addReference(binding.getName()); - } - - public void stop() { - servletHost.removeServletMapping(SERVLET_PATH); - } - -} diff --git a/java/sca/contrib/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRService.java b/java/sca/contrib/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRService.java deleted file mode 100644 index 7d5a7f1677..0000000000 --- a/java/sca/contrib/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRService.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.sca.binding.dwr; - -import java.lang.reflect.InvocationHandler; -import java.lang.reflect.Method; -import java.lang.reflect.Proxy; - -import org.apache.tuscany.sca.assembly.Binding; -import org.apache.tuscany.sca.extension.helper.ComponentLifecycle; -import org.apache.tuscany.sca.host.http.ServletHost; -import org.apache.tuscany.sca.interfacedef.Operation; -import org.apache.tuscany.sca.interfacedef.java.JavaInterface; -import org.apache.tuscany.sca.interfacedef.java.impl.JavaInterfaceUtil; -import org.apache.tuscany.sca.runtime.RuntimeComponent; -import org.apache.tuscany.sca.runtime.RuntimeComponentService; -import org.apache.tuscany.sca.runtime.RuntimeWire; - -/** - * DWR Service. - * - * @version $Rev$ $Date$ - */ -public class DWRService implements ComponentLifecycle { - - private RuntimeComponent rc; - private RuntimeComponentService rcs; - private Binding binding; - private ServletHost servletHost; - - static final String SERVLET_PATH = "/SCADomain/*"; - - public DWRService(RuntimeComponent rc, RuntimeComponentService rcs, Binding binding, DWRBinding ab, ServletHost servletHost) { - this.rc = rc; - this.rcs = rcs; - this.binding = binding; - this.servletHost = servletHost; - } - - public void start() { - - DWRServlet servlet = (DWRServlet) servletHost.getServletMapping(SERVLET_PATH); - if (servlet == null) { - servlet = new DWRServlet(); - servletHost.addServletMapping(SERVLET_PATH, servlet); - } - - // Create a Java proxy to the target service - Class type = ((JavaInterface)rcs.getInterfaceContract().getInterface()).getJavaClass(); - Object proxy = Proxy.newProxyInstance(type.getClassLoader(), new Class[]{type}, new InvocationHandler() { - public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { - RuntimeWire wire = rcs.getRuntimeWire(binding); - Operation op = JavaInterfaceUtil.findOperation(method, rcs.getInterfaceContract().getInterface().getOperations()); - return wire.invoke(op, args); - }}); - - servlet.addService(binding.getName(), type, proxy); - } - - public void stop() { - servletHost.removeServletMapping(SERVLET_PATH); - } - -} diff --git a/java/sca/contrib/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRServlet.java b/java/sca/contrib/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRServlet.java deleted file mode 100644 index 3a2471d8f3..0000000000 --- a/java/sca/contrib/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRServlet.java +++ /dev/null @@ -1,247 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.sca.binding.dwr; - -import java.io.IOException; -import java.io.PrintWriter; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import javax.servlet.ServletConfig; -import javax.servlet.ServletContext; -import javax.servlet.ServletException; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.directwebremoting.Container; -import org.directwebremoting.create.AbstractCreator; -import org.directwebremoting.extend.CreatorManager; -import org.directwebremoting.extend.Handler; -import org.directwebremoting.extend.Remoter; -import org.directwebremoting.servlet.DwrServlet; -import org.directwebremoting.servlet.EngineHandler; -import org.directwebremoting.servlet.PathConstants; -import org.directwebremoting.servlet.UrlProcessor; - -/** - * Tuscany customized DWR Servlet to implement support for the DWR binding - * - * Handles requests for SCA services and references that use , - * and also the HTTP GET for the Tuscany DWR system script "scaDomain.js" - * - * @version $Rev$ $Date$ - */ -public class DWRServlet extends DwrServlet { - private static final long serialVersionUID = 1L; - - private transient Map services; - private transient List referenceNames; - private transient boolean initialized; - private transient Map initParams; - - private static final String SCADOMAIN_SCRIPT_PATH = "/scaDomain.js"; - - public DWRServlet() { - this.services = new HashMap(); - this.referenceNames = new ArrayList(); - - this.initParams = new HashMap(); - // maybe use attributes to define the init params - initParams.put("activeReverseAjaxEnabled", "true"); - } - - @Override - public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException { - super.service(req, res); - } - - /** - * Initialize the Servlet - * There is a single instance of this Servlet which is registered - * for multiple path mappings, but the init should only run once. - */ - @Override - public void init(ServletConfig servletConfig) throws ServletException { - if (!initialized) { - super.init(patchConfig(servletConfig)); - addScriptHandler(); - initServices(); - initialized = true; - } - } - - /** - * Add in the handler to process the HTTP get for /sca/scaDomain.js - * - * This wrappers the DWR Engine handler which returns the DWR engine.js script, - * this wrappers that handler so as to add Tuscany specific header and footer code - * to the DWR engine.js to define the Tuscany SCADomain control functions and - * functions for each SCA service and reference that use . - */ - private void addScriptHandler() { - - UrlProcessor urlProcessor = (UrlProcessor)getContainer().getBean(UrlProcessor.class.getName()); - - final EngineHandler engineHandler = - (EngineHandler)getContainer().getBean(PathConstants.URL_PREFIX + "/engine.js"); - - final Handler scaDomainScriptHandler = new Handler() { - public void handle(HttpServletRequest request, HttpServletResponse response) throws IOException { - PrintWriter out = response.getWriter(); - out.println("/** Apache Tuscany scaDomain.js Header */"); - - engineHandler.handle(request, response); - - tuscanyFooter(request, out); - } - - }; - - // add the scaDomainScriptHandler to the urlProcessor - // bit of a hack, there's probably cleaner way to get it registered - urlProcessor.afterContainerSetup(new Container() { - public Object getBean(String name) { - return scaDomainScriptHandler; - } - public Collection getBeanNames() { - return Arrays.asList(new String[] {PathConstants.URL_PREFIX + SCADOMAIN_SCRIPT_PATH}); - } - }); - } - - /** - * Adds the JavaScript defining SCADomain, its control functions, - * and functions for all the available SCA services and references. - */ - private void tuscanyFooter(HttpServletRequest request, PrintWriter out) { - out.println("/** Apache Tuscany scaDomain.js Footer */"); - out.println(); - out.println("function scaDomain() { }"); - out.println(); - out.println("// SCA services"); - - // Use the DWR remoter to generate the JavaScipt function for each SCA service - Remoter remoter = (Remoter)getContainer().getBean(Remoter.class.getName()); - - String path = request.getContextPath() + request.getServletPath(); - - for (String serviceName : services.keySet()) { - String serviceScript = remoter.generateInterfaceScript(serviceName, path); - out.println(serviceScript); - } - - if (referenceNames.size() > 0) { - - out.println("// SCA reverse ajax control functions"); - out.println(); - out.println("scaDomain.open = function() { dwr.engine.setActiveReverseAjax(true); };"); - out.println("scaDomain.close = function() { dwr.engine.setActiveReverseAjax(false); };"); - - out.println(); - out.println("// SCA references"); - out.println(); - - // the JavaScript function for SCA references has an - // empty impl as it uses DWR severside "push" - for (String referenceName : referenceNames) { - out.println("function " + referenceName + "() { }"); - } - } - - out.println(); - out.println("/** End of Apache Tuscany scaDomain.js */"); - out.println(); - } - - /** - * Add an SCA reference to be added to the DWR runtime - */ - public void addReference(String name) { - referenceNames.add(name); - } - - /** - * Add an SCA service to be added to the DWR runtime - */ - public void addService(String name, final Class type, final Object instance) { - ServiceHolder holder = new ServiceHolder(); - holder.name = name; - holder.type = type; - holder.instance = instance; - services.put(name, holder); - } - - /** - * Defines each SCA service proxy instance to DWR - */ - private void initServices() { - CreatorManager creatorManager = (CreatorManager)getContainer().getBean(CreatorManager.class.getName()); - - for (final ServiceHolder holder : services.values()) { - creatorManager.addCreator(holder.name, new AbstractCreator() { - public Class getType() { - return holder.type; - } - - public Object getInstance() throws InstantiationException { - return holder.instance; - } - }); - } - } - - // utility class to aid passing around services - private class ServiceHolder { - String name; - Class type; - Object instance; - } - - /** - * Patch the ServletConfig to enable setting init params for DWR - * and so DWR can't see the Tuscany servlet's init params. - */ - private ServletConfig patchConfig(final ServletConfig servletConfig) { - ServletConfig patchedContext = new ServletConfig() { - public String getInitParameter(String name) { - return initParams.get(name); - } - public Enumeration getInitParameterNames() { - return Collections.enumeration(initParams.keySet()); - } - public ServletContext getServletContext() { - return servletConfig.getServletContext(); - } - public String getServletName() { - return servletConfig.getServletName(); - } - }; - return patchedContext; - } - -} diff --git a/java/sca/contrib/modules/binding-dwr/src/main/resources/META-INF/services/org.apache.tuscany.sca.extension.helper.BindingActivator b/java/sca/contrib/modules/binding-dwr/src/main/resources/META-INF/services/org.apache.tuscany.sca.extension.helper.BindingActivator deleted file mode 100644 index 1a9f91fab2..0000000000 --- a/java/sca/contrib/modules/binding-dwr/src/main/resources/META-INF/services/org.apache.tuscany.sca.extension.helper.BindingActivator +++ /dev/null @@ -1,19 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT 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/java/sca/modules/api/LICENSE b/java/sca/modules/api/LICENSE new file mode 100644 index 0000000000..6e529a25c4 --- /dev/null +++ b/java/sca/modules/api/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/java/sca/modules/api/NOTICE b/java/sca/modules/api/NOTICE new file mode 100644 index 0000000000..1325efd8bf --- /dev/null +++ b/java/sca/modules/api/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2008 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/java/sca/modules/api/pom.xml b/java/sca/modules/api/pom.xml new file mode 100644 index 0000000000..92f6bf9189 --- /dev/null +++ b/java/sca/modules/api/pom.xml @@ -0,0 +1,304 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 2.0-SNAPSHOT + ../pom.xml + + + tuscany-api + Apache Tuscany SCA API + + + + org.apache.tuscany.sca + tuscany-sca-api + 2.0-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-host-embedded + 2.0-SNAPSHOT + + + org.apache.tuscany.sca + tuscany-extensibility + + + org.apache.tuscany.sca + tuscany-core + + + org.apache.tuscany.sca + tuscany-definitions + + + org.apache.tuscany.sca + tuscany-definitions-xml + + + org.apache.tuscany.sca + tuscany-assembly-xml + + + org.apache.tuscany.sca + tuscany-binding-sca + + + org.apache.tuscany.sca + tuscany-binding-sca-xml + + + org.apache.tuscany.sca + tuscany-contribution-impl + + + org.apache.tuscany.sca + tuscany-policy-xml + + + org.apache.tuscany.sca + tuscany-core-databinding + + + org.apache.tuscany.sca + tuscany-assembly-xsd + + + org.apache.tuscany.sca + tuscany-policy-xml + + + org.apache.tuscany.sca + tuscany-endpoint + + + + + + + + + + + src/main/resources + + **/* + + + + + + + + org.apache.maven.plugins + maven-shade-plugin + + + + package + + shade + + + org.apache.tuscany.sca + + false + ${createSourcesJar} + false + true + + + + + + org.apache.tuscany.sca:tuscany-host-embedded + + org/apache/tuscany/sca/host/embedded/impl/** + + + + ${project.groupId}:${project.artifactId} + + + org/** + + + + + + + META-INF/services/org.apache.tuscany.sca.assembly.AssemblyFactory + + + META-INF/services/org.apache.tuscany.sca.assembly.SCABindingFactory + + + META-INF/services/org.apache.tuscany.sca.binding.feed.AtomBindingFactory + + + META-INF/services/org.apache.tuscany.sca.binding.feed.RSSBindingFactory + + + META-INF/services/org.apache.tuscany.sca.binding.atom.AtomBindingFactory + + + META-INF/services/org.apache.tuscany.sca.binding.rss.RSSBindingFactory + + + META-INF/services/org.apache.tuscany.sca.binding.http.HTTPResourceBindingFactory + + + META-INF/services/org.apache.tuscany.sca.contribution.ContributionFactory + + + META-INF/services/org.apache.tuscany.sca.contribution.java.JavaImportExportFactory + + + META-INF/services/org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint + + + META-INF/services/org.apache.tuscany.sca.contribution.namespace.NamespaceImportExportFactory + + + META-INF/services/org.apache.tuscany.sca.contribution.processor.ContributionPostProcessorExtensionPoint + + + META-INF/services/org.apache.tuscany.sca.contribution.processor.PackageProcessor + + + META-INF/services/org.apache.tuscany.sca.contribution.processor.PackageProcessorExtensionPoint + + + META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor + + + META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint + + + META-INF/services/org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor + + + META-INF/services/org.apache.tuscany.sca.contribution.processor.URLArtifactProcessorExtensionPoint + + + META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver + + + META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolverExtensionPoint + + + META-INF/services/org.apache.tuscany.sca.contribution.service.ContributionListener + + + META-INF/services/org.apache.tuscany.sca.contribution.service.ContributionListenerExtensionPoint + + + META-INF/services/org.apache.tuscany.sca.core.ModuleActivator + + + META-INF/services/org.apache.tuscany.sca.databinding.DataBinding + + + META-INF/services/org.apache.tuscany.sca.databinding.DataBindingExtensionPoint + + + META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer + + + META-INF/services/org.apache.tuscany.sca.databinding.PushTransformer + + + META-INF/services/org.apache.tuscany.sca.databinding.TransformerExtensionPoint + + + META-INF/services/org.apache.tuscany.sca.extension.helper.BindingActivator + + + META-INF/services/org.apache.tuscany.sca.extension.helper.ImplementationActivator + + + META-INF/services/org.apache.tuscany.sca.host.http.ServletHostExtensionPoint + + + META-INF/services/org.apache.tuscany.sca.host.rmi.RMIHostExtensionPoint + + + META-INF/services/org.apache.tuscany.sca.implementation.java.JavaImplementationFactory + + + META-INF/services/org.apache.tuscany.sca.implementation.resource.ResourceImplementationFactory + + + META-INF/services/org.apache.tuscany.sca.interfacedef.java.introspect.JavaInterfaceVisitor + + + META-INF/services/org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory + + + META-INF/services/org.apache.tuscany.sca.interfacedef.wsdl.WSDLFactory + + + META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory + + + META-INF/services/org.apache.tuscany.sca.provider.ImplementationProviderFactory + + + META-INF/services/org.apache.tuscany.sca.provider.ProviderFactoryExtensionPoint + + + META-INF/services/org.apache.tuscany.sca.runtime.RuntimeWireProcessorExtensionPoint + + + META-INF/services/org.apache.tuscany.sca.spi.ImplementationActivator + + + META-INF/services/org.apache.tuscany.sca.work.WorkScheduler + + + META-INF/services/org.apache.tuscany.sca.policy.util.PolicyHandler + + + META-INF/services/org.apache.tuscany.sca.provider.PolicyProviderFactory + + + META-INF/services/org.apache.tuscany.sca.definitions.SCADefinitionsProvider + + + + + + + + + + diff --git a/java/sca/modules/assembly-java-dsl/LICENSE b/java/sca/modules/assembly-java-dsl/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/java/sca/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/java/sca/modules/assembly-java-dsl/NOTICE b/java/sca/modules/assembly-java-dsl/NOTICE new file mode 100644 index 0000000000..fdfa0e9faa --- /dev/null +++ b/java/sca/modules/assembly-java-dsl/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2008 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/java/sca/modules/assembly-java-dsl/pom.xml b/java/sca/modules/assembly-java-dsl/pom.xml new file mode 100644 index 0000000000..8da66dbfef --- /dev/null +++ b/java/sca/modules/assembly-java-dsl/pom.xml @@ -0,0 +1,56 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 2.0-SNAPSHOT + ../pom.xml + + tuscany-assembly-java-dsl + Apache Tuscany SCA Assembly Model Java DSL + + + + org.apache.tuscany.sca + tuscany-assembly + 2.0-SNAPSHOT + + + + + + + org.apache.felix + maven-bundle-plugin + + + + ${tuscany.version} + org.apache.tuscany.sca.assembly.java.dsl + ${pom.name} + org.apache.tuscany.assembly.java.dsl* + + + + + + diff --git a/java/sca/modules/assembly-java-dsl/src/main/java/org/apache/tuscany/sca/assembly/dsl/AssemblyBuilder.java b/java/sca/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/java/sca/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/java/sca/modules/assembly-java-dsl/src/main/java/org/apache/tuscany/sca/assembly/dsl/ComponentBuilder.java b/java/sca/modules/assembly-java-dsl/src/main/java/org/apache/tuscany/sca/assembly/dsl/ComponentBuilder.java new file mode 100644 index 0000000000..3d97041907 --- /dev/null +++ b/java/sca/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); + + ComponentBuilder uses(ComponentReferenceBuilder... componentReferences); + + ComponentBuilder provides(ComponentServiceBuilder... componentServices); + + ComponentBuilder declares(ComponentPropertyBuilder...componentProperties); + +} diff --git a/java/sca/modules/assembly-java-dsl/src/main/java/org/apache/tuscany/sca/assembly/dsl/ComponentPropertyBuilder.java b/java/sca/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/java/sca/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/java/sca/modules/assembly-java-dsl/src/main/java/org/apache/tuscany/sca/assembly/dsl/ComponentReferenceBuilder.java b/java/sca/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/java/sca/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/java/sca/modules/assembly-java-dsl/src/main/java/org/apache/tuscany/sca/assembly/dsl/ComponentServiceBuilder.java b/java/sca/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/java/sca/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/java/sca/modules/assembly-java-dsl/src/main/java/org/apache/tuscany/sca/assembly/dsl/CompositeBuilder.java b/java/sca/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/java/sca/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/java/sca/modules/assembly-java-dsl/src/main/java/org/apache/tuscany/sca/assembly/dsl/impl/AssemblyBuilderImpl.java b/java/sca/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/java/sca/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/java/sca/modules/assembly-java-dsl/src/main/java/org/apache/tuscany/sca/assembly/dsl/impl/ComponentBuilderImpl.java b/java/sca/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/java/sca/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/java/sca/modules/assembly-java-dsl/src/main/java/org/apache/tuscany/sca/assembly/dsl/impl/ComponentPropertyBuilderImpl.java b/java/sca/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/java/sca/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/java/sca/modules/assembly-java-dsl/src/main/java/org/apache/tuscany/sca/assembly/dsl/impl/ComponentReferenceBuilderImpl.java b/java/sca/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/java/sca/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/java/sca/modules/assembly-java-dsl/src/main/java/org/apache/tuscany/sca/assembly/dsl/impl/ComponentServiceBuilderImpl.java b/java/sca/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/java/sca/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/java/sca/modules/assembly-java-dsl/src/main/java/org/apache/tuscany/sca/assembly/dsl/impl/CompositeBuilderImpl.java b/java/sca/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/java/sca/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/java/sca/modules/assembly-java-dsl/src/test/java/org/apache/tuscany/sca/assembly/dsl/AccountDataService.java b/java/sca/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/java/sca/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/java/sca/modules/assembly-java-dsl/src/test/java/org/apache/tuscany/sca/assembly/dsl/AccountDataServiceImpl.java b/java/sca/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/java/sca/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/java/sca/modules/assembly-java-dsl/src/test/java/org/apache/tuscany/sca/assembly/dsl/AccountService.java b/java/sca/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/java/sca/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/java/sca/modules/assembly-java-dsl/src/test/java/org/apache/tuscany/sca/assembly/dsl/AccountServiceImpl.java b/java/sca/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/java/sca/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/java/sca/modules/assembly-java-dsl/src/test/java/org/apache/tuscany/sca/assembly/dsl/BigBankBuilder.java b/java/sca/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/java/sca/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/java/sca/modules/assembly-java-dsl/src/test/java/org/apache/tuscany/sca/assembly/dsl/BigBankBuilderTestCase.java b/java/sca/modules/assembly-java-dsl/src/test/java/org/apache/tuscany/sca/assembly/dsl/BigBankBuilderTestCase.java new file mode 100644 index 0000000000..fb950b5c13 --- /dev/null +++ b/java/sca/modules/assembly-java-dsl/src/test/java/org/apache/tuscany/sca/assembly/dsl/BigBankBuilderTestCase.java @@ -0,0 +1,33 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.assembly.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); + } + +} diff --git a/java/sca/modules/assembly-java-dsl/src/test/java/org/apache/tuscany/sca/assembly/dsl/StockQuoteService.java b/java/sca/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/java/sca/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/java/sca/modules/binding-dwr/LICENSE b/java/sca/modules/binding-dwr/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/java/sca/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/java/sca/modules/binding-dwr/NOTICE b/java/sca/modules/binding-dwr/NOTICE new file mode 100644 index 0000000000..fdfa0e9faa --- /dev/null +++ b/java/sca/modules/binding-dwr/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2008 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/java/sca/modules/binding-dwr/pom.xml b/java/sca/modules/binding-dwr/pom.xml new file mode 100644 index 0000000000..19f98a4c23 --- /dev/null +++ b/java/sca/modules/binding-dwr/pom.xml @@ -0,0 +1,95 @@ + + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 2.0-SNAPSHOT + ../pom.xml + + + tuscany-binding-dwr + Apache Tuscany SCA AJAX DWR Binding Extension + + + + + org.apache.tuscany.sca + tuscany-extension-helper + 2.0-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-host-http + 2.0-SNAPSHOT + + + + org.directwebremoting + dwr + 2.0.1 + + + + javax.servlet + servlet-api + 2.4 + provided + + + + junit + junit + 4.5 + test + + + + org.easymock + easymock + 2.2 + test + + + + + + + + + org.apache.felix + maven-bundle-plugin + + + + ${tuscany.version} + org.apache.tuscany.sca.binding.dwr + ${pom.name} + org.apache.tuscany.sca.binding.dwr* + + + + + + + diff --git a/java/sca/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRBinding.java b/java/sca/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRBinding.java new file mode 100644 index 0000000000..ae5cf327ab --- /dev/null +++ b/java/sca/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRBinding.java @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.dwr; + +/** + * The runtime representation of the SCDL + * + * @version $Rev$ $Date$ + */ +public class DWRBinding { + + // Empty as doesn't use any additional attributes or elements (yet). + +} diff --git a/java/sca/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRBindingActivator.java b/java/sca/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRBindingActivator.java new file mode 100644 index 0000000000..d14751f235 --- /dev/null +++ b/java/sca/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRBindingActivator.java @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.dwr; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.extension.helper.BindingActivator; +import org.apache.tuscany.sca.extension.helper.ComponentLifecycle; +import org.apache.tuscany.sca.extension.helper.InvokerFactory; +import org.apache.tuscany.sca.host.http.ServletHost; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + +/** + * The Binding Activator for the DWR Binding. + * + * @version $Rev$ $Date$ + */ +public class DWRBindingActivator implements BindingActivator{ + + private ServletHost servletHost; + + public DWRBindingActivator(ServletHost servletHost) { + this.servletHost = servletHost; + } + + public Class getBindingClass() { + return DWRBinding.class; + } + + public InvokerFactory createInvokerFactory(RuntimeComponent rc, RuntimeComponentReference rcr, Binding b, DWRBinding ab) { + return new DWRInvokerFactory(rc, rcr, b, ab, servletHost); + } + + public ComponentLifecycle createService(RuntimeComponent rc, RuntimeComponentService rcs, Binding b, DWRBinding ab) { + return new DWRService(rc, rcs, b, ab, servletHost); + } + +} diff --git a/java/sca/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRInvoker.java b/java/sca/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRInvoker.java new file mode 100644 index 0000000000..24e6dbbcd4 --- /dev/null +++ b/java/sca/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRInvoker.java @@ -0,0 +1,93 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.dwr; + +import java.util.Collection; + +import org.apache.tuscany.sca.core.invocation.MessageImpl; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.directwebremoting.ScriptBuffer; +import org.directwebremoting.WebContext; +import org.directwebremoting.WebContextFactory; +import org.directwebremoting.proxy.dwr.Util; + +/** + * The invoker for a DWR Binding. + * + * @version $Rev$ $Date$ + */ +public class DWRInvoker implements Invoker { + + private String referenceFunction; + + public DWRInvoker(String referenceName, Operation operation) { + this.referenceFunction = referenceName + "." + operation.getName(); + } + + public Message invoke(Message requestMsg) { + + invoke((Object[])requestMsg.getBody()); + + // DWR references can not return anything + return new MessageImpl(); + } + + public void invoke(Object[] args) { + + // TODO: this only works if its the same thread as request + WebContext wctx = WebContextFactory.get(); + String currentPage = wctx.getCurrentPage(); + + // Get a DWR Util proxy for all the browsers on the current page: + Collection sessions = wctx.getScriptSessionsByPage(currentPage); + Util utilAll = new Util(sessions); + + ScriptBuffer referenceInvoke = getInvokeFragment(args, wctx); + + // add the reference call to the Util proxy which will cause DWR to + // asynchronously send it to be run on each active browser client + utilAll.addScript(referenceInvoke); + } + + /** + * Creates a fragment of JavaScript code to invoke the reference function + * Eg: ".(arg1, arg2,...);" + */ + protected ScriptBuffer getInvokeFragment(Object[] args, WebContext wctx) { + + ScriptBuffer sb = new ScriptBuffer(); + sb.appendScript(referenceFunction); + sb.appendScript("("); + if (args != null) { + for (int i = 0; i < args.length; i++) { + sb.appendData(args[i]); + if (i < (args.length - 1)) { + sb.appendScript(", "); + } + } + } + sb.appendScript(");"); + + return sb; + } + +} diff --git a/java/sca/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRInvokerFactory.java b/java/sca/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRInvokerFactory.java new file mode 100644 index 0000000000..1d073c9ecf --- /dev/null +++ b/java/sca/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRInvokerFactory.java @@ -0,0 +1,67 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.dwr; + +import static org.apache.tuscany.sca.binding.dwr.DWRService.SERVLET_PATH; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.extension.helper.ComponentLifecycle; +import org.apache.tuscany.sca.extension.helper.InvokerFactory; +import org.apache.tuscany.sca.host.http.ServletHost; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; + +/** + * InvokerFactory for the DWRBinding. + * + * @version $Rev$ $Date$ + */ +public class DWRInvokerFactory implements InvokerFactory, ComponentLifecycle { + + private Binding binding; + private ServletHost servletHost; + + public DWRInvokerFactory(RuntimeComponent rc, RuntimeComponentReference rcr, Binding b, DWRBinding ab, ServletHost servletHost) { + this.binding = b; + this.servletHost = servletHost; + } + + public Invoker createInvoker(Operation operation) { + return new DWRInvoker(binding.getName(), operation); + } + + public void start() { + + DWRServlet servlet = (DWRServlet) servletHost.getServletMapping(SERVLET_PATH); + if (servlet == null) { + servlet = new DWRServlet(); + servletHost.addServletMapping(SERVLET_PATH, servlet); + } + + servlet.addReference(binding.getName()); + } + + public void stop() { + servletHost.removeServletMapping(SERVLET_PATH); + } + +} diff --git a/java/sca/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRService.java b/java/sca/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRService.java new file mode 100644 index 0000000000..7d5a7f1677 --- /dev/null +++ b/java/sca/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRService.java @@ -0,0 +1,81 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.dwr; + +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; +import java.lang.reflect.Proxy; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.extension.helper.ComponentLifecycle; +import org.apache.tuscany.sca.host.http.ServletHost; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.java.JavaInterface; +import org.apache.tuscany.sca.interfacedef.java.impl.JavaInterfaceUtil; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; +import org.apache.tuscany.sca.runtime.RuntimeWire; + +/** + * DWR Service. + * + * @version $Rev$ $Date$ + */ +public class DWRService implements ComponentLifecycle { + + private RuntimeComponent rc; + private RuntimeComponentService rcs; + private Binding binding; + private ServletHost servletHost; + + static final String SERVLET_PATH = "/SCADomain/*"; + + public DWRService(RuntimeComponent rc, RuntimeComponentService rcs, Binding binding, DWRBinding ab, ServletHost servletHost) { + this.rc = rc; + this.rcs = rcs; + this.binding = binding; + this.servletHost = servletHost; + } + + public void start() { + + DWRServlet servlet = (DWRServlet) servletHost.getServletMapping(SERVLET_PATH); + if (servlet == null) { + servlet = new DWRServlet(); + servletHost.addServletMapping(SERVLET_PATH, servlet); + } + + // Create a Java proxy to the target service + Class type = ((JavaInterface)rcs.getInterfaceContract().getInterface()).getJavaClass(); + Object proxy = Proxy.newProxyInstance(type.getClassLoader(), new Class[]{type}, new InvocationHandler() { + public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + RuntimeWire wire = rcs.getRuntimeWire(binding); + Operation op = JavaInterfaceUtil.findOperation(method, rcs.getInterfaceContract().getInterface().getOperations()); + return wire.invoke(op, args); + }}); + + servlet.addService(binding.getName(), type, proxy); + } + + public void stop() { + servletHost.removeServletMapping(SERVLET_PATH); + } + +} diff --git a/java/sca/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRServlet.java b/java/sca/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRServlet.java new file mode 100644 index 0000000000..3a2471d8f3 --- /dev/null +++ b/java/sca/modules/binding-dwr/src/main/java/org/apache/tuscany/sca/binding/dwr/DWRServlet.java @@ -0,0 +1,247 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.dwr; + +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.servlet.ServletConfig; +import javax.servlet.ServletContext; +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.directwebremoting.Container; +import org.directwebremoting.create.AbstractCreator; +import org.directwebremoting.extend.CreatorManager; +import org.directwebremoting.extend.Handler; +import org.directwebremoting.extend.Remoter; +import org.directwebremoting.servlet.DwrServlet; +import org.directwebremoting.servlet.EngineHandler; +import org.directwebremoting.servlet.PathConstants; +import org.directwebremoting.servlet.UrlProcessor; + +/** + * Tuscany customized DWR Servlet to implement support for the DWR binding + * + * Handles requests for SCA services and references that use , + * and also the HTTP GET for the Tuscany DWR system script "scaDomain.js" + * + * @version $Rev$ $Date$ + */ +public class DWRServlet extends DwrServlet { + private static final long serialVersionUID = 1L; + + private transient Map services; + private transient List referenceNames; + private transient boolean initialized; + private transient Map initParams; + + private static final String SCADOMAIN_SCRIPT_PATH = "/scaDomain.js"; + + public DWRServlet() { + this.services = new HashMap(); + this.referenceNames = new ArrayList(); + + this.initParams = new HashMap(); + // maybe use attributes to define the init params + initParams.put("activeReverseAjaxEnabled", "true"); + } + + @Override + public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException { + super.service(req, res); + } + + /** + * Initialize the Servlet + * There is a single instance of this Servlet which is registered + * for multiple path mappings, but the init should only run once. + */ + @Override + public void init(ServletConfig servletConfig) throws ServletException { + if (!initialized) { + super.init(patchConfig(servletConfig)); + addScriptHandler(); + initServices(); + initialized = true; + } + } + + /** + * Add in the handler to process the HTTP get for /sca/scaDomain.js + * + * This wrappers the DWR Engine handler which returns the DWR engine.js script, + * this wrappers that handler so as to add Tuscany specific header and footer code + * to the DWR engine.js to define the Tuscany SCADomain control functions and + * functions for each SCA service and reference that use . + */ + private void addScriptHandler() { + + UrlProcessor urlProcessor = (UrlProcessor)getContainer().getBean(UrlProcessor.class.getName()); + + final EngineHandler engineHandler = + (EngineHandler)getContainer().getBean(PathConstants.URL_PREFIX + "/engine.js"); + + final Handler scaDomainScriptHandler = new Handler() { + public void handle(HttpServletRequest request, HttpServletResponse response) throws IOException { + PrintWriter out = response.getWriter(); + out.println("/** Apache Tuscany scaDomain.js Header */"); + + engineHandler.handle(request, response); + + tuscanyFooter(request, out); + } + + }; + + // add the scaDomainScriptHandler to the urlProcessor + // bit of a hack, there's probably cleaner way to get it registered + urlProcessor.afterContainerSetup(new Container() { + public Object getBean(String name) { + return scaDomainScriptHandler; + } + public Collection getBeanNames() { + return Arrays.asList(new String[] {PathConstants.URL_PREFIX + SCADOMAIN_SCRIPT_PATH}); + } + }); + } + + /** + * Adds the JavaScript defining SCADomain, its control functions, + * and functions for all the available SCA services and references. + */ + private void tuscanyFooter(HttpServletRequest request, PrintWriter out) { + out.println("/** Apache Tuscany scaDomain.js Footer */"); + out.println(); + out.println("function scaDomain() { }"); + out.println(); + out.println("// SCA services"); + + // Use the DWR remoter to generate the JavaScipt function for each SCA service + Remoter remoter = (Remoter)getContainer().getBean(Remoter.class.getName()); + + String path = request.getContextPath() + request.getServletPath(); + + for (String serviceName : services.keySet()) { + String serviceScript = remoter.generateInterfaceScript(serviceName, path); + out.println(serviceScript); + } + + if (referenceNames.size() > 0) { + + out.println("// SCA reverse ajax control functions"); + out.println(); + out.println("scaDomain.open = function() { dwr.engine.setActiveReverseAjax(true); };"); + out.println("scaDomain.close = function() { dwr.engine.setActiveReverseAjax(false); };"); + + out.println(); + out.println("// SCA references"); + out.println(); + + // the JavaScript function for SCA references has an + // empty impl as it uses DWR severside "push" + for (String referenceName : referenceNames) { + out.println("function " + referenceName + "() { }"); + } + } + + out.println(); + out.println("/** End of Apache Tuscany scaDomain.js */"); + out.println(); + } + + /** + * Add an SCA reference to be added to the DWR runtime + */ + public void addReference(String name) { + referenceNames.add(name); + } + + /** + * Add an SCA service to be added to the DWR runtime + */ + public void addService(String name, final Class type, final Object instance) { + ServiceHolder holder = new ServiceHolder(); + holder.name = name; + holder.type = type; + holder.instance = instance; + services.put(name, holder); + } + + /** + * Defines each SCA service proxy instance to DWR + */ + private void initServices() { + CreatorManager creatorManager = (CreatorManager)getContainer().getBean(CreatorManager.class.getName()); + + for (final ServiceHolder holder : services.values()) { + creatorManager.addCreator(holder.name, new AbstractCreator() { + public Class getType() { + return holder.type; + } + + public Object getInstance() throws InstantiationException { + return holder.instance; + } + }); + } + } + + // utility class to aid passing around services + private class ServiceHolder { + String name; + Class type; + Object instance; + } + + /** + * Patch the ServletConfig to enable setting init params for DWR + * and so DWR can't see the Tuscany servlet's init params. + */ + private ServletConfig patchConfig(final ServletConfig servletConfig) { + ServletConfig patchedContext = new ServletConfig() { + public String getInitParameter(String name) { + return initParams.get(name); + } + public Enumeration getInitParameterNames() { + return Collections.enumeration(initParams.keySet()); + } + public ServletContext getServletContext() { + return servletConfig.getServletContext(); + } + public String getServletName() { + return servletConfig.getServletName(); + } + }; + return patchedContext; + } + +} diff --git a/java/sca/modules/binding-dwr/src/main/resources/META-INF/services/org.apache.tuscany.sca.extension.helper.BindingActivator b/java/sca/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/java/sca/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/java/sca/modules/binding-feed/LICENSE b/java/sca/modules/binding-feed/LICENSE new file mode 100644 index 0000000000..6e529a25c4 --- /dev/null +++ b/java/sca/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/java/sca/modules/binding-feed/NOTICE b/java/sca/modules/binding-feed/NOTICE new file mode 100644 index 0000000000..1325efd8bf --- /dev/null +++ b/java/sca/modules/binding-feed/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2008 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/java/sca/modules/binding-feed/pom.xml b/java/sca/modules/binding-feed/pom.xml new file mode 100644 index 0000000000..c0c895a894 --- /dev/null +++ b/java/sca/modules/binding-feed/pom.xml @@ -0,0 +1,165 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 2.0-SNAPSHOT + ../pom.xml + + + tuscany-binding-feed + Apache Tuscany SCA Atom+RSS Feed Binding Extension + + + + org.apache.tuscany.sca + tuscany-assembly + 2.0-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-interface-java + 2.0-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-data-api + 2.0-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-core-spi + 2.0-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-databinding + 2.0-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-host-http + 2.0-SNAPSHOT + + + + commons-httpclient + commons-httpclient + 3.1 + + + + rome + rome + 0.9 + + + + javax.servlet + servlet-api + 2.4 + provided + + + + org.apache.tuscany.sca + tuscany-host-jetty + 2.0-SNAPSHOT + test + + + + org.apache.tuscany.sca + tuscany-implementation-java-runtime + 2.0-SNAPSHOT + test + + + + org.apache.tuscany.sca + tuscany-host-embedded + 2.0-SNAPSHOT + test + + + + junit + junit + 4.5 + test + + + + commons-codec + commons-codec + 1.3 + + + commons-codec + commons-codec + + + + + + commons-logging + commons-logging + 1.1.1 + + + javax.servlet + servlet-api + + + avalon-framework + avalon-framework + + + + + + + + + + + org.apache.felix + maven-bundle-plugin + + + + ${tuscany.version} + org.apache.tuscany.sca.binding.feed + ${pom.name} + org.apache.tuscany.sca.binding.feed* + + + + + + + diff --git a/java/sca/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/AtomBinding.java b/java/sca/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/AtomBinding.java new file mode 100644 index 0000000000..00aa813af2 --- /dev/null +++ b/java/sca/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/AtomBinding.java @@ -0,0 +1,30 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.feed; + +import org.apache.tuscany.sca.assembly.Binding; + +/** + * Atom binding model. + * + * @version $Rev$ $Date$ + */ +public interface AtomBinding extends Binding { +} diff --git a/java/sca/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/AtomBindingFactory.java b/java/sca/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/AtomBindingFactory.java new file mode 100644 index 0000000000..050ba9b73c --- /dev/null +++ b/java/sca/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/java/sca/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/RSSBinding.java b/java/sca/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/RSSBinding.java new file mode 100644 index 0000000000..81b9fd95ad --- /dev/null +++ b/java/sca/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/RSSBinding.java @@ -0,0 +1,30 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.feed; + +import org.apache.tuscany.sca.assembly.Binding; + +/** + * RSS Feed binding model. + * + * @version $Rev$ $Date$ + */ +public interface RSSBinding extends Binding { +} diff --git a/java/sca/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/RSSBindingFactory.java b/java/sca/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/RSSBindingFactory.java new file mode 100644 index 0000000000..c95c8ac012 --- /dev/null +++ b/java/sca/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/java/sca/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/collection/Collection.java b/java/sca/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/collection/Collection.java new file mode 100644 index 0000000000..30068afa0a --- /dev/null +++ b/java/sca/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/collection/Collection.java @@ -0,0 +1,72 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.feed.collection; + +import org.osoa.sca.annotations.Remotable; + +import com.sun.syndication.feed.atom.Entry; + +/** + * Provides access to a collection of resources using Atom. + * + * @version $Rev$ $Date$ + */ +@Remotable +public interface Collection { + + /** + * Get an RSS or Atom feed for a collection of resources. + * + * @return the RSS or Atom feed + */ + com.sun.syndication.feed.atom.Feed getFeed(); + + /** + * Creates a new entry. + * + * @param entry + * @return + */ + Entry post(Entry entry); + + /** + * Retrieves an entry. + * + * @param id + * @return + */ + Entry get(String id) throws NotFoundException; + + /** + * Update an entry. + * + * @param id + * @param entry + * @return + */ + void put(String id, Entry entry) throws NotFoundException; + + /** + * Delete an entry. + * + * @param id + */ + void delete(String id) throws NotFoundException; + +} diff --git a/java/sca/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/collection/MediaCollection.java b/java/sca/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/collection/MediaCollection.java new file mode 100644 index 0000000000..39a4213a65 --- /dev/null +++ b/java/sca/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/collection/MediaCollection.java @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.feed.collection; + +import java.io.InputStream; + +import org.osoa.sca.annotations.Remotable; + +import com.sun.syndication.feed.atom.Entry; + +/** + * Provides access to a collection of resources using Atom. + * + * @version $Rev$ $Date$ + */ +@Remotable +public interface MediaCollection extends Collection { + + /** + * Creates a new media entry + * + * @param title + * @param slug + * @param contentType + * @param media + */ + Entry postMedia(String title, String slug, String contentType, InputStream media); + + /** + * Update a media entry. + * + * @param id + * @param contentType + * @param media + * @return + */ + void putMedia(String id, String contentType, InputStream media) throws NotFoundException; + +} diff --git a/java/sca/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/collection/NotFoundException.java b/java/sca/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/java/sca/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/java/sca/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/impl/AtomBindingFactoryImpl.java b/java/sca/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/java/sca/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/java/sca/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/impl/AtomBindingImpl.java b/java/sca/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/impl/AtomBindingImpl.java new file mode 100644 index 0000000000..76551bc412 --- /dev/null +++ b/java/sca/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/impl/AtomBindingImpl.java @@ -0,0 +1,96 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.feed.impl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.sca.binding.feed.AtomBinding; +import org.apache.tuscany.sca.policy.Intent; +import org.apache.tuscany.sca.policy.IntentAttachPointType; +import org.apache.tuscany.sca.policy.PolicySet; +import org.apache.tuscany.sca.policy.PolicySetAttachPoint; + +/** + * Implementation of the Atom Feed binding model. + * + * @version $Rev$ $Date$ + */ +class AtomBindingImpl implements AtomBinding, PolicySetAttachPoint { + + private String name; + private String uri; + private List requiredIntents = new ArrayList(); + private List policySets = new ArrayList(); + private IntentAttachPointType intentAttachPointType; + private List applicablePolicySets = new ArrayList(); + + public List getApplicablePolicySets() { + return applicablePolicySets; + } + + public String getName() { + return name; + } + + public String getURI() { + return uri; + } + + public void setName(String name) { + this.name = name; + } + + public void setURI(String uri) { + this.uri = uri; + } + + + public boolean isUnresolved() { + // The binding is always resolved + return false; + } + + public void setUnresolved(boolean unresolved) { + // The binding is always resolved + } + + public List getPolicySets() { + return policySets; + } + + public List getRequiredIntents() { + return requiredIntents; + } + + public IntentAttachPointType getType() { + return intentAttachPointType; + } + + public void setType(IntentAttachPointType intentAttachPointType) { + this.intentAttachPointType = intentAttachPointType; + } + + @Override + public Object clone() throws CloneNotSupportedException { + return super.clone(); + } + +} diff --git a/java/sca/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/impl/RSSBindingFactoryImpl.java b/java/sca/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/java/sca/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/java/sca/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/impl/RSSBindingImpl.java b/java/sca/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/impl/RSSBindingImpl.java new file mode 100644 index 0000000000..9df2ec60da --- /dev/null +++ b/java/sca/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/impl/RSSBindingImpl.java @@ -0,0 +1,101 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.feed.impl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.sca.binding.feed.RSSBinding; +import org.apache.tuscany.sca.policy.Intent; +import org.apache.tuscany.sca.policy.IntentAttachPointType; +import org.apache.tuscany.sca.policy.PolicySet; +import org.apache.tuscany.sca.policy.PolicySetAttachPoint; + +/** + * Implementation of the RSS Feed binding model. + * + * @version $Rev$ $Date$ + */ +class RSSBindingImpl implements RSSBinding, PolicySetAttachPoint { + + private String name; + private String uri; + private List requiredIntents = new ArrayList(); + private List policySets = new ArrayList(); + private IntentAttachPointType intentAttachPointType; + private List applicablePolicySets = new ArrayList(); + + public List getApplicablePolicySets() { + return applicablePolicySets; + } + + public String getName() { + return name; + } + + public String getURI() { + return uri; + } + + public void setName(String name) { + this.name = name; + } + + public void setURI(String uri) { + this.uri = uri; + } + + public boolean isUnresolved() { + return false; + } + + public void setUnresolved(boolean unresolved) { + // The binding is always resolved + } + + public List getPolicySets() { + return policySets; + } + + public List getRequiredIntents() { + return requiredIntents; + } + + public IntentAttachPointType getType() { + return intentAttachPointType; + } + + public void setType(IntentAttachPointType intentAttachPointType) { + this.intentAttachPointType = intentAttachPointType; + } + + public void setPolicySets(List policySets) { + this.policySets = policySets; + } + + public void setRequiredIntents(List intents) { + this.requiredIntents = intents; + } + + @Override + public Object clone() throws CloneNotSupportedException { + return super.clone(); + } +} diff --git a/java/sca/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/AtomBindingInvoker.java b/java/sca/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/AtomBindingInvoker.java new file mode 100644 index 0000000000..45b35d9206 --- /dev/null +++ b/java/sca/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/AtomBindingInvoker.java @@ -0,0 +1,345 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.feed.provider; + +import java.io.InputStreamReader; +import java.io.StringWriter; + +import org.apache.commons.httpclient.HttpClient; +import org.apache.commons.httpclient.methods.DeleteMethod; +import org.apache.commons.httpclient.methods.GetMethod; +import org.apache.commons.httpclient.methods.PostMethod; +import org.apache.commons.httpclient.methods.PutMethod; +import org.apache.commons.httpclient.methods.StringRequestEntity; +import org.apache.tuscany.sca.binding.feed.collection.NotFoundException; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.invocation.DataExchangeSemantics; +import org.osoa.sca.ServiceRuntimeException; + +import com.sun.syndication.feed.atom.Entry; +import com.sun.syndication.feed.atom.Feed; +import com.sun.syndication.io.WireFeedInput; +import com.sun.syndication.io.XmlReader; + +/** + * Invoker for the Atom binding. + * + * @version $Rev$ $Date$ + */ +class AtomBindingInvoker implements Invoker, DataExchangeSemantics { + + Operation operation; + String uri; + HttpClient httpClient; + String authorizationHeader; + + //FIXME Support conversion to/from data api entries + + AtomBindingInvoker(Operation operation, String uri, HttpClient httpClient, String authorizationHeader) { + this.operation = operation; + this.uri = uri; + this.httpClient = httpClient; + this.authorizationHeader = authorizationHeader; + } + + public Message invoke(Message msg) { + // Shouldn't get here, as the only supported methods are + // defined in the ResourceCollection interface, and implemented + // by specific invoker subclasses + throw new UnsupportedOperationException(operation.getName()); + } + + public boolean allowsPassByReference() { + return true; + } + + /** + * Get operation invoker + */ + public static class GetInvoker extends AtomBindingInvoker { + + public GetInvoker(Operation operation, String uri, HttpClient httpClient, String authorizationHeader) { + super(operation, uri, httpClient, authorizationHeader); + } + + @Override + public Message invoke(Message msg) { + + // Get an entry + String id = (String)((Object[])msg.getBody())[0]; + + // Send an HTTP GET + GetMethod getMethod = new GetMethod(uri + "/" + id); + getMethod.setRequestHeader("Authorization", authorizationHeader); + try { + httpClient.executeMethod(getMethod); + int status = getMethod.getStatusCode(); + + // Read the Atom entry + if (status == 200) { + Entry feedEntry = + AtomFeedEntryUtil.readFeedEntry("atom_1.0", new InputStreamReader(getMethod.getResponseBodyAsStream())); + msg.setBody(feedEntry); + + } else if (status == 404) { + msg.setFaultBody(new NotFoundException()); + } else { + msg.setFaultBody(new ServiceRuntimeException("HTTP status code: " + status)); + } + + } catch (Exception e) { + msg.setFaultBody(new ServiceRuntimeException(e)); + } finally { + getMethod.releaseConnection(); + } + + return msg; + } + } + + /** + * Post operation invoker + */ + public static class PostInvoker extends AtomBindingInvoker { + + public PostInvoker(Operation operation, String uri, HttpClient httpClient, String authorizationHeader) { + super(operation, uri, httpClient, authorizationHeader); + } + + @Override + public Message invoke(Message msg) { + + // Post an entry + Entry feedEntry = (Entry)((Object[])msg.getBody())[0]; + + // Send an HTTP POST + PostMethod postMethod = new PostMethod(uri); + postMethod.setRequestHeader("Authorization", authorizationHeader); + try { + + // Write the Atom entry + StringWriter writer = new StringWriter(); + AtomFeedEntryUtil.writeFeedEntry(feedEntry, "atom_1.0", writer); + postMethod.setRequestHeader("Content-type", "application/atom+xml; charset=utf-8"); + postMethod.setRequestEntity(new StringRequestEntity(writer.toString())); + + httpClient.executeMethod(postMethod); + int status = postMethod.getStatusCode(); + + // Read the Atom entry + if (status == 200 || status == 201) { + Entry createdEntry = + AtomFeedEntryUtil + .readFeedEntry("atom_1.0", new InputStreamReader(postMethod.getResponseBodyAsStream())); + msg.setBody(createdEntry); + + } else if (status == 404) { + msg.setFaultBody(new NotFoundException()); + } else { + msg.setFaultBody(new ServiceRuntimeException("HTTP status code: " + status)); + } + + } catch (Exception e) { + msg.setFaultBody(new ServiceRuntimeException(e)); + } finally { + postMethod.releaseConnection(); + } + + return msg; + } + } + + /** + * Put operation invoker + */ + public static class PutInvoker extends AtomBindingInvoker { + + public PutInvoker(Operation operation, String uri, HttpClient httpClient, String authorizationHeader) { + super(operation, uri, httpClient, authorizationHeader); + } + + @Override + public Message invoke(Message msg) { + + // Put an entry + Object[] args = (Object[])msg.getBody(); + String id = (String)args[0]; + Entry feedEntry = (Entry)args[1]; + + // Send an HTTP PUT + PutMethod putMethod = new PutMethod(uri + "/" + id); + putMethod.setRequestHeader("Authorization", authorizationHeader); + try { + + // Write the Atom entry + StringWriter writer = new StringWriter(); + AtomFeedEntryUtil.writeFeedEntry(feedEntry, "atom_1.0", writer); + putMethod.setRequestHeader("Content-type", "application/atom+xml; charset=utf-8"); + putMethod.setRequestEntity(new StringRequestEntity(writer.toString())); + + httpClient.executeMethod(putMethod); + int status = putMethod.getStatusCode(); + + // Read the Atom entry + if (status == 200 || status == 201) { + try { + Entry updatedEntry = + AtomFeedEntryUtil.readFeedEntry("atom_1.0", new InputStreamReader(putMethod + .getResponseBodyAsStream())); + msg.setBody(updatedEntry); + } catch (Exception e) { + // Returning the updated entry is optional + } + + } else if (status == 404) { + msg.setFaultBody(new NotFoundException()); + } else { + msg.setFaultBody(new ServiceRuntimeException("HTTP status code: " + status)); + } + + } catch (Exception e) { + msg.setFaultBody(new ServiceRuntimeException(e)); + } finally { + putMethod.releaseConnection(); + } + + return msg; + } + } + + /** + * Delete operation invoker + */ + public static class DeleteInvoker extends AtomBindingInvoker { + + public DeleteInvoker(Operation operation, String uri, HttpClient httpClient, String authorizationHeader) { + super(operation, uri, httpClient, authorizationHeader); + } + + @Override + public Message invoke(Message msg) { + + // Delete an entry + String id = (String)((Object[])msg.getBody())[0]; + + // Send an HTTP DELETE + DeleteMethod deleteMethod = new DeleteMethod(uri + "/" + id); + deleteMethod.setRequestHeader("Authorization", authorizationHeader); + try { + httpClient.executeMethod(deleteMethod); + int status = deleteMethod.getStatusCode(); + + // Read the Atom entry + if (status == 200) { + msg.setBody(null); + + } else if (status == 404) { + msg.setFaultBody(new NotFoundException()); + } else { + msg.setFaultBody(new ServiceRuntimeException("HTTP status code: " + status)); + } + + } catch (Exception e) { + msg.setFaultBody(new ServiceRuntimeException(e)); + } finally { + deleteMethod.releaseConnection(); + } + + return msg; + } + } + + /** + * GetAll operation invoker + */ + public static class GetAllInvoker extends AtomBindingInvoker { + + public GetAllInvoker(Operation operation, String uri, HttpClient httpClient, String authorizationHeader) { + super(operation, uri, httpClient, authorizationHeader); + } + + @Override + public Message invoke(Message msg) { + + // Get a feed + + // Send an HTTP GET + GetMethod getMethod = new GetMethod(uri); + getMethod.setRequestHeader("Authorization", authorizationHeader); + try { + httpClient.executeMethod(getMethod); + int status = getMethod.getStatusCode(); + + // Read the Atom feed + if (status == 200) { + WireFeedInput input = new WireFeedInput(); + Feed feed = (Feed)input.build(new XmlReader(getMethod.getResponseBodyAsStream())); + msg.setBody(feed); + + } else if (status == 404) { + msg.setFaultBody(new NotFoundException()); + } else { + msg.setFaultBody(new ServiceRuntimeException("HTTP status code: " + status)); + } + + } catch (Exception e) { + msg.setFaultBody(new ServiceRuntimeException(e)); + } finally { + getMethod.releaseConnection(); + } + + return msg; + } + } + + /** + * PostMedia operation invoker + */ + public static class PostMediaInvoker extends AtomBindingInvoker { + + public PostMediaInvoker(Operation operation, String uri, HttpClient httpClient, String authorizationHeader) { + super(operation, uri, httpClient, authorizationHeader); + } + + @Override + public Message invoke(Message msg) { + // TODO implement + return super.invoke(msg); + } + } + + /** + * PutMedia operation invoker + */ + public static class PutMediaInvoker extends AtomBindingInvoker { + + public PutMediaInvoker(Operation operation, String uri, HttpClient httpClient, String authorizationHeader) { + super(operation, uri, httpClient, authorizationHeader); + } + + @Override + public Message invoke(Message msg) { + // TODO implement + return super.invoke(msg); + } + } + +} diff --git a/java/sca/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/AtomBindingProviderFactory.java b/java/sca/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/AtomBindingProviderFactory.java new file mode 100644 index 0000000000..9a858f899f --- /dev/null +++ b/java/sca/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/AtomBindingProviderFactory.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.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.databinding.DataBindingExtensionPoint; +import org.apache.tuscany.sca.databinding.Mediator; +import org.apache.tuscany.sca.databinding.TransformerExtensionPoint; +import org.apache.tuscany.sca.databinding.impl.MediatorImpl; +import org.apache.tuscany.sca.host.http.ServletHost; +import org.apache.tuscany.sca.host.http.ServletHostExtensionPoint; +import org.apache.tuscany.sca.invocation.MessageFactory; +import org.apache.tuscany.sca.provider.BindingProviderFactory; +import org.apache.tuscany.sca.provider.ReferenceBindingProvider; +import org.apache.tuscany.sca.provider.ServiceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + +/** + * Implementation of the Atom binding model. + * + * @version $Rev$ $Date$ + */ +public class AtomBindingProviderFactory implements BindingProviderFactory { + + private MessageFactory messageFactory; + private Mediator mediator; + private ServletHost servletHost; + + public AtomBindingProviderFactory(ExtensionPointRegistry extensionPoints) { + ServletHostExtensionPoint servletHosts = extensionPoints.getExtensionPoint(ServletHostExtensionPoint.class); + this.servletHost = servletHosts.getServletHosts().get(0); + ModelFactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class); + this.messageFactory = modelFactories.getFactory(MessageFactory.class); + this.mediator = new MediatorImpl(extensionPoints.getExtensionPoint(DataBindingExtensionPoint.class), + extensionPoints.getExtensionPoint(TransformerExtensionPoint.class)); + } + + public ReferenceBindingProvider createReferenceBindingProvider(RuntimeComponent component, + RuntimeComponentReference reference, + AtomBinding binding) { + return new AtomReferenceBindingProvider(component, reference, binding); + } + + public ServiceBindingProvider createServiceBindingProvider(RuntimeComponent component, + RuntimeComponentService service, + AtomBinding binding) { + return new AtomServiceBindingProvider(component, service, binding, servletHost, messageFactory, mediator); + } + + public Class getModelType() { + return AtomBinding.class; + } +} diff --git a/java/sca/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/AtomFeedEntryUtil.java b/java/sca/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/AtomFeedEntryUtil.java new file mode 100644 index 0000000000..7adbfca6e8 --- /dev/null +++ b/java/sca/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/AtomFeedEntryUtil.java @@ -0,0 +1,117 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.feed.provider; + +import java.io.IOException; +import java.io.Reader; +import java.io.StringWriter; +import java.io.Writer; +import java.util.ArrayList; +import java.util.List; + +import org.jdom.Document; +import org.jdom.Element; +import org.jdom.JDOMException; +import org.jdom.input.SAXBuilder; +import org.jdom.output.Format; +import org.jdom.output.XMLOutputter; + +import com.sun.syndication.feed.atom.Content; +import com.sun.syndication.feed.atom.Entry; +import com.sun.syndication.feed.atom.Feed; +import com.sun.syndication.io.FeedException; +import com.sun.syndication.io.WireFeedInput; +import com.sun.syndication.io.WireFeedOutput; + +/** + * Utility methods to read/write Atom entries. + * + * @version $Rev$ $Date$ + */ +class AtomFeedEntryUtil { + + /** + * Read an Atom entry + * + * @param request + * @return + * @throws IOException + * @throws JDOMException + * @throws FeedException + * @throws IllegalArgumentException + */ + static Entry readFeedEntry(String feedType, Reader reader) throws JDOMException, IOException, IllegalArgumentException, + FeedException { + SAXBuilder builder = new SAXBuilder(); + Document document = builder.build(reader); + Element root = document.getRootElement(); + root.detach(); + Feed feed = new Feed(); + feed.setFeedType(feedType); + WireFeedOutput wireFeedOutput = new WireFeedOutput(); + document = wireFeedOutput.outputJDom(feed); + document.getRootElement().addContent(root); + WireFeedInput input = new WireFeedInput(); + feed = (Feed)input.build(document); + Entry feedEntry = (Entry)feed.getEntries().get(0); + if (feedEntry.getContents().size() != 0) { + Content content = (Content)feedEntry.getContents().get(0); + if ("text/xml".equals(content.getType())) { + Element element = root.getChild("content", root.getNamespace()); + if (!element.getChildren().isEmpty()) { + element = (Element)element.getChildren().get(0); + XMLOutputter outputter = new XMLOutputter(); + StringWriter sw = new StringWriter(); + outputter.output(element, sw); + content.setValue(sw.toString()); + } + } + } + return feedEntry; + } + + /** + * Write an Atom entry. + * + * @param entry + * @param response + * @throws FeedException + * @throws IllegalArgumentException + * @throws IOException + * @throws ServletException + */ + static void writeFeedEntry(Entry feedEntry, String feedType, Writer writer) throws IllegalArgumentException, FeedException, + IOException { + Feed feed = new Feed(); + feed.setFeedType(feedType); + List feedEntries = new ArrayList(); + feedEntries.add(feedEntry); + feed.setEntries(feedEntries); + + WireFeedOutput wireFeedOutput = new WireFeedOutput(); + Document document = wireFeedOutput.outputJDom(feed); + Element root = document.getRootElement(); + Element element = (Element)root.getChildren().get(0); + XMLOutputter outputter = new XMLOutputter(); + outputter.setFormat(Format.getPrettyFormat()); + outputter.output(element, writer); + } + +} diff --git a/java/sca/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/AtomReferenceBindingProvider.java b/java/sca/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/AtomReferenceBindingProvider.java new file mode 100644 index 0000000000..d9bda1fb9a --- /dev/null +++ b/java/sca/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/AtomReferenceBindingProvider.java @@ -0,0 +1,116 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.feed.provider; + +import java.net.URI; + +import org.apache.commons.codec.binary.Base64; +import org.apache.commons.httpclient.Credentials; +import org.apache.commons.httpclient.HttpClient; +import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager; +import org.apache.commons.httpclient.UsernamePasswordCredentials; +import org.apache.commons.httpclient.auth.AuthScope; +import org.apache.tuscany.sca.binding.feed.AtomBinding; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.provider.ReferenceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; + +/** + * Implementation of the Atom binding provider. + * + * @version $Rev$ $Date$ + */ +class AtomReferenceBindingProvider implements ReferenceBindingProvider { + + private RuntimeComponentReference reference; + private AtomBinding binding; + private String authorizationHeader; + private HttpClient httpClient; + + /** + * Constructs a new AtomReferenceBindingProvider + * @param component + * @param reference + * @param binding + */ + AtomReferenceBindingProvider(RuntimeComponent component, + RuntimeComponentReference reference, + AtomBinding binding) { + this.reference = reference; + this.binding = binding; + + // Prepare authorization header + String authorization = "admin" + ":" + "admin"; + authorizationHeader = "Basic " + new String(Base64.encodeBase64(authorization.getBytes())); + + // Create an HTTP client + httpClient = new HttpClient(new MultiThreadedHttpConnectionManager()); + httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(60000); + } + + public Invoker createInvoker(Operation operation) { + String operationName = operation.getName(); + if (operationName.equals("get")) { + return new AtomBindingInvoker.GetInvoker(operation, binding.getURI(), httpClient, authorizationHeader); + } else if (operationName.equals("post")) { + return new AtomBindingInvoker.PostInvoker(operation, binding.getURI(), httpClient, authorizationHeader); + } else if (operationName.equals("put")) { + return new AtomBindingInvoker.PutInvoker(operation, binding.getURI(), httpClient, authorizationHeader); + } else if (operationName.equals("delete")) { + return new AtomBindingInvoker.DeleteInvoker(operation, binding.getURI(), httpClient, + authorizationHeader); + } else if (operationName.equals("getFeed") || operationName.equals("getAll")) { + return new AtomBindingInvoker.GetAllInvoker(operation, binding.getURI(), httpClient, + authorizationHeader); + } else if (operationName.equals("postMedia")) { + return new AtomBindingInvoker.PostMediaInvoker(operation, binding.getURI(), httpClient, + authorizationHeader); + } else if (operationName.equals("putMedia")) { + return new AtomBindingInvoker.PutMediaInvoker(operation, binding.getURI(), httpClient, + authorizationHeader); + } + + return new AtomBindingInvoker(operation, binding.getURI(), httpClient, authorizationHeader); + } + + public InterfaceContract getBindingInterfaceContract() { + return reference.getInterfaceContract(); + } + + public void start() { + + // Configure the HTTP client credentials + Credentials credentials = new UsernamePasswordCredentials("admin", "admin"); + httpClient.getParams().setAuthenticationPreemptive(true); + URI uri = URI.create(binding.getURI()); + httpClient.getState().setCredentials(new AuthScope(uri.getHost(), uri.getPort()), credentials); + } + + public void stop() { + } + + public boolean supportsOneWayInvocation() { + return false; + } + +} diff --git a/java/sca/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/AtomServiceBindingProvider.java b/java/sca/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/AtomServiceBindingProvider.java new file mode 100644 index 0000000000..23c36f51e3 --- /dev/null +++ b/java/sca/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/AtomServiceBindingProvider.java @@ -0,0 +1,87 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.feed.provider; + +import org.apache.tuscany.sca.binding.feed.AtomBinding; +import org.apache.tuscany.sca.databinding.Mediator; +import org.apache.tuscany.sca.host.http.ServletHost; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.invocation.MessageFactory; +import org.apache.tuscany.sca.provider.ServiceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; +import org.apache.tuscany.sca.runtime.RuntimeWire; + +/** + * Implementation of the Atom binding provider. + * + * @version $Rev$ $Date$ + */ +class AtomServiceBindingProvider implements ServiceBindingProvider { + + private RuntimeComponentService service; + private AtomBinding binding; + private ServletHost servletHost; + private MessageFactory messageFactory; + private String servletMapping; + private Mediator mediator; + + AtomServiceBindingProvider(RuntimeComponent component, + RuntimeComponentService service, + AtomBinding binding, + ServletHost servletHost, + MessageFactory messageFactory, + Mediator mediator) { + this.service = service; + this.binding = binding; + this.servletHost = servletHost; + this.messageFactory = messageFactory; + this.mediator = mediator; + } + + public InterfaceContract getBindingInterfaceContract() { + return service.getInterfaceContract(); + } + + public boolean supportsOneWayInvocation() { + return false; + } + + public void start() { + RuntimeComponentService componentService = (RuntimeComponentService)service; + RuntimeWire wire = componentService.getRuntimeWire(binding); + + FeedBindingListenerServlet servlet = + new FeedBindingListenerServlet(wire, messageFactory, mediator, "atom_1.0"); + + servletMapping = binding.getURI(); + if (!servletMapping.endsWith("/")) { + servletMapping += "/"; + } + if (!servletMapping.endsWith("*")) { + servletMapping += "*"; + } + servletHost.addServletMapping(servletMapping, servlet); + } + + public void stop() { + servletHost.removeServletMapping(servletMapping); + } +} diff --git a/java/sca/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/FeedBindingListenerServlet.java b/java/sca/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/FeedBindingListenerServlet.java new file mode 100644 index 0000000000..89366456f5 --- /dev/null +++ b/java/sca/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/FeedBindingListenerServlet.java @@ -0,0 +1,788 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.feed.provider; + +import java.io.IOException; +import java.io.OutputStreamWriter; +import java.io.UnsupportedEncodingException; +import java.io.Writer; +import java.net.URLDecoder; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.StringTokenizer; +import java.util.logging.Logger; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.xml.namespace.QName; + +import org.apache.commons.codec.binary.Base64; +import org.apache.tuscany.sca.data.collection.Item; +import org.apache.tuscany.sca.databinding.Mediator; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; +import org.apache.tuscany.sca.interfacedef.util.XMLType; +import org.apache.tuscany.sca.invocation.InvocationChain; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.invocation.MessageFactory; +import org.apache.tuscany.sca.runtime.RuntimeWire; +import org.jdom.Document; +import org.jdom.Element; +import org.jdom.JDOMException; +import org.jdom.Namespace; +import org.jdom.output.Format; +import org.jdom.output.XMLOutputter; + +import com.sun.syndication.feed.atom.Content; +import com.sun.syndication.feed.atom.Entry; +import com.sun.syndication.feed.atom.Feed; +import com.sun.syndication.feed.atom.Link; +import com.sun.syndication.feed.synd.SyndFeed; +import com.sun.syndication.feed.synd.SyndFeedImpl; +import com.sun.syndication.io.FeedException; +import com.sun.syndication.io.SyndFeedOutput; +import com.sun.syndication.io.WireFeedOutput; + +/** + * A resource collection binding listener, implemented as a Servlet and + * registered in a Servlet host provided by the SCA hosting runtime. + * + * @version $Rev$ $Date$ + */ +class FeedBindingListenerServlet extends HttpServlet { + private static final Logger logger = Logger.getLogger(FeedBindingListenerServlet.class.getName()); + private static final long serialVersionUID = 1L; + + private static final Namespace APP_NS = Namespace.getNamespace("app", "http://purl.org/atom/app#"); + private static final Namespace ATOM_NS = Namespace.getNamespace("atom", "http://www.w3.org/2005/Atom"); + + private RuntimeWire wire; + private Invoker getFeedInvoker; + private Invoker getAllInvoker; + private Invoker queryInvoker; + private Invoker getInvoker; + private Invoker postInvoker; + private Invoker postMediaInvoker; + private Invoker putInvoker; + private Invoker putMediaInvoker; + private Invoker deleteInvoker; + private MessageFactory messageFactory; + private String feedType; + private Mediator mediator; + private DataType itemClassType; + private DataType itemXMLType; + private boolean supportsFeedEntries; + + /** + * Constructs a new binding listener. + * + * @param wire + * @param messageFactory + * @param feedType + */ + FeedBindingListenerServlet(RuntimeWire wire, MessageFactory messageFactory, Mediator mediator, String feedType) { + this.wire = wire; + this.messageFactory = messageFactory; + this.mediator = mediator; + this.feedType = feedType; + + // Get the invokers for the supported operations + Operation getOperation = null; + for (InvocationChain invocationChain : this.wire.getInvocationChains()) { + invocationChain.setAllowsPassByReference(true); + Operation operation = invocationChain.getTargetOperation(); + String operationName = operation.getName(); + if (operationName.equals("getFeed")) { + getFeedInvoker = invocationChain.getHeadInvoker(); + } else if (operationName.equals("getAll")) { + getAllInvoker = invocationChain.getHeadInvoker(); + } else if (operationName.equals("query")) { + queryInvoker = invocationChain.getHeadInvoker(); + } else if (operationName.equals("get")) { + getInvoker = invocationChain.getHeadInvoker(); + getOperation = operation; + } else if (operationName.equals("put")) { + putInvoker = invocationChain.getHeadInvoker(); + } else if (operationName.equals("putMedia")) { + putMediaInvoker = invocationChain.getHeadInvoker(); + } else if (operationName.equals("post")) { + postInvoker = invocationChain.getHeadInvoker(); + } else if (operationName.equals("postMedia")) { + postMediaInvoker = invocationChain.getHeadInvoker(); + } else if (operationName.equals("delete")) { + deleteInvoker = invocationChain.getHeadInvoker(); + } + } + + // Determine the collection item type + itemXMLType = new DataTypeImpl>(String.class.getName(), String.class, String.class); + Class itemClass = getOperation.getOutputType().getPhysical(); + if (itemClass == Entry.class) { + supportsFeedEntries = true; + } + DataType outputType = getOperation.getOutputType(); + QName qname = outputType.getLogical().getElementName(); + qname = new QName(qname.getNamespaceURI(), itemClass.getSimpleName()); + itemClassType = new DataTypeImpl("java:complexType", itemClass, new XMLType(qname, null)); + + } + + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + + // No authentication required for a get request + + // Get the request path + String path = URLDecoder.decode(request.getRequestURI().substring(request.getServletPath().length()), "UTF-8"); + + // The feedType parameter is used to override what type of feed is going + // to be produced + String requestFeedType = request.getParameter("feedType"); + if (requestFeedType == null) + requestFeedType = feedType; + + logger.info(">>> FeedEndPointServlet (" + requestFeedType + ") " + request.getRequestURI()); + + // Handle an Atom request + if (requestFeedType.startsWith("atom_")) { + + if (path != null && path.equals("/atomsvc")) { + + // Return the Atom service document + response.setContentType("application/atomsvc+xml; charset=utf-8"); + Document document = new Document(); + Element service = new Element("service", APP_NS); + document.setRootElement(service); + + Element workspace = new Element("workspace", APP_NS); + Element title = new Element("title", ATOM_NS); + title.setText("resource"); + workspace.addContent(title); + service.addContent(workspace); + + Element collection = new Element("collection", APP_NS); + String href = request.getRequestURL().toString(); + href = href.substring(0, href.length() - "/atomsvc".length()); + collection.setAttribute("href", href); + Element collectionTitle = new Element("title", ATOM_NS); + collectionTitle.setText("entries"); + collection.addContent(collectionTitle); + workspace.addContent(collection); + + XMLOutputter outputter = new XMLOutputter(); + Format format = Format.getPrettyFormat(); + format.setEncoding("UTF-8"); + outputter.setFormat(format); + outputter.output(document, getWriter(response)); + + } else if (path == null || path.length() == 0 || path.equals("/")) { + + // Return a feed containing the entries in the collection + Feed feed = null; + if (supportsFeedEntries) { + + // The service implementation supports feed entries, invoke its getFeed operation + Message requestMessage = messageFactory.createMessage(); + Message responseMessage = getFeedInvoker.invoke(requestMessage); + if (responseMessage.isFault()) { + throw new ServletException((Throwable)responseMessage.getBody()); + } + feed = (Feed)responseMessage.getBody(); + + } else { + + // The service implementation does not support feed entries, + // invoke its getAll operation to get the data item collection, then create + // feed entries from the items + Message requestMessage = messageFactory.createMessage(); + Message responseMessage; + if (request.getQueryString() != null) { + requestMessage.setBody(new Object[] {request.getQueryString()}); + responseMessage = queryInvoker.invoke(requestMessage); + } else { + responseMessage = getAllInvoker.invoke(requestMessage); + } + if (responseMessage.isFault()) { + throw new ServletException((Throwable)responseMessage.getBody()); + } + org.apache.tuscany.sca.data.collection.Entry[] collection = + (org.apache.tuscany.sca.data.collection.Entry[])responseMessage.getBody(); + if (collection != null) { + // Create the feed + feed = new Feed(); + feed.setTitle("Feed"); + for (org.apache.tuscany.sca.data.collection.Entry entry: collection) { + Entry feedEntry = createFeedEntry(entry); + feed.getEntries().add(feedEntry); + } + } + } + if (feed != null) { + + // Write the Atom feed + response.setContentType("application/atom+xml; charset=utf-8"); + feed.setFeedType(requestFeedType); + WireFeedOutput feedOutput = new WireFeedOutput(); + try { + feedOutput.output(feed, getWriter(response)); + } catch (FeedException e) { + throw new ServletException(e); + } + } else { + response.sendError(HttpServletResponse.SC_NOT_FOUND); + } + + } else if (path.startsWith("/")) { + + // Return a specific entry in the collection + Entry feedEntry; + + // Invoke the get operation on the service implementation + Message requestMessage = messageFactory.createMessage(); + String id = path.substring(1); + requestMessage.setBody(new Object[] {id}); + Message responseMessage = getInvoker.invoke(requestMessage); + if (responseMessage.isFault()) { + throw new ServletException((Throwable)responseMessage.getBody()); + } + if (supportsFeedEntries) { + + // The service implementation returns a feed entry + feedEntry = responseMessage.getBody(); + + } else { + + // The service implementation only returns a data item, create an entry + // from it + feedEntry = createFeedEntry(new org.apache.tuscany.sca.data.collection.Entry(id, responseMessage.getBody())); + } + + // Write the Atom entry + if (feedEntry != null) { + response.setContentType("application/atom+xml; charset=utf-8"); + try { + AtomFeedEntryUtil.writeFeedEntry(feedEntry, feedType, getWriter(response)); + } catch (FeedException e) { + throw new ServletException(e); + } + } else { + response.sendError(HttpServletResponse.SC_NOT_FOUND); + } + + } else { + + // Path doesn't match any known pattern + response.sendError(HttpServletResponse.SC_NOT_FOUND); + } + } else { + + // Handle an RSS request + if (path == null || path.length() == 0 || path.equals("/")) { + + // Return an RSS feed containing the entries in the collection + Feed feed = null; + if (supportsFeedEntries) { + + // The service implementation supports feed entries, invoke its getFeed operation + Message requestMessage = messageFactory.createMessage(); + Message responseMessage = getFeedInvoker.invoke(requestMessage); + if (responseMessage.isFault()) { + throw new ServletException((Throwable)responseMessage.getBody()); + } + feed = (Feed)responseMessage.getBody(); + + } else { + + // The service implementation does not support feed entries, invoke its + // getAll operation to get the data item collection. then create feed entries + // from the data items + Message requestMessage = messageFactory.createMessage(); + Message responseMessage; + if (request.getQueryString() != null) { + requestMessage.setBody(new Object[] {request.getQueryString()}); + responseMessage = queryInvoker.invoke(requestMessage); + } else { + responseMessage = getAllInvoker.invoke(requestMessage); + } + if (responseMessage.isFault()) { + throw new ServletException((Throwable)responseMessage.getBody()); + } + org.apache.tuscany.sca.data.collection.Entry[] collection = + (org.apache.tuscany.sca.data.collection.Entry[])responseMessage.getBody(); + if (collection != null) { + // Create the feed + feed = new Feed(); + feed.setTitle("Feed"); + for (org.apache.tuscany.sca.data.collection.Entry entry: collection) { + Entry feedEntry = createFeedEntry(entry); + feed.getEntries().add(feedEntry); + } + } + } + + // Convert to an RSS feed + if (feed != null) { + response.setContentType("application/rss+xml; charset=utf-8"); + feed.setFeedType("atom_1.0"); + SyndFeed syndFeed = new SyndFeedImpl(feed); + syndFeed.setFeedType(requestFeedType); + syndFeed.setLink(path); + SyndFeedOutput syndOutput = new SyndFeedOutput(); + try { + syndOutput.output(syndFeed, getWriter(response)); + } catch (FeedException e) { + throw new ServletException(e); + } + } else { + response.sendError(HttpServletResponse.SC_NOT_FOUND); + } + } else { + response.sendError(HttpServletResponse.SC_NOT_FOUND); + } + } + } + + /** + * Create an Atom entry from a data collection entry. + * @param entry + * @return + */ + private Entry createFeedEntry(org.apache.tuscany.sca.data.collection.Entry entry) { + Object key = entry.getKey(); + Object data = entry.getData(); + if (data instanceof Item) { + Item item = (Item)data; + + Entry feedEntry = new Entry(); + feedEntry.setId(key.toString()); + feedEntry.setTitle(item.getTitle()); + + String value = item.getContents(); + if (value != null) { + Content content = new Content(); + content.setType("text/xml"); + content.setValue(value); + List contents = new ArrayList(); + contents.add(content); + feedEntry.setContents(contents); + } + + String href = item.getLink(); + if (href == null) { + href = key.toString(); + } + Link link = new Link(); + link.setRel("edit"); + link.setHref(href); + feedEntry.getOtherLinks().add(link); + link = new Link(); + link.setRel("alternate"); + link.setHref(href); + feedEntry.getAlternateLinks().add(link); + + Date date = item.getDate(); + if (date == null) { + date = new Date(); + } + feedEntry.setCreated(date); + return feedEntry; + + } else if (data != null) { + Entry feedEntry = new Entry(); + feedEntry.setId(key.toString()); + feedEntry.setTitle("item"); + + // Convert the item to XML + String value = mediator.mediate(data, itemClassType, itemXMLType, null).toString(); + + Content content = new Content(); + content.setType("text/xml"); + content.setValue(value); + List contents = new ArrayList(); + contents.add(content); + feedEntry.setContents(contents); + + Link link = new Link(); + link.setRel("edit"); + link.setHref(key.toString()); + feedEntry.getOtherLinks().add(link); + link = new Link(); + link.setRel("alternate"); + link.setHref(key.toString()); + feedEntry.getAlternateLinks().add(link); + + feedEntry.setCreated(new Date()); + return feedEntry; + } else { + return null; + } + } + + /** + * Create a data collection entry from an Atom entry. + * @param feedEntry + * @return + */ + private org.apache.tuscany.sca.data.collection.Entry createEntry(Entry feedEntry) { + if (feedEntry != null) { + if (itemClassType.getPhysical() == Item.class) { + String key = feedEntry.getId(); + + Item item = new Item(); + item.setTitle(feedEntry.getTitle()); + + List contents = feedEntry.getContents(); + if (!contents.isEmpty()) { + Content content = (Content)contents.get(0); + String value = content.getValue(); + item.setContents(value); + } + + for (Object l : feedEntry.getOtherLinks()) { + Link link = (Link)l; + if (link.getRel() == null || "edit".equals(link.getRel())) { + String href = link.getHref(); + if (href.startsWith("null/")) { + href = href.substring(5); + } + item.setLink(href); + break; + } + } + + item.setDate(feedEntry.getCreated()); + + return new org.apache.tuscany.sca.data.collection.Entry(key, item); + + } else { + String key = feedEntry.getId(); + + // Create the item from XML + List contents = feedEntry.getContents(); + if (contents.isEmpty()) { + return null; + } + Content content = (Content)contents.get(0); + String value = content.getValue(); + Object data = mediator.mediate(value, itemXMLType, itemClassType, null); + + return new org.apache.tuscany.sca.data.collection.Entry(key, data); + } + } else { + return null; + } + } + + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, + IOException { + + // Authenticate the user + String user = processAuthorizationHeader(request); + if (user == null) { + unauthorized(response); + return; + } + + // Get the request path + String path = URLDecoder.decode(request.getRequestURI().substring(request.getServletPath().length()), "UTF-8"); + + if (path == null || path.length() == 0 || path.equals("/")) { + Entry createdFeedEntry = null; + + // Create a new Atom entry + String contentType = request.getContentType(); + if (contentType != null && contentType.startsWith("application/atom+xml")) { + + // Read the entry from the request + Entry feedEntry; + try { + feedEntry = AtomFeedEntryUtil.readFeedEntry(feedType, request.getReader()); + } catch (JDOMException e) { + throw new ServletException(e); + } catch (FeedException e) { + throw new ServletException(e); + } + + // Let the component implementation create it + if (supportsFeedEntries) { + + // The service implementation supports feed entries, pass the entry to it + Message requestMessage = messageFactory.createMessage(); + requestMessage.setBody(new Object[] {feedEntry}); + Message responseMessage = postInvoker.invoke(requestMessage); + if (responseMessage.isFault()) { + throw new ServletException((Throwable)responseMessage.getBody()); + } + createdFeedEntry = responseMessage.getBody(); + } else { + + // The service implementation does not support feed entries, pass the data item to it + Message requestMessage = messageFactory.createMessage(); + org.apache.tuscany.sca.data.collection.Entry entry = createEntry(feedEntry); + requestMessage.setBody(new Object[] {entry.getKey(), entry.getData()}); + Message responseMessage = postInvoker.invoke(requestMessage); + if (responseMessage.isFault()) { + throw new ServletException((Throwable)responseMessage.getBody()); + } + entry.setKey(responseMessage.getBody()); + createdFeedEntry = createFeedEntry(entry); + } + + } else if (contentType != null) { + + // Create a new media entry + + // Get incoming headers + String title = request.getHeader("Title"); + String slug = request.getHeader("Slug"); + + // Let the component implementation create the media entry + Message requestMessage = messageFactory.createMessage(); + requestMessage.setBody(new Object[] {title, slug, contentType, request.getInputStream()}); + Message responseMessage = postMediaInvoker.invoke(requestMessage); + if (responseMessage.isFault()) { + throw new ServletException((Throwable)responseMessage.getBody()); + } + createdFeedEntry = responseMessage.getBody(); + } else { + response.sendError(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE); + } + + // A new entry was created successfully + if (createdFeedEntry != null) { + + // Set location of the created entry in the Location header + for (Object l : createdFeedEntry.getOtherLinks()) { + Link link = (Link)l; + if (link.getRel() == null || "edit".equals(link.getRel())) { + response.addHeader("Location", link.getHref()); + break; + } + } + + // Write the created Atom entry + response.setStatus(HttpServletResponse.SC_CREATED); + response.setContentType("application/atom+xml; charset=utf-8"); + try { + AtomFeedEntryUtil.writeFeedEntry(createdFeedEntry, feedType, getWriter(response)); + } catch (FeedException e) { + throw new ServletException(e); + } + + } else { + response.sendError(HttpServletResponse.SC_NOT_FOUND); + } + + } else { + response.sendError(HttpServletResponse.SC_NOT_FOUND); + } + } + + private Writer getWriter(HttpServletResponse response) throws UnsupportedEncodingException, IOException { + Writer writer = new OutputStreamWriter(response.getOutputStream(), "UTF-8"); + return writer; + } + + @Override + protected void doPut(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + + // Authenticate the user + String user = processAuthorizationHeader(request); + if (user == null) { + unauthorized(response); + return; + } + + // Get the request path + String path = URLDecoder.decode(request.getRequestURI().substring(request.getServletPath().length()), "UTF-8"); + + if (path != null && path.startsWith("/")) { + String id = path.substring(1); + + // Update an Atom entry + String contentType = request.getContentType(); + if (contentType != null && contentType.startsWith("application/atom+xml")) { + + // Read the entry from the request + Entry feedEntry; + try { + feedEntry = AtomFeedEntryUtil.readFeedEntry(feedType, request.getReader()); + } catch (JDOMException e) { + throw new ServletException(e); + } catch (FeedException e) { + throw new ServletException(e); + } + + // Let the component implementation create it + if (supportsFeedEntries) { + + // The service implementation supports feed entries, pass the entry to it + Message requestMessage = messageFactory.createMessage(); + requestMessage.setBody(new Object[] {id, feedEntry}); + Message responseMessage = putInvoker.invoke(requestMessage); + if (responseMessage.isFault()) { + Object body = responseMessage.getBody(); + if (body.getClass().getName().endsWith(".NotFoundException")) { + response.sendError(HttpServletResponse.SC_NOT_FOUND); + } else { + throw new ServletException((Throwable)responseMessage.getBody()); + } + } + } else { + + // The service implementation does not support feed entries, pass the data item to it + Message requestMessage = messageFactory.createMessage(); + org.apache.tuscany.sca.data.collection.Entry entry = createEntry(feedEntry); + requestMessage.setBody(new Object[] {entry.getKey(), entry.getData()}); + Message responseMessage = putInvoker.invoke(requestMessage); + if (responseMessage.isFault()) { + Object body = responseMessage.getBody(); + if (body.getClass().getName().endsWith(".NotFoundException")) { + response.sendError(HttpServletResponse.SC_NOT_FOUND); + } else { + throw new ServletException((Throwable)responseMessage.getBody()); + } + } + } + + } else if (contentType != null) { + + // Updated a media entry + + // Let the component implementation create the media entry + Message requestMessage = messageFactory.createMessage(); + requestMessage.setBody(new Object[] {id, contentType, request.getInputStream()}); + Message responseMessage = putMediaInvoker.invoke(requestMessage); + Object body = responseMessage.getBody(); + if (responseMessage.isFault()) { + if (body.getClass().getName().endsWith(".NotFoundException")) { + response.sendError(HttpServletResponse.SC_NOT_FOUND); + } else { + throw new ServletException((Throwable)responseMessage.getBody()); + } + } + } else { + response.sendError(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE); + } + } else { + response.sendError(HttpServletResponse.SC_NOT_FOUND); + } + } + + @Override + protected void doDelete(HttpServletRequest request, HttpServletResponse response) throws ServletException, + IOException { + + // Authenticate the user + String user = processAuthorizationHeader(request); + if (user == null) { + unauthorized(response); + return; + } + + // Get the request path + String path = URLDecoder.decode(request.getRequestURI().substring(request.getServletPath().length()), "UTF-8"); + + String id; + if (path != null && path.startsWith("/")) { + id = path.substring(1); + } else { + id = ""; + } + + // Delete a specific entry from the collection + Message requestMessage = messageFactory.createMessage(); + requestMessage.setBody(new Object[] {id}); + Message responseMessage = deleteInvoker.invoke(requestMessage); + if (responseMessage.isFault()) { + Object body = responseMessage.getBody(); + if (body.getClass().getName().endsWith(".NotFoundException")) { + response.sendError(HttpServletResponse.SC_NOT_FOUND); + } else { + throw new ServletException((Throwable)responseMessage.getBody()); + } + } + } + + /** + * Process the authorization header + * + * @param request + * @return + * @throws ServletException + */ + private String processAuthorizationHeader(HttpServletRequest request) throws ServletException { + try { + String authorization = request.getHeader("Authorization"); + if (authorization != null) { + StringTokenizer tokens = new StringTokenizer(authorization); + if (tokens.hasMoreTokens()) { + String basic = tokens.nextToken(); + if (basic.equalsIgnoreCase("Basic")) { + String credentials = tokens.nextToken(); + String userAndPassword = new String(Base64.decodeBase64(credentials.getBytes())); + int colon = userAndPassword.indexOf(":"); + if (colon != -1) { + String user = userAndPassword.substring(0, colon); + String password = userAndPassword.substring(colon + 1); + + // Authenticate the User. + if (authenticate(user, password)) { + return user; + } + } + } + } + } + } catch (Exception e) { + throw new ServletException(e); + } + return null; + } + + /** + * Authenticate a user. + * + * @param user + * @param password + * @return + */ + private boolean authenticate(String user, String password) { + + // TODO Handle this using SCA security policies + //FIXME Why are we using endsWith instead of equals here?? + return ("admin".endsWith(user) && "admin".equals(password)); + } + + /** + * Reject an unauthorized request. + * + * @param response + */ + private void unauthorized(HttpServletResponse response) throws IOException { + response.setHeader("WWW-Authenticate", "BASIC realm=\"Tuscany\""); + response.sendError(HttpServletResponse.SC_UNAUTHORIZED); + } +} diff --git a/java/sca/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/RSSBindingInvoker.java b/java/sca/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/RSSBindingInvoker.java new file mode 100644 index 0000000000..c5bd3ec009 --- /dev/null +++ b/java/sca/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/RSSBindingInvoker.java @@ -0,0 +1,91 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.feed.provider; + +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.logging.Logger; + +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.invocation.DataExchangeSemantics; + +import com.sun.syndication.feed.atom.Feed; +import com.sun.syndication.feed.synd.SyndFeed; +import com.sun.syndication.io.FeedException; +import com.sun.syndication.io.SyndFeedInput; +import com.sun.syndication.io.WireFeedInput; +import com.sun.syndication.io.XmlReader; + +/** + * Invoker for the RSS binding. + * + * @version $Rev$ $Date$ + */ +class RSSBindingInvoker implements Invoker, DataExchangeSemantics { + private static final Logger logger = Logger.getLogger(RSSBindingInvoker.class.getName()); + + private String feedType; + private String uri; + + RSSBindingInvoker(String uri, String feedType) { + this.uri = uri; + this.feedType = feedType; + } + + public Message invoke(Message msg) { + try { + logger.info(">>> RSSBindingInvoker (" + feedType + ") " + uri); + + // Read the configured feed URI into a Feed object + Feed feed; + if (feedType.startsWith("atom_")) { + + // Read an Atom feed + WireFeedInput input = new WireFeedInput(); + feed = (Feed)input.build(new XmlReader(new URL(uri))); + } else { + + // Read an RSS feed and convert it to an Atom feed + SyndFeedInput input = new SyndFeedInput(); + SyndFeed syndFeed = input.build(new XmlReader(new URL(uri))); + feed = (Feed)syndFeed.createWireFeed("atom_1.0"); + } + + //FIXME Support conversion to data-api entries + + msg.setBody(feed); + + } catch (MalformedURLException e) { + msg.setFaultBody(e); + } catch (IllegalArgumentException e) { + msg.setFaultBody(e); + } catch (FeedException e) { + msg.setFaultBody(e); + } catch (IOException e) { + msg.setFaultBody(e); + } + return msg; + } + + public boolean allowsPassByReference() { + return true; + } +} diff --git a/java/sca/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/RSSBindingProviderFactory.java b/java/sca/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/RSSBindingProviderFactory.java new file mode 100644 index 0000000000..f4c336e12b --- /dev/null +++ b/java/sca/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/RSSBindingProviderFactory.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.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.databinding.DataBindingExtensionPoint; +import org.apache.tuscany.sca.databinding.Mediator; +import org.apache.tuscany.sca.databinding.TransformerExtensionPoint; +import org.apache.tuscany.sca.databinding.impl.MediatorImpl; +import org.apache.tuscany.sca.host.http.ServletHost; +import org.apache.tuscany.sca.host.http.ServletHostExtensionPoint; +import org.apache.tuscany.sca.invocation.MessageFactory; +import org.apache.tuscany.sca.provider.BindingProviderFactory; +import org.apache.tuscany.sca.provider.ReferenceBindingProvider; +import org.apache.tuscany.sca.provider.ServiceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + +/** + * Implementation of the RSS binding provider factory. + * + * @version $Rev$ $Date$ + */ +public class RSSBindingProviderFactory implements BindingProviderFactory { + + private MessageFactory messageFactory; + private Mediator mediator; + private ServletHost servletHost; + + public RSSBindingProviderFactory(ExtensionPointRegistry extensionPoints) { + ServletHostExtensionPoint servletHosts = extensionPoints.getExtensionPoint(ServletHostExtensionPoint.class); + this.servletHost = servletHosts.getServletHosts().get(0); + ModelFactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class); + this.messageFactory = modelFactories.getFactory(MessageFactory.class); + this.mediator = new MediatorImpl(extensionPoints.getExtensionPoint(DataBindingExtensionPoint.class), + extensionPoints.getExtensionPoint(TransformerExtensionPoint.class)); + } + + public ReferenceBindingProvider createReferenceBindingProvider(RuntimeComponent component, + RuntimeComponentReference reference, + RSSBinding binding) { + return new RSSReferenceBindingProvider(component, reference, binding); + } + + public ServiceBindingProvider createServiceBindingProvider(RuntimeComponent component, + RuntimeComponentService service, + RSSBinding binding) { + return new RSSServiceBindingProvider(component, service, binding, servletHost, messageFactory, mediator); + } + + public Class getModelType() { + return RSSBinding.class; + } +} diff --git a/java/sca/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/RSSReferenceBindingProvider.java b/java/sca/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/RSSReferenceBindingProvider.java new file mode 100644 index 0000000000..278ed9cb7e --- /dev/null +++ b/java/sca/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/RSSReferenceBindingProvider.java @@ -0,0 +1,65 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.feed.provider; + +import org.apache.tuscany.sca.binding.feed.RSSBinding; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.provider.ReferenceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; + +/** + * Implementation of the RSS binding provider. + * + * @version $Rev$ $Date$ + */ +class RSSReferenceBindingProvider implements ReferenceBindingProvider { + + private RuntimeComponentReference reference; + private RSSBinding binding; + + RSSReferenceBindingProvider(RuntimeComponent component, + RuntimeComponentReference reference, + RSSBinding binding) { + this.reference = reference; + this.binding = binding; + } + + public Invoker createInvoker(Operation operation) { + return new RSSBindingInvoker(binding.getURI(), "rss_2.0"); + } + + public boolean supportsOneWayInvocation() { + return false; + } + + public InterfaceContract getBindingInterfaceContract() { + return reference.getInterfaceContract(); + } + + public void start() { + } + + public void stop() { + } + +} diff --git a/java/sca/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/RSSServiceBindingProvider.java b/java/sca/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/RSSServiceBindingProvider.java new file mode 100644 index 0000000000..779b28cef6 --- /dev/null +++ b/java/sca/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/RSSServiceBindingProvider.java @@ -0,0 +1,85 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.feed.provider; + +import org.apache.tuscany.sca.binding.feed.RSSBinding; +import org.apache.tuscany.sca.databinding.Mediator; +import org.apache.tuscany.sca.host.http.ServletHost; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.invocation.MessageFactory; +import org.apache.tuscany.sca.provider.ServiceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; +import org.apache.tuscany.sca.runtime.RuntimeWire; + +/** + * Implementation of the RSS binding provider. + * + * @version $Rev$ $Date$ + */ +class RSSServiceBindingProvider implements ServiceBindingProvider { + + private RuntimeComponentService service; + private RSSBinding binding; + private ServletHost servletHost; + private MessageFactory messageFactory; + private String servletMapping; + private Mediator mediator; + + RSSServiceBindingProvider(RuntimeComponent component, + RuntimeComponentService service, + RSSBinding binding, + ServletHost servletHost, + MessageFactory messageFactory, + Mediator mediator) { + this.service = service; + this.binding = binding; + this.servletHost = servletHost; + this.messageFactory = messageFactory; + this.mediator = mediator; + } + + public InterfaceContract getBindingInterfaceContract() { + return service.getInterfaceContract(); + } + + public boolean supportsOneWayInvocation() { + return false; + } + + public void start() { + RuntimeComponentService componentService = (RuntimeComponentService)service; + RuntimeWire wire = componentService.getRuntimeWire(binding); + + FeedBindingListenerServlet servlet = + new FeedBindingListenerServlet(wire, messageFactory, mediator, "rss_2.0"); + + servletMapping = binding.getURI(); + servletHost.addServletMapping(servletMapping, servlet); + + // Save the actual binding URI in the binding + binding.setURI(servletHost.getURLMapping(binding.getURI()).toString()); + } + + public void stop() { + servletHost.removeServletMapping(servletMapping); + } + +} diff --git a/java/sca/modules/binding-feed/src/main/resources/META-INF/services/org.apache.tuscany.sca.binding.feed.AtomBindingFactory b/java/sca/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/java/sca/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/java/sca/modules/binding-feed/src/main/resources/META-INF/services/org.apache.tuscany.sca.binding.feed.RSSBindingFactory b/java/sca/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/java/sca/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/java/sca/modules/binding-feed/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor b/java/sca/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/java/sca/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/java/sca/modules/binding-feed/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory b/java/sca/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/java/sca/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/java/sca/modules/binding-feed/src/test/java/org/apache/tuscany/sca/binding/feed/Consumer.java b/java/sca/modules/binding-feed/src/test/java/org/apache/tuscany/sca/binding/feed/Consumer.java new file mode 100644 index 0000000000..4a33637121 --- /dev/null +++ b/java/sca/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/java/sca/modules/binding-feed/src/test/java/org/apache/tuscany/sca/binding/feed/CustomerClient.java b/java/sca/modules/binding-feed/src/test/java/org/apache/tuscany/sca/binding/feed/CustomerClient.java new file mode 100644 index 0000000000..b7416011ba --- /dev/null +++ b/java/sca/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/java/sca/modules/binding-feed/src/test/java/org/apache/tuscany/sca/binding/feed/CustomerClientImpl.java b/java/sca/modules/binding-feed/src/test/java/org/apache/tuscany/sca/binding/feed/CustomerClientImpl.java new file mode 100644 index 0000000000..884e954036 --- /dev/null +++ b/java/sca/modules/binding-feed/src/test/java/org/apache/tuscany/sca/binding/feed/CustomerClientImpl.java @@ -0,0 +1,97 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.feed; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.sca.binding.feed.collection.Collection; +import org.osoa.sca.annotations.Reference; + +import com.sun.syndication.feed.atom.Content; +import com.sun.syndication.feed.atom.Entry; +import com.sun.syndication.feed.atom.Feed; + +public class CustomerClientImpl implements CustomerClient { + + @Reference + public Collection resourceCollection; + + public void testCustomerCollection() throws Exception { + + Entry newEntry = newEntry("Sponge Bob"); + System.out.println(">>> post entry=" + newEntry.getTitle()); + newEntry = resourceCollection.post(newEntry); + System.out.println("<<< post id=" + newEntry.getId() + " entry=" + newEntry.getTitle()); + + newEntry = newEntry("Jane Bond"); + System.out.println(">>> post entry=" + newEntry.getTitle()); + newEntry = resourceCollection.post(newEntry); + System.out.println("<<< post id=" + newEntry.getId() + " entry=" + newEntry.getTitle()); + + System.out.println(">>> get id=" + newEntry.getId()); + Entry entry = resourceCollection.get(newEntry.getId()); + System.out.println("<<< get id=" + entry.getId() + " entry=" + entry.getTitle()); + + System.out.println(">>> put id=" + newEntry.getId() + " entry=" + entry.getTitle()); + resourceCollection.put(entry.getId(), updateEntry(entry, "James Bond")); + System.out.println("<<< put id=" + entry.getId() + " entry=" + entry.getTitle()); + + System.out.println(">>> delete id=" + entry.getId()); + resourceCollection.delete(entry.getId()); + System.out.println("<<< delete id=" + entry.getId()); + + System.out.println(">>> get collection"); + Feed feed = resourceCollection.getFeed(); + System.out.println("<<< get collection"); + for (Object o : feed.getEntries()) { + Entry e = (Entry)o; + System.out.println("id = " + e.getId() + " entry = " + e.getTitle()); + } + } + + private Entry newEntry(String value) { + + Entry entry = new Entry(); + entry.setTitle("customer " + value); + + Content content = new Content(); + content.setValue(value); + content.setType(Content.TEXT); + List list = new ArrayList(); + list.add(content); + entry.setContents(list); + + return entry; + } + + private Entry updateEntry(Entry entry, String value) { + + entry.setTitle("customer " + value); + Content content = new Content(); + content.setValue(value); + content.setType(Content.TEXT); + List list = new ArrayList(); + list.add(content); + entry.setContents(list); + + return entry; + } +} diff --git a/java/sca/modules/binding-feed/src/test/java/org/apache/tuscany/sca/binding/feed/CustomerCollectionImpl.java b/java/sca/modules/binding-feed/src/test/java/org/apache/tuscany/sca/binding/feed/CustomerCollectionImpl.java new file mode 100644 index 0000000000..ca4a5a1946 --- /dev/null +++ b/java/sca/modules/binding-feed/src/test/java/org/apache/tuscany/sca/binding/feed/CustomerCollectionImpl.java @@ -0,0 +1,136 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.feed; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +import org.apache.tuscany.sca.binding.feed.collection.Collection; +import org.osoa.sca.annotations.Scope; + +import com.sun.syndication.feed.atom.Content; +import com.sun.syndication.feed.atom.Entry; +import com.sun.syndication.feed.atom.Feed; +import com.sun.syndication.feed.atom.Link; + +@Scope("COMPOSITE") +public class CustomerCollectionImpl implements Collection { + + private Map entries = new HashMap(); + + public CustomerCollectionImpl() { + + for (int i = 0; i < 4; i++) { + String id = "urn:uuid:customer-" + UUID.randomUUID().toString(); + + Entry entry = new Entry(); + entry.setTitle("customer " + "Jane Doe_" + String.valueOf(i)); + entry.setId(id); + + Content content = new Content(); + content.setValue("Jane Doe_" + String.valueOf(i)); + content.setType(Content.TEXT); + entry.setContents(Collections.singletonList(content)); + + List links = new ArrayList(); + Link link = new Link(); + link.setRel("edit"); + link.setHref("" + id); + links.add(link); + entry.setOtherLinks(links); + + links = new ArrayList(); + link = new Link(); + link.setRel("alternate"); + link.setHref("" + id); + links.add(link); + entry.setAlternateLinks(links); + + entry.setCreated(new Date()); + + entries.put(id, entry); + System.out.println(">>> id=" + id); + } + } + + public Entry post(Entry entry) { + System.out.println(">>> ResourceCollectionImpl.post entry=" + entry.getTitle()); + + String id = "urn:uuid:customer-" + UUID.randomUUID().toString(); + entry.setId(id); + + List links = new ArrayList(); + Link link = new Link(); + link.setRel("edit"); + link.setHref("" + id); + links.add(link); + entry.setOtherLinks(links); + + links = new ArrayList(); + link = new Link(); + link.setRel("alternate"); + link.setHref("" + id); + links.add(link); + entry.setAlternateLinks(links); + + entry.setCreated(new Date()); + + entries.put(id, entry); + System.out.println(">>> ResourceCollectionImpl.post return id=" + id); + + return entry; + } + + public Entry get(String id) { + System.out.println(">>> ResourceCollectionImpl.get id=" + id); + return entries.get(id); + } + + public void put(String id, Entry entry) { + System.out.println(">>> ResourceCollectionImpl.put id=" + id + " entry=" + entry.getTitle()); + + entry.setUpdated(new Date()); + entries.put(id, entry); + } + + public void delete(String id) { + System.out.println(">>> ResourceCollectionImpl.delete id=" + id); + entries.remove(id); + } + + @SuppressWarnings("unchecked") + public Feed getFeed() { + System.out.println(">>> ResourceCollectionImpl.get collection"); + + Feed feed = new Feed(); + feed.setTitle("customers"); + Content subtitle = new Content(); + subtitle.setValue("This is a sample feed"); + feed.setSubtitle(subtitle); + feed.getEntries().addAll(entries.values()); + return feed; + } + +} diff --git a/java/sca/modules/binding-feed/src/test/java/org/apache/tuscany/sca/binding/feed/Provider.java b/java/sca/modules/binding-feed/src/test/java/org/apache/tuscany/sca/binding/feed/Provider.java new file mode 100644 index 0000000000..a9ddc1a2c8 --- /dev/null +++ b/java/sca/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/java/sca/modules/binding-feed/src/test/resources/org/apache/tuscany/sca/binding/feed/Consumer.composite b/java/sca/modules/binding-feed/src/test/resources/org/apache/tuscany/sca/binding/feed/Consumer.composite new file mode 100644 index 0000000000..1987c042e6 --- /dev/null +++ b/java/sca/modules/binding-feed/src/test/resources/org/apache/tuscany/sca/binding/feed/Consumer.composite @@ -0,0 +1,32 @@ + + + + + + + + + + + + diff --git a/java/sca/modules/binding-feed/src/test/resources/org/apache/tuscany/sca/binding/feed/Provider.composite b/java/sca/modules/binding-feed/src/test/resources/org/apache/tuscany/sca/binding/feed/Provider.composite new file mode 100644 index 0000000000..9268fbe211 --- /dev/null +++ b/java/sca/modules/binding-feed/src/test/resources/org/apache/tuscany/sca/binding/feed/Provider.composite @@ -0,0 +1,33 @@ + + + + + + + + + + + + + diff --git a/java/sca/modules/binding-gdata2-runtime/LICENSE b/java/sca/modules/binding-gdata2-runtime/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/java/sca/modules/binding-gdata2-runtime/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/java/sca/modules/binding-gdata2-runtime/NOTICE b/java/sca/modules/binding-gdata2-runtime/NOTICE new file mode 100644 index 0000000000..fdfa0e9faa --- /dev/null +++ b/java/sca/modules/binding-gdata2-runtime/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2008 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/java/sca/modules/binding-gdata2-runtime/deployGdataToMaven.sh b/java/sca/modules/binding-gdata2-runtime/deployGdataToMaven.sh new file mode 100755 index 0000000000..306ad19f66 --- /dev/null +++ b/java/sca/modules/binding-gdata2-runtime/deployGdataToMaven.sh @@ -0,0 +1,7 @@ +mvn gpg:sign-and-deploy-file -DgroupId=com.google.gdata -DartifactId=gdata-core -Dversion=1.0 -Dpackaging=jar -Dfile=gdata-core-1.0.jar -DrepositoryId=apache.people -Durl=scp://people.apache.org/home/lresende/public_html/google-gdata/maven -Dkeyname=lresende + +mvn gpg:sign-and-deploy-file -DgroupId=com.google.gdata -DartifactId=gdata-client -Dversion=1.0 -Dpackaging=jar -Dfile=gdata-client-1.0.jar -DrepositoryId=apache.people -Durl=scp://people.apache.org/home/lresende/public_html/google-gdata/maven -Dkeyname=lresende + +mvn gpg:sign-and-deploy-file -DgroupId=com.google.gdata -DartifactId=gdata-client-meta -Dversion=1.0 -Dpackaging=jar -Dfile=gdata-client-meta-1.0.jar -DrepositoryId=apache.people -Durl=scp://people.apache.org/home/lresende/public_html/google-gdata/maven -Dkeyname=lresende + +mvn gpg:sign-and-deploy-file -DgroupId=com.google.gdata -DartifactId=gdata-media -Dversion=1.0 -Dpackaging=jar -Dfile=gdata-media-1.0.jar -DrepositoryId=apache.people -Durl=scp://people.apache.org/home/lresende/public_html/google-gdata/maven -Dkeyname=lresende diff --git a/java/sca/modules/binding-gdata2-runtime/pom.xml b/java/sca/modules/binding-gdata2-runtime/pom.xml new file mode 100644 index 0000000000..0768864c1c --- /dev/null +++ b/java/sca/modules/binding-gdata2-runtime/pom.xml @@ -0,0 +1,183 @@ + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 2.0-SNAPSHOT + ../pom.xml + + + tuscany-binding-gdata2-runtime + Apache Tuscany SCA GData Binding Extension Runtime + + + + com.google.gdata + http://people.apache.org/~lresende/google-gdata/maven/ + + + + + + org.apache.tuscany.sca + tuscany-binding-gdata2 + 2.0-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-assembly + 2.0-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-interface-java + 2.0-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-data-api + 2.0-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-core-spi + 2.0-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-databinding + 2.0-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-host-http + 2.0-SNAPSHOT + + + + commons-httpclient + commons-httpclient + 3.1 + + + + javax.servlet + servlet-api + 2.4 + provided + + + + org.apache.tuscany.sca + tuscany-host-jetty + 2.0-SNAPSHOT + test + + + + org.apache.tuscany.sca + tuscany-implementation-java-runtime + 2.0-SNAPSHOT + test + + + + org.apache.tuscany.sca + tuscany-host-embedded + 2.0-SNAPSHOT + test + + + + com.google.gdata + gdata-core + 1.0 + + + + com.google.gdata + gdata-client + 1.0 + + + + commons-codec + commons-codec + 1.3 + + + commons-codec + commons-codec + + + + + + commons-logging + commons-logging + 1.1.1 + + + servlet-api + javax.servlet + + + avalon-framework + avalon-framework + + + + + + junit + junit + 4.5 + test + + + + + + + + + org.apache.felix + maven-bundle-plugin + + + + ${tuscany.version} + org.apache.tuscany.sca.binding.atom.abdera + ${pom.name} + org.apache.tuscany.sca.binding.atom* + + + + + + + diff --git a/java/sca/modules/binding-gdata2-runtime/src/main/java/org/apache/tuscany/sca/binding/gdata/collection/Collection.java b/java/sca/modules/binding-gdata2-runtime/src/main/java/org/apache/tuscany/sca/binding/gdata/collection/Collection.java new file mode 100644 index 0000000000..2679071ea8 --- /dev/null +++ b/java/sca/modules/binding-gdata2-runtime/src/main/java/org/apache/tuscany/sca/binding/gdata/collection/Collection.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.gdata.collection; + +import com.google.gdata.data.BaseEntry; +import com.google.gdata.data.BaseFeed; + +import org.apache.tuscany.sca.implementation.data.collection.NotFoundException; +import org.osoa.sca.annotations.Remotable; + +/** + * Provides access to a collection of resources using Atom. + * + * @version $Rev$ $Date$ + */ +@Remotable +public interface Collection { + + /** + * Get an Atom feed for a collection of resources. + * + * @return the Atom feed + */ + BaseFeed getFeed(); + + /** + * Get an Atom feed for a collection of resources resulting + * from a query. + * + * @param queryString a query string + * @return the Atom feed + */ + BaseFeed query(String queryString); + + /** + * Creates a new entry. + * + * @param entry + * @return + */ + BaseEntry post(BaseEntry entry); + + /** + * Retrieves an entry. + * + * @param id + * @return + */ + BaseEntry get(String id) throws NotFoundException; + + /** + * Update an entry. + * + * @param id + * @param entry + * @return + */ + BaseEntry put(String id, BaseEntry entry) throws NotFoundException; + + /** + * Delete an entry. + * + * @param id + */ + void delete(String id) throws NotFoundException; +} diff --git a/java/sca/modules/binding-gdata2-runtime/src/main/java/org/apache/tuscany/sca/binding/gdata/collection/MediaCollection.java b/java/sca/modules/binding-gdata2-runtime/src/main/java/org/apache/tuscany/sca/binding/gdata/collection/MediaCollection.java new file mode 100644 index 0000000000..b9252d097a --- /dev/null +++ b/java/sca/modules/binding-gdata2-runtime/src/main/java/org/apache/tuscany/sca/binding/gdata/collection/MediaCollection.java @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.gdata.collection; + +import com.google.gdata.data.BaseEntry; +import java.io.InputStream; + +import org.osoa.sca.annotations.Remotable; + +import org.apache.tuscany.sca.implementation.data.collection.NotFoundException; + +/** + * 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 + */ + BaseEntry postMedia(String title, String slug, String contentType, InputStream media); + + /** + * Update a media entry. + * + * @param id + * @param contentType + * @param media + * @return + */ + void putMedia(String id, String contentType, InputStream media) throws NotFoundException; +} diff --git a/java/sca/modules/binding-gdata2-runtime/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/GDataBindingInvoker.java b/java/sca/modules/binding-gdata2-runtime/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/GDataBindingInvoker.java new file mode 100644 index 0000000000..d2c5ed4017 --- /dev/null +++ b/java/sca/modules/binding-gdata2-runtime/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/GDataBindingInvoker.java @@ -0,0 +1,510 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.gdata.provider; + +import java.util.logging.Level; +import java.util.logging.Logger; +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.google.gdata.client.GoogleService; +import com.google.gdata.client.Query; +import com.google.gdata.data.BaseEntry; +import com.google.gdata.data.BaseFeed; +import com.google.gdata.data.Entry; +import com.google.gdata.data.ExtensionProfile; +import com.google.gdata.data.Feed; +import com.google.gdata.data.ParseSource; +import com.google.gdata.util.AuthenticationException; +import java.net.URL; +import com.google.gdata.util.ResourceNotFoundException; +import com.google.gdata.util.common.xml.XmlWriter; +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.gdata.GDataBinding; +import org.apache.tuscany.sca.data.collection.NotFoundException; +import org.apache.tuscany.sca.invocation.DataExchangeSemantics; + +/** + * Invoker for the Atom binding. + * + * @version $Rev$ $Date$ + */ +class GDataBindingInvoker implements Invoker, DataExchangeSemantics { + + Operation operation; + GDataBinding binding; + HttpClient httpClient; + String authorizationHeader; + GoogleService service; + + GDataBindingInvoker(Operation operation, GDataBinding binding, HttpClient httpClient, String authorizationHeader) { + this.operation = operation; + this.binding = binding; + this.httpClient = httpClient; + this.authorizationHeader = authorizationHeader; + + //Create the GoogleService + if (!binding.getServiceType().equals("sca")) { + this.service = new GoogleService(binding.getServiceType(), ""); + + try { + service.setUserCredentials(binding.getUsername(), binding.getPassword()); + } catch (AuthenticationException ex) { + //FIXME - promote the exception + Logger.getLogger(GDataReferenceBindingProvider.class.getName()).log(Level.SEVERE, null, ex); + } + + this.service.setConnectTimeout(60000); + } + } + + public Message invoke(Message msg) { + // Shouldn't get here, as the only supported methods are + // defined in the ResourceCollection interface, and implemented + // by specific invoker subclasses + throw new UnsupportedOperationException(operation.getName()); + } + + /** + * Get operation invoker + */ + public static class GetInvoker extends GDataBindingInvoker { + + public GetInvoker(Operation operation, GDataBinding binding, HttpClient httpClient, String authorizationHeader) { + super(operation, binding, httpClient, authorizationHeader); + } + + @Override + public Message invoke(Message msg) { + + BaseEntry entry; + GetMethod getMethod = null; + boolean parsing = false; + + String id = (String) ((Object[]) msg.getBody())[0]; + + try { + // serviceType == "sca" - Send an HTTP GET + if (service == null) { + getMethod = new GetMethod(binding.getURI() + "/" + id); + getMethod.setRequestHeader("Authorization", authorizationHeader); + + httpClient.executeMethod(getMethod); + int status = getMethod.getStatusCode(); + + // Read the Atom feed + if (status == 200) { + + parsing = true; + + ParseSource parser = new ParseSource(getMethod.getResponseBodyAsStream()); + entry = BaseEntry.readEntry(parser); + + msg.setBody(entry); + + } else if (status == 404) { + msg.setFaultBody(new NotFoundException()); + } else { + msg.setFaultBody(new ServiceRuntimeException("HTTP status code: " + status)); + } + + } // serviceType != "sca" - Use GoogleService + else { + entry = service.getEntry(new URL(id), Entry.class); + msg.setBody(entry); + } + } catch (ResourceNotFoundException ex) { + msg.setFaultBody(new ResourceNotFoundException("Invalid Resource at " + binding.getURI())); + } catch (Exception ex) { + msg.setFaultBody(new ServiceRuntimeException(ex)); + } finally { + if (service == null && !parsing) { + getMethod.releaseConnection(); + } + return msg; + } + + } + } + + /** + * Post operation invoker + */ + public static class PostInvoker extends GDataBindingInvoker { + + public PostInvoker(Operation operation, GDataBinding binding, HttpClient httpClient, String authorizationHeader) { + super(operation, binding, httpClient, authorizationHeader); + } + + @Override + public Message invoke(Message msg) { + + BaseEntry entry = (BaseEntry) ((Object[]) msg.getBody())[0]; + BaseEntry returnedEntry; + + PostMethod postMethod = null; + boolean parsing = false; + + try { + // serviceType == "sca" - Send an HTTP POST + if (service == null) { + postMethod = new PostMethod(binding.getURI()); + postMethod.setRequestHeader("Authorization", authorizationHeader); + + // Write the Atom entry + StringWriter strWriter = new StringWriter(); + XmlWriter writer = new XmlWriter(strWriter); + entry.generateAtom(writer, new ExtensionProfile()); + writer.flush(); + writer.close(); + + postMethod.setRequestHeader("Content-type", "application/atom+xml; charset=utf-8"); + postMethod.setRequestEntity(new StringRequestEntity(strWriter.toString())); + + httpClient.executeMethod(postMethod); + int status = postMethod.getStatusCode(); + + // Read the Atom feed + if (status == 200 || status == 201) { + + parsing = true; + + ParseSource parser = new ParseSource(postMethod.getResponseBodyAsStream()); + returnedEntry = BaseEntry.readEntry(parser); + + msg.setBody(returnedEntry); + + } else if (status == 404) { + msg.setFaultBody(new NotFoundException()); + } else { + msg.setFaultBody(new ServiceRuntimeException("HTTP status code: " + status)); + } + + } // serviceType != "sca" - Use GoogleService + else { + returnedEntry = service.insert(new URL(binding.getURI()), entry); + msg.setBody(returnedEntry); + } + } catch (ResourceNotFoundException ex) { + msg.setFaultBody(new ResourceNotFoundException("Invalid Resource at " + binding.getURI())); + } catch (Exception ex) { + msg.setFaultBody(new ServiceRuntimeException(ex)); + } finally { + if (service == null && !parsing) { + postMethod.releaseConnection(); + } + return msg; + } + + } + } + + /** + * Put operation invoker + */ + public static class PutInvoker extends GDataBindingInvoker { + + public PutInvoker(Operation operation, GDataBinding binding, HttpClient httpClient, String authorizationHeader) { + super(operation, binding, httpClient, authorizationHeader); + } + + @Override + public Message invoke(Message msg) { + + BaseEntry updatedEntry; + String id = (String) ((Object[]) msg.getBody())[0]; + BaseEntry entry = (BaseEntry) ((Object[]) msg.getBody())[1]; + + PutMethod putMethod = null; + boolean parsing = false; + + try { + // serviceType == "sca" - Send an HTTP PUT + if (service == null) { + putMethod = new PutMethod(binding.getURI() + "/" + id); + putMethod.setRequestHeader("Authorization", authorizationHeader); + + // Write the Atom entry + StringWriter strWriter = new StringWriter(); + XmlWriter writer = new XmlWriter(strWriter); + entry.generateAtom(writer, new ExtensionProfile()); + writer.flush(); + writer.close(); + + putMethod.setRequestHeader("Content-type", "application/atom+xml; charset=utf-8"); + putMethod.setRequestEntity(new StringRequestEntity(strWriter.toString())); + + httpClient.executeMethod(putMethod); + int status = putMethod.getStatusCode(); + + // Read the Atom feed + if (status == 200 || status == 201) { + + parsing = true; + + ParseSource parser = new ParseSource(putMethod.getResponseBodyAsStream()); + updatedEntry = BaseEntry.readEntry(parser); + + msg.setBody(updatedEntry); + + } else if (status == 404) { + msg.setFaultBody(new NotFoundException()); + } else { + msg.setFaultBody(new ServiceRuntimeException("HTTP status code: " + status)); + } + + } // serviceType != "sca" - Use GoogleService + else { + updatedEntry = service.update(new URL(id), entry); + msg.setBody(updatedEntry); + } + } catch (ResourceNotFoundException ex) { + msg.setFaultBody(new ResourceNotFoundException("Invalid Resource at " + binding.getURI())); + } catch (Exception ex) { + msg.setFaultBody(new ServiceRuntimeException(ex)); + } finally { + if (service == null && !parsing) { + putMethod.releaseConnection(); + } + return msg; + } + } + } + + /** + * Delete operation invoker + */ + public static class DeleteInvoker extends GDataBindingInvoker { + + public DeleteInvoker(Operation operation, GDataBinding binding, HttpClient httpClient, String authorizationHeader) { + super(operation, binding, httpClient, authorizationHeader); + } + + @Override + public Message invoke(Message msg) { + + DeleteMethod deleteMethod = null; + + String id = (String) ((Object[]) msg.getBody())[0]; + + try { + // serviceType == "sca" - Send an HTTP DELETE + if (service == null) { + deleteMethod = new DeleteMethod(binding.getURI() + "/" + id); + deleteMethod.setRequestHeader("Authorization", authorizationHeader); + + httpClient.executeMethod(deleteMethod); + int status = deleteMethod.getStatusCode(); + + // Read the Atom feed + if (status == 200) { + msg.setBody(null); + + } else if (status == 404) { + msg.setFaultBody(new NotFoundException()); + } else { + msg.setFaultBody(new ServiceRuntimeException("HTTP status code: " + status)); + } + + } // serviceType != "sca" - Use GoogleService + else { + service.delete(new URL(id)); + msg.setBody(null); + } + } catch (ResourceNotFoundException ex) { + msg.setFaultBody(new ResourceNotFoundException("Invalid Resource at " + binding.getURI())); + } catch (Exception ex) { + msg.setFaultBody(new ServiceRuntimeException(ex)); + } finally { + if (service == null) { + deleteMethod.releaseConnection(); + } + return msg; + } + + } + } + + /** + * GetAll operation invoker + */ + public static class GetAllInvoker extends GDataBindingInvoker { + + public GetAllInvoker(Operation operation, GDataBinding binding, HttpClient httpClient, String authorizationHeader) { + super(operation, binding, httpClient, authorizationHeader); + } + + @Override + public Message invoke(Message msg) { + + BaseFeed feed; + GetMethod getMethod = null; + boolean parsing = false; + + try { + // serviceType == "sca" - Send an HTTP GET + if (service == null) { + getMethod = new GetMethod(binding.getURI()); + getMethod.setRequestHeader("Authorization", authorizationHeader); + + httpClient.executeMethod(getMethod); + int status = getMethod.getStatusCode(); + + // Read the Atom feed + if (status == 200) { + + parsing = true; + + ParseSource parser = new ParseSource(getMethod.getResponseBodyAsStream()); + feed = BaseFeed.readFeed(parser); + + msg.setBody(feed); + + } else if (status == 404) { + msg.setFaultBody(new NotFoundException()); + } else { + msg.setFaultBody(new ServiceRuntimeException("HTTP status code: " + status)); + } + + } // serviceType != "sca" - Use GoogleService + else { + feed = service.getFeed(new URL(binding.getURI()), Feed.class); + msg.setBody(feed); + } + } catch (ResourceNotFoundException ex) { + msg.setFaultBody(new ResourceNotFoundException("Invalid Resource at " + binding.getURI())); + } catch (Exception ex) { + msg.setFaultBody(new ServiceRuntimeException(ex)); + } finally { + if (service == null && !parsing) { + getMethod.releaseConnection(); + } + return msg; + } + } + } + + /** + * Query operation invoker + */ + public static class QueryInvoker extends GDataBindingInvoker { + + public QueryInvoker(Operation operation, GDataBinding binding, HttpClient httpClient, String authorizationHeader) { + super(operation, binding, httpClient, authorizationHeader); + } + + @Override + public Message invoke(Message msg) { + + BaseFeed feed; + GetMethod getMethod = null; + boolean parsing = false; + + String queryString = (String) ((Object[]) msg.getBody())[0]; + + try { + // serviceType == "sca" - Send an HTTP GET + if (service == null) { + getMethod = new GetMethod(binding.getURI()); + getMethod.setRequestHeader("Authorization", authorizationHeader); + getMethod.setQueryString(queryString); + + httpClient.executeMethod(getMethod); + int status = getMethod.getStatusCode(); + + // Read the Atom feed + if (status == 200) { + + parsing = true; + + ParseSource parser = new ParseSource(getMethod.getResponseBodyAsStream()); + feed = BaseFeed.readFeed(parser); + + msg.setBody(feed); + + } else if (status == 404) { + msg.setFaultBody(new NotFoundException()); + } else { + msg.setFaultBody(new ServiceRuntimeException("HTTP status code: " + status)); + } + + } // serviceType != "sca" - Use GoogleService + else { + Query query = new Query(new URL(binding.getURI())); + query.setFullTextQuery(queryString); + feed = service.query(query, Feed.class); + msg.setBody(feed); + } + } catch (ResourceNotFoundException ex) { + msg.setFaultBody(new ResourceNotFoundException("Invalid Resource at " + binding.getURI())); + } catch (Exception ex) { + msg.setFaultBody(new ServiceRuntimeException(ex)); + } finally { + if (service == null && !parsing) { + getMethod.releaseConnection(); + } + return msg; + } + } + } + + /** + * PostMedia operation invoker + */ + public static class PostMediaInvoker extends GDataBindingInvoker { + + public PostMediaInvoker(Operation operation, GDataBinding binding, HttpClient httpClient, String authorizationHeader) { + super(operation, binding, httpClient, authorizationHeader); + } + + @Override + public Message invoke(Message msg) { + // TODO implement + return super.invoke(msg); + } + } + + /** + * PutMedia operation invoker + */ + public static class PutMediaInvoker extends GDataBindingInvoker { + + public PutMediaInvoker(Operation operation, GDataBinding binding, HttpClient httpClient, String authorizationHeader) { + super(operation, binding, httpClient, authorizationHeader); + } + + @Override + public Message invoke(Message msg) { + // TODO implement + return super.invoke(msg); + } + } + + public boolean allowsPassByReference() { + return true; + } +} diff --git a/java/sca/modules/binding-gdata2-runtime/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/GDataBindingListenerServlet.java b/java/sca/modules/binding-gdata2-runtime/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/GDataBindingListenerServlet.java new file mode 100644 index 0000000000..1f9318070d --- /dev/null +++ b/java/sca/modules/binding-gdata2-runtime/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/GDataBindingListenerServlet.java @@ -0,0 +1,426 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.gdata.provider; + +import com.google.gdata.data.BaseEntry; +import com.google.gdata.data.BaseFeed; +import com.google.gdata.data.ExtensionProfile; +import com.google.gdata.data.Link; +import com.google.gdata.data.ParseSource; +import com.google.gdata.util.ServiceException; +import com.google.gdata.util.common.xml.XmlWriter; +import java.io.IOException; +import java.net.URLDecoder; +import java.util.logging.Logger; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.runtime.RuntimeWire; +import org.apache.tuscany.sca.invocation.MessageFactory; +import org.apache.tuscany.sca.databinding.Mediator; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.InvocationChain; +import org.apache.tuscany.sca.invocation.Message; + +class GDataBindingListenerServlet extends HttpServlet { + + private static final Logger logger = Logger.getLogger(GDataBindingListenerServlet.class.getName()); + private RuntimeWire wire; + private Invoker getFeedInvoker; + private Invoker queryInvoker; + private Invoker getInvoker; + private Invoker postInvoker; + private Invoker postMediaInvoker; + private Invoker putInvoker; + private Invoker putMediaInvoker; + private Invoker deleteInvoker; + private MessageFactory messageFactory; + private String title; + private Mediator mediator; +// private DataType itemClassType; +// private DataType itemXMLType; +// private boolean supportsFeedEntries; + + GDataBindingListenerServlet(RuntimeWire wire, MessageFactory messageFactory, Mediator mediator, String title) { + this.wire = wire; + this.messageFactory = messageFactory; + this.mediator = mediator; + this.title = title; + + // Get the invokers for the supported operations + //Operation getOperation = null; + for (InvocationChain invocationChain : this.wire.getInvocationChains()) { + invocationChain.setAllowsPassByReference(true); + Operation operation = invocationChain.getTargetOperation(); + String operationName = operation.getName(); + if (operationName.equals("getFeed")) { + getFeedInvoker = invocationChain.getHeadInvoker(); + } else if (operationName.equals("query")) { + queryInvoker = invocationChain.getHeadInvoker(); + } else if (operationName.equals("get")) { + getInvoker = invocationChain.getHeadInvoker(); + //getOperation = operation; + } else if (operationName.equals("put")) { + putInvoker = invocationChain.getHeadInvoker(); + } else if (operationName.equals("putMedia")) { + putMediaInvoker = invocationChain.getHeadInvoker(); + } else if (operationName.equals("post")) { + postInvoker = invocationChain.getHeadInvoker(); + } else if (operationName.equals("postMedia")) { + postMediaInvoker = invocationChain.getHeadInvoker(); + } else if (operationName.equals("delete")) { + deleteInvoker = invocationChain.getHeadInvoker(); + } + } + +// // Determine the collection item type +// itemXMLType = new DataTypeImpl>(String.class.getName(), String.class, String.class); +// Class itemClass = getOperation.getOutputType().getPhysical(); +// if (itemClass == BaseEntry.class) { +// supportsFeedEntries = true; +// } +// DataType outputType = getOperation.getOutputType(); +// QName qname = outputType.getLogical().getElementName(); +// qname = new QName(qname.getNamespaceURI(), itemClass.getSimpleName()); +// itemClassType = new DataTypeImpl("java:complexType", itemClass, new XMLType(qname, null)); + } + + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + + int servletPathLength = request.getContextPath().length() + request.getServletPath().length(); + + String path = URLDecoder.decode(request.getRequestURI().substring(servletPathLength), "UTF-8"); + + logger.fine("get " + request.getRequestURI()); + + if (path != null && path.equals("/atomsvc")) { + //FIX-ME - Doing nothing + } else if (path == null || path.length() == 0 || path.equals("/")) { + + // Return a feed containing the entries in the collection + BaseFeed feed = null; + + Message requestMessage = messageFactory.createMessage(); + Message responseMessage; + if (request.getQueryString() != null) { + requestMessage.setBody(new Object[]{request.getQueryString()}); + responseMessage = queryInvoker.invoke(requestMessage); + } else { + responseMessage = getFeedInvoker.invoke(requestMessage); + } + if (responseMessage.isFault()) { + throw new ServletException((Throwable) responseMessage.getBody()); + } + + // The service implementation supports feed entries, invoke its getFeed operation + feed = (BaseFeed) responseMessage.getBody(); + + if (feed != null) { + + // Write the Atom feed + response.setContentType("application/atom+xml; charset=utf-8"); + try { + + XmlWriter writer = new XmlWriter(response.getWriter()); + feed.generateAtom(writer, new ExtensionProfile()); + writer.flush(); + writer.close(); + + } catch (IOException ioe) { + throw new ServletException(ioe); + } + } else { + response.sendError(HttpServletResponse.SC_NOT_FOUND); + } + + } else if (path.startsWith("/")) { + // Return a specific entry in the collection + BaseEntry feedEntry; + + // Invoke the get operation on the service implementation + Message requestMessage = messageFactory.createMessage(); + String id = path.substring(1); + requestMessage.setBody(new Object[]{id}); + Message responseMessage = getInvoker.invoke(requestMessage); + if (responseMessage.isFault()) { + throw new ServletException((Throwable) responseMessage.getBody()); + } + + // The service implementation returns a feed entry + feedEntry = responseMessage.getBody(); + + // Write the Atom entry + if (feedEntry != null) { + response.setContentType("application/atom+xml; charset=utf-8"); + try { + XmlWriter writer = new XmlWriter(response.getWriter()); + feedEntry.generateAtom(writer, new ExtensionProfile()); + writer.flush(); + writer.close(); + } catch (IOException ioe) { + throw new ServletException(ioe); + } + } else { + response.sendError(HttpServletResponse.SC_NOT_FOUND); + } + } else { + // Path doesn't match any known pattern + response.sendError(HttpServletResponse.SC_NOT_FOUND); + } + } + + @Override + protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + + // FIX-ME: Authenticate the user + +// String user = processAuthorizationHeader(request); +// if (user == null) { +// unauthorized(response); +// return; +// } + + // Get the request path + String path = URLDecoder.decode(request.getRequestURI().substring(request.getServletPath().length()), "UTF-8"); + + if (path == null || path.length() == 0 || path.equals("/")) { + + BaseEntry createdFeedEntry = null; + + // Create a new Atom entry + String contentType = request.getContentType(); + if (contentType != null && contentType.startsWith("application/atom+xml")) { + + // Read the entry from the request + BaseEntry feedEntry; + try { + ParseSource parser = new ParseSource(request.getReader()); + feedEntry = BaseEntry.readEntry(parser); + + } catch (ServiceException ex) { + throw new ServletException(ex); + } + + // The service implementation supports feed entries, pass the entry to it + Message requestMessage = messageFactory.createMessage(); + requestMessage.setBody(new Object[]{feedEntry}); + Message responseMessage = postInvoker.invoke(requestMessage); + + if (responseMessage.isFault()) { + throw new ServletException((Throwable) responseMessage.getBody()); + } + + createdFeedEntry = responseMessage.getBody(); + + } else if (contentType != null) { + + // Create a new media entry + + // Get incoming headers + String reqTitle = request.getHeader("Title"); + String slug = request.getHeader("Slug"); + + // Let the component implementation create the media entry + Message requestMessage = messageFactory.createMessage(); + requestMessage.setBody(new Object[]{reqTitle, slug, contentType, request.getInputStream()}); + Message responseMessage = postMediaInvoker.invoke(requestMessage); + + if (responseMessage.isFault()) { + throw new ServletException((Throwable) responseMessage.getBody()); + } + createdFeedEntry = responseMessage.getBody(); + } else { + response.sendError(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE); + } + + // A new entry was created successfully + if (createdFeedEntry != null) { + + // Set location of the created entry in the Location header + Link link = createdFeedEntry.getSelfLink(); + if (link != null) { + response.addHeader("Location", link.getHref().toString()); + } + + // Write the created Atom entry + response.setStatus(HttpServletResponse.SC_CREATED); + response.setContentType("application/atom+xml; charset=utf-8"); + try { + + XmlWriter writer = new XmlWriter(response.getWriter()); + createdFeedEntry.generateAtom(writer, new ExtensionProfile()); + writer.flush(); + writer.close(); + + } catch (IOException ioe) { + throw new ServletException(ioe); + } + + } 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 { + + // FIX-ME: Authenticate the user + +// String user = processAuthorizationHeader(request); +// if (user == null) { +// unauthorized(response); +// return; +// } + + // Get the request path + String path = request.getRequestURI().substring(request.getServletPath().length()); + + BaseEntry createdFeedEntry = null; + + if (path != null && path.startsWith("/")) { + String id = path.substring(1); + + // Update an Atom entry + String contentType = request.getContentType(); + if (contentType != null && contentType.startsWith("application/atom+xml")) { + + // Read the entry from the request + BaseEntry feedEntry; + try { + ParseSource parser = new ParseSource(request.getReader()); + feedEntry = BaseEntry.readEntry(parser); + + } catch (ServiceException ex) { + throw new ServletException(ex); + } + + // Let the component implementation create it + + // The service implementation supports feed entries, pass the entry to it + Message requestMessage = messageFactory.createMessage(); + requestMessage.setBody(new Object[]{id, feedEntry}); + Message responseMessage = putInvoker.invoke(requestMessage); + + if (responseMessage.isFault()) { + Object body = responseMessage.getBody(); + if (body.getClass().getName().endsWith(".NotFoundException")) { + response.sendError(HttpServletResponse.SC_NOT_FOUND); + } else { + throw new ServletException((Throwable) responseMessage.getBody()); + } + } + + createdFeedEntry = responseMessage.getBody(); + + } else if (contentType != null) { + + // Updated a media entry + + // Let the component implementation create the media entry + Message requestMessage = messageFactory.createMessage(); + requestMessage.setBody(new Object[]{id, contentType, request.getInputStream()}); + Message responseMessage = putMediaInvoker.invoke(requestMessage); + Object body = responseMessage.getBody(); + if (responseMessage.isFault()) { + if (body.getClass().getName().endsWith(".NotFoundException")) { + response.sendError(HttpServletResponse.SC_NOT_FOUND); + } else { + throw new ServletException((Throwable) responseMessage.getBody()); + } + } + + createdFeedEntry = responseMessage.getBody(); + + } else { + response.sendError(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE); + } + + // A new entry was created successfully + if (createdFeedEntry != null) { + + // Set location of the created entry in the Location header + Link link = createdFeedEntry.getSelfLink(); + if (link != null) { + response.addHeader("Location", link.getHref().toString()); + } + + // Write the created Atom entry + response.setStatus(HttpServletResponse.SC_CREATED); + response.setContentType("application/atom+xml; charset=utf-8"); + try { + + XmlWriter writer = new XmlWriter(response.getWriter()); + createdFeedEntry.generateAtom(writer, new ExtensionProfile()); + writer.flush(); + writer.close(); + + } catch (IOException ioe) { + throw new ServletException(ioe); + } + + } 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 { + + // FIX-ME: Authenticate the user +// String user = processAuthorizationHeader(request); +// if (user == null) { +// unauthorized(response); +// return; +// } + + // Get the request path + String path = URLDecoder.decode(request.getRequestURI().substring(request.getServletPath().length()), "UTF-8"); + + String id; + if (path != null && path.startsWith("/")) { + id = path.substring(1); + } else { + id = ""; + } + + // Delete a specific entry from the collection + Message requestMessage = messageFactory.createMessage(); + requestMessage.setBody(new Object[]{id}); + Message responseMessage = deleteInvoker.invoke(requestMessage); + if (responseMessage.isFault()) { + Object body = responseMessage.getBody(); + if (body.getClass().getName().endsWith(".NotFoundException")) { + response.sendError(HttpServletResponse.SC_NOT_FOUND); + } else { + throw new ServletException((Throwable) responseMessage.getBody()); + } + } + } +} diff --git a/java/sca/modules/binding-gdata2-runtime/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/GDataBindingProviderFactory.java b/java/sca/modules/binding-gdata2-runtime/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/GDataBindingProviderFactory.java new file mode 100644 index 0000000000..bace6f68bb --- /dev/null +++ b/java/sca/modules/binding-gdata2-runtime/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/GDataBindingProviderFactory.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.gdata.provider; + +import org.apache.tuscany.sca.binding.gdata.GDataBinding; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint; +import org.apache.tuscany.sca.databinding.Mediator; +import org.apache.tuscany.sca.databinding.TransformerExtensionPoint; +import org.apache.tuscany.sca.databinding.impl.MediatorImpl; +import org.apache.tuscany.sca.host.http.ServletHost; +import org.apache.tuscany.sca.host.http.ServletHostExtensionPoint; +import org.apache.tuscany.sca.invocation.MessageFactory; +import org.apache.tuscany.sca.provider.BindingProviderFactory; +import org.apache.tuscany.sca.provider.ReferenceBindingProvider; +import org.apache.tuscany.sca.provider.ServiceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + +/** + * Implementation of a Binding provider factory for the Atom binding. + * + * @version $Rev$ $Date$ + */ +public class GDataBindingProviderFactory implements BindingProviderFactory { + + private MessageFactory messageFactory; + private Mediator mediator; + private ServletHost servletHost; + + public GDataBindingProviderFactory(ExtensionPointRegistry extensionPoints) { + ServletHostExtensionPoint servletHosts = extensionPoints.getExtensionPoint(ServletHostExtensionPoint.class); + this.servletHost = servletHosts.getServletHosts().get(0); + ModelFactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class); + this.messageFactory = modelFactories.getFactory(MessageFactory.class); + this.mediator = new MediatorImpl(extensionPoints.getExtensionPoint(DataBindingExtensionPoint.class), + extensionPoints.getExtensionPoint(TransformerExtensionPoint.class)); + } + + public ReferenceBindingProvider createReferenceBindingProvider(RuntimeComponent component, + RuntimeComponentReference reference, + GDataBinding binding) { + return new GDataReferenceBindingProvider(component, reference, binding); + } + + public ServiceBindingProvider createServiceBindingProvider(RuntimeComponent component, + RuntimeComponentService service, + GDataBinding binding) { + return new GDataServiceBindingProvider(component, service, binding, servletHost, messageFactory, mediator); + } + + public Class getModelType() { + return GDataBinding.class; + } +} diff --git a/java/sca/modules/binding-gdata2-runtime/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/GDataReferenceBindingProvider.java b/java/sca/modules/binding-gdata2-runtime/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/GDataReferenceBindingProvider.java new file mode 100644 index 0000000000..198edbaa88 --- /dev/null +++ b/java/sca/modules/binding-gdata2-runtime/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/GDataReferenceBindingProvider.java @@ -0,0 +1,125 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.gdata.provider; + + +import org.apache.tuscany.sca.binding.gdata.GDataBinding; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.provider.ReferenceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.apache.commons.httpclient.HttpClient; +import java.net.URI; +import org.apache.commons.codec.binary.Base64; +import org.apache.commons.httpclient.Credentials; +import org.apache.commons.httpclient.HttpConnectionManager; +import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager; +import org.apache.commons.httpclient.UsernamePasswordCredentials; +import org.apache.commons.httpclient.auth.AuthScope; + +/** + * Implementation of the Atom binding provider. + * + * @version $Rev$ $Date$ + */ +class GDataReferenceBindingProvider implements ReferenceBindingProvider { + + private RuntimeComponentReference reference; + private GDataBinding binding; + private HttpClient httpClient; + private String authorizationHeader; + + /** + * Constructs a new AtomReferenceBindingProvider + * @param component + * @param reference + * @param binding + * @param mediator + */ + GDataReferenceBindingProvider(RuntimeComponent component, + RuntimeComponentReference reference, + GDataBinding binding) { + this.reference = reference; + this.binding = binding; + + // Prepare authorization header + //String authorization = "admin" + ":" + "admin"; + String authorization = "gsocstudent2008" + ":" + "gsoc2008"; + authorizationHeader = "Basic " + new String(Base64.encodeBase64(authorization.getBytes())); + + // Create an HTTP client + HttpConnectionManager connectionManager = new MultiThreadedHttpConnectionManager(); + connectionManager.getParams().setDefaultMaxConnectionsPerHost(10); + connectionManager.getParams().setConnectionTimeout(60000); + httpClient = new HttpClient(connectionManager); + } + + + + public Invoker createInvoker(Operation operation) { + + String operationName = operation.getName(); + if (operationName.equals("get")) { + return new GDataBindingInvoker.GetInvoker(operation, binding, httpClient, authorizationHeader); + } else if (operationName.equals("post")) { + return new GDataBindingInvoker.PostInvoker(operation, binding, httpClient, authorizationHeader); + } else if (operationName.equals("put")) { + return new GDataBindingInvoker.PutInvoker(operation, binding, httpClient, authorizationHeader); + } else if (operationName.equals("delete")) { + return new GDataBindingInvoker.DeleteInvoker(operation, binding, httpClient, authorizationHeader); + } else if (operationName.equals("getFeed") || operationName.equals("getAll")) { + return new GDataBindingInvoker.GetAllInvoker(operation, binding, httpClient, authorizationHeader); + } else if (operationName.equals("postMedia")) { + return new GDataBindingInvoker.PostMediaInvoker(operation, binding, httpClient, authorizationHeader); + } else if (operationName.equals("putMedia")) { + return new GDataBindingInvoker.PutMediaInvoker(operation, binding, httpClient, authorizationHeader); + } else if (operationName.equals("query")) { + return new GDataBindingInvoker.QueryInvoker(operation, binding, httpClient, authorizationHeader); + } + + return new GDataBindingInvoker(operation, binding, httpClient, authorizationHeader); + } + + public InterfaceContract getBindingInterfaceContract() { + return reference.getInterfaceContract(); + } + + public void start() { + // Configure the HTTP client credentials + //Credentials credentials = new UsernamePasswordCredentials("admin", "admin"); + Credentials credentials = new UsernamePasswordCredentials("gsocstudent2008", "gsoc2008"); + httpClient.getParams().setAuthenticationPreemptive(true); + URI uri = URI.create(binding.getURI()); + httpClient.getState().setCredentials(new AuthScope(uri.getHost(), uri.getPort()), credentials); + + // Find the get operation on the reference interface + if (true) { + return; + } + } + + public void stop() { + } + + public boolean supportsOneWayInvocation() { + return false; + } +} diff --git a/java/sca/modules/binding-gdata2-runtime/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/GDataServiceBindingProvider.java b/java/sca/modules/binding-gdata2-runtime/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/GDataServiceBindingProvider.java new file mode 100644 index 0000000000..bb5739324c --- /dev/null +++ b/java/sca/modules/binding-gdata2-runtime/src/main/java/org/apache/tuscany/sca/binding/gdata/provider/GDataServiceBindingProvider.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.gdata.provider; + +import org.apache.tuscany.sca.binding.gdata.GDataBinding; +import org.apache.tuscany.sca.databinding.Mediator; +import org.apache.tuscany.sca.host.http.ServletHost; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.invocation.MessageFactory; +import org.apache.tuscany.sca.provider.ServiceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; +import org.apache.tuscany.sca.runtime.RuntimeWire; + +class GDataServiceBindingProvider implements ServiceBindingProvider { + + private RuntimeComponentService service; + private GDataBinding binding; + private ServletHost servletHost; + private MessageFactory messageFactory; + private String servletMapping; + private Mediator mediator; + + GDataServiceBindingProvider(RuntimeComponent component, + RuntimeComponentService service, + GDataBinding binding, + ServletHost servletHost, + MessageFactory messageFactory, + Mediator mediator) { + + this.service = service; + this.binding = binding; + this.servletHost = servletHost; + this.messageFactory = messageFactory; + this.mediator = mediator; + } + + public void start() { + RuntimeComponentService componentService = (RuntimeComponentService) service; + RuntimeWire wire = componentService.getRuntimeWire(binding); + + GDataBindingListenerServlet servlet = + new GDataBindingListenerServlet(wire, messageFactory, mediator, binding.getTitle()); + + servletMapping = binding.getURI(); + if (!servletMapping.endsWith("/")) { + servletMapping += "/"; + } + if (!servletMapping.endsWith("*")) { + servletMapping += "*"; + } + servletHost.addServletMapping(servletMapping, servlet); + + // Save the actual binding URI in the binding + binding.setURI(servletHost.getURLMapping(binding.getURI()).toString()); + } + + public void stop() { + servletHost.removeServletMapping(servletMapping); + } + + public InterfaceContract getBindingInterfaceContract() { + return service.getInterfaceContract(); + } + + public boolean supportsOneWayInvocation() { + return false; + } +} diff --git a/java/sca/modules/binding-gdata2-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory b/java/sca/modules/binding-gdata2-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory new file mode 100644 index 0000000000..7b655eb6b7 --- /dev/null +++ b/java/sca/modules/binding-gdata2-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Implementation class for the binding extension +org.apache.tuscany.sca.binding.gdata.provider.GDataBindingProviderFactory;model=org.apache.tuscany.sca.binding.gdata.GDataBinding diff --git a/java/sca/modules/binding-gdata2-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/calendarconsumer/CalendarConsumer.java b/java/sca/modules/binding-gdata2-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/calendarconsumer/CalendarConsumer.java new file mode 100644 index 0000000000..35a692ac67 --- /dev/null +++ b/java/sca/modules/binding-gdata2-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/calendarconsumer/CalendarConsumer.java @@ -0,0 +1,121 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.gdata.calendarconsumer; + +import com.google.gdata.data.BaseEntry; +import com.google.gdata.data.DateTime; +import com.google.gdata.data.Entry; +import com.google.gdata.data.Feed; +import com.google.gdata.data.Person; +import com.google.gdata.data.PlainTextConstruct; +import com.google.gdata.data.extensions.EventEntry; +import com.google.gdata.data.extensions.When; +import org.apache.tuscany.sca.host.embedded.SCADomain; + +public class CalendarConsumer { + + public static void main(String... args) throws Exception { + + SCADomain scaDomain; + CalendarConsumerImpl resourceCollection; + + //init + scaDomain = SCADomain.newInstance("org/apache/tuscany/sca/binding/gdata/CalendarConsumer.composite"); + resourceCollection = scaDomain.getService(CalendarConsumerImpl.class, "CalendarConsumer"); + + //test methods + System.out.println( + "\n//--------------------------" + + "\n// Get the Feed" + + "\n//--------------------------\n"); + + Feed feed = (Feed) resourceCollection.getFeed(); + + System.out.println("Feed content - " + feed.getUpdated().toString() + ":\n"); + for (Entry e : feed.getEntries()) { + System.out.println("# " + e.getTitle().getPlainText()); + } + + System.out.println( + "\n//--------------------------" + + "\n// Post a new Entry" + + "\n//--------------------------\n"); + + EventEntry entry = new EventEntry(); + + entry.setTitle(new PlainTextConstruct("GSoC extra activity")); + entry.setContent(new PlainTextConstruct("Reading the book Beautiful Code")); + + Person author = new Person("GSoC Student 2008", null, "gsocstudent2008@gmail.com"); + entry.getAuthors().add(author); + + DateTime startTime = DateTime.parseDateTime("2008-07-30T15:00:00-08:00"); + DateTime endTime = DateTime.parseDateTime("2008-07-30T17:00:00-08:00"); + When eventTimes = new When(); + eventTimes.setStartTime(startTime); + eventTimes.setEndTime(endTime); + entry.addTime(eventTimes); + + BaseEntry returnedEntry = resourceCollection.post(entry); + + System.out.println("# " + returnedEntry.getTitle().getPlainText()); + + System.out.println( + "\n//--------------------------" + + "\n// Get an Entry" + + "\n//--------------------------\n"); + + BaseEntry searchedEntry = resourceCollection.get(returnedEntry.getSelfLink().getHref()); + + System.out.println("# " + searchedEntry.getTitle().getPlainText()); + + System.out.println( + "\n//--------------------------" + + "\n// Update an Entry" + + "\n//--------------------------\n"); + + searchedEntry.setTitle(new PlainTextConstruct("GSoC extra activity(opcional)")); + BaseEntry updatedEntry = resourceCollection.put(searchedEntry.getEditLink().getHref(), searchedEntry); + + System.out.println("# " + updatedEntry.getTitle().getPlainText()); + + System.out.println( + "\n//--------------------------" + + "\n// Delete an Entry" + + "\n//--------------------------\n"); + + resourceCollection.delete(updatedEntry.getEditLink().getHref()); + + System.out.println( + "\n//--------------------------" + + "\n// Execute a query" + + "\n//--------------------------\n"); + + feed = (Feed) resourceCollection.query("Students"); + + System.out.println("Feed content - " + feed.getUpdated().toString() + ":\n"); + for (Entry e : feed.getEntries()) { + System.out.println("# " + e.getTitle().getPlainText()); + } + + //close + scaDomain.close(); + + } +} diff --git a/java/sca/modules/binding-gdata2-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/calendarconsumer/CalendarConsumerImpl.java b/java/sca/modules/binding-gdata2-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/calendarconsumer/CalendarConsumerImpl.java new file mode 100644 index 0000000000..8da6977c2c --- /dev/null +++ b/java/sca/modules/binding-gdata2-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/calendarconsumer/CalendarConsumerImpl.java @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.gdata.calendarconsumer; + +import com.google.gdata.data.BaseEntry; +import com.google.gdata.data.BaseFeed; + +import org.apache.tuscany.sca.binding.gdata.collection.Collection; +import org.osoa.sca.annotations.Reference; + +public class CalendarConsumerImpl { + + @Reference + public Collection resourceCollection; + + public BaseFeed getFeed() { + return resourceCollection.getFeed(); + } + + public BaseEntry post(BaseEntry entry) { + return resourceCollection.post(entry); + } + + public BaseEntry get(String id) throws org.apache.tuscany.sca.implementation.data.collection.NotFoundException { + return resourceCollection.get(id); + } + + public BaseEntry put(String id, BaseEntry entry) throws org.apache.tuscany.sca.implementation.data.collection.NotFoundException { + return resourceCollection.put(id, entry); + } + + public void delete(String id) throws org.apache.tuscany.sca.implementation.data.collection.NotFoundException { + resourceCollection.delete(id); + } + + public BaseFeed query(String queryString) { + return resourceCollection.query(queryString); + } +} diff --git a/java/sca/modules/binding-gdata2-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/calendarconsumer/CalendarConsumerTest.java b/java/sca/modules/binding-gdata2-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/calendarconsumer/CalendarConsumerTest.java new file mode 100644 index 0000000000..361b9b122d --- /dev/null +++ b/java/sca/modules/binding-gdata2-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/calendarconsumer/CalendarConsumerTest.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.binding.gdata.calendarconsumer; + +import com.google.gdata.data.BaseEntry; +import com.google.gdata.data.DateTime; +import com.google.gdata.data.Feed; +import com.google.gdata.data.Person; +import com.google.gdata.data.PlainTextConstruct; +import com.google.gdata.data.extensions.EventEntry; +import com.google.gdata.data.extensions.When; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.apache.tuscany.sca.host.embedded.SCADomain; +import org.apache.tuscany.sca.implementation.data.collection.NotFoundException; + +import org.junit.Test; +import org.junit.BeforeClass; +import org.junit.AfterClass; +import static org.junit.Assert.assertNotNull; + +//FIX-ME: the tests are executed in an incorrect order +public class CalendarConsumerTest { + + private static SCADomain scaDomain; + private Feed feed; + private BaseEntry returnedEntry; + private BaseEntry searchedEntry; + private BaseEntry updatedEntry; + private static CalendarConsumerImpl consumer; + + @BeforeClass + public static void init() { + scaDomain = SCADomain.newInstance("org/apache/tuscany/sca/binding/gdata/CalendarConsumer.composite"); + consumer = scaDomain.getService(CalendarConsumerImpl.class, "CalendarConsumer"); + } + + @AfterClass + public static void close() { + scaDomain.close(); + } + + @Test + public void getFeed() { + System.out.println("getfeed"); + feed = (Feed) consumer.getFeed(); + assertNotNull(feed); + } + + @Test + public void post() { + System.out.println("post"); + EventEntry entry = new EventEntry(); + + entry.setTitle(new PlainTextConstruct("GSoC extra activity")); + entry.setContent(new PlainTextConstruct("Reading the book Beautiful Code")); + + Person author = new Person("GSoC Student 2008", null, "gsocstudent2008@gmail.com"); + entry.getAuthors().add(author); + + DateTime startTime = DateTime.parseDateTime("2008-07-22T15:00:00-08:00"); + DateTime endTime = DateTime.parseDateTime("2008-07-22T17:00:00-08:00"); + When eventTimes = new When(); + eventTimes.setStartTime(startTime); + eventTimes.setEndTime(endTime); + entry.addTime(eventTimes); + + returnedEntry = consumer.post(entry); + assertNotNull(returnedEntry); + } + + @Test + public void get() { + System.out.println("get"); + try { + searchedEntry = consumer.get(returnedEntry.getSelfLink().getHref()); + assertNotNull(searchedEntry); + } catch (NotFoundException ex) { + Logger.getLogger(CalendarConsumerTest.class.getName()).log(Level.SEVERE, null, ex); + } + } + + @Test + public void put() { + System.out.println("put"); + try { + searchedEntry.setTitle(new PlainTextConstruct("GSoC extra activity(opcional)")); + updatedEntry = consumer.put(searchedEntry.getEditLink().getHref(), searchedEntry); + assertNotNull(updatedEntry); + } catch (NotFoundException ex) { + Logger.getLogger(CalendarConsumerTest.class.getName()).log(Level.SEVERE, null, ex); + } + } + + @Test + public void delete() { + System.out.println("delete"); + try { + consumer.delete(updatedEntry.getEditLink().getHref()); + } catch (NotFoundException ex) { + Logger.getLogger(CalendarConsumerTest.class.getName()).log(Level.SEVERE, null, ex); + } + } + + @Test + public void query() { + System.out.println("query"); + feed = (Feed) consumer.query("Students"); + assertNotNull(feed); + }// public void testCustomerCollection() throws Exception { +// +// System.out.println( +// "\n//--------------------------" + +// "\n// Get the Feed" + +// "\n//--------------------------\n"); +// +// Feed feed = (Feed) resourceCollection.getFeed(); +// +// System.out.println("Feed content - " + feed.getUpdated().toString() + ":\n"); +// for (Entry e : feed.getEntries()) { +// System.out.println("# " + e.getTitle().getPlainText()); +// } +// +// System.out.println( +// "\n//--------------------------" + +// "\n// Post a new Entry" + +// "\n//--------------------------\n"); +// +// EventEntry entry = new EventEntry(); +// +// entry.setTitle(new PlainTextConstruct("GSoC extra activity")); +// entry.setContent(new PlainTextConstruct("Reading the book Beautiful Code")); +// +// Person author = new Person("GSoC Student 2008", null, "gsocstudent2008@gmail.com"); +// entry.getAuthors().add(author); +// +// DateTime startTime = DateTime.parseDateTime("2008-06-19T15:00:00-08:00"); +// DateTime endTime = DateTime.parseDateTime("2008-06-19T17:00:00-08:00"); +// When eventTimes = new When(); +// eventTimes.setStartTime(startTime); +// eventTimes.setEndTime(endTime); +// entry.addTime(eventTimes); +// +// BaseEntry returnedEntry = resourceCollection.post(entry); +// +// System.out.println("# " + returnedEntry.getTitle().getPlainText()); +// +// System.out.println( +// "\n//--------------------------" + +// "\n// Get an Entry" + +// "\n//--------------------------\n"); +// +// BaseEntry searchedEntry = resourceCollection.get(returnedEntry.getSelfLink().getHref()); +// +// System.out.println("# " + searchedEntry.getTitle().getPlainText()); +// +// System.out.println( +// "\n//--------------------------" + +// "\n// Update an Entry" + +// "\n//--------------------------\n"); +// +// searchedEntry.setTitle(new PlainTextConstruct("GSoC extra activity(opcional)")); +// BaseEntry updatedEntry = resourceCollection.put(searchedEntry.getEditLink().getHref(), searchedEntry); +// +// System.out.println("# " + updatedEntry.getTitle().getPlainText()); +// +// System.out.println( +// "\n//--------------------------" + +// "\n// Delete an Entry" + +// "\n//--------------------------\n"); +// +// resourceCollection.delete(updatedEntry.getEditLink().getHref()); +// +// System.out.println( +// "\n//--------------------------" + +// "\n// Execute a query" + +// "\n//--------------------------\n"); +// +// feed = (Feed) resourceCollection.query("Students"); +// +// System.out.println("Feed content - " + feed.getUpdated().toString() + ":\n"); +// for (Entry e : feed.getEntries()) { +// System.out.println("# " + e.getTitle().getPlainText()); +// } +// +// } +} diff --git a/java/sca/modules/binding-gdata2-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/consumerprovider/Consumer.java b/java/sca/modules/binding-gdata2-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/consumerprovider/Consumer.java new file mode 100644 index 0000000000..00055f28b2 --- /dev/null +++ b/java/sca/modules/binding-gdata2-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/consumerprovider/Consumer.java @@ -0,0 +1,36 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.gdata.consumerprovider; + +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/gdata/Consumer.composite"); + + CustomerClient testService = scaDomain.getService(CustomerClient.class, "CustomerClient"); + + testService.testCustomerCollection(); + + scaDomain.close(); + } +} diff --git a/java/sca/modules/binding-gdata2-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/consumerprovider/CustomerClient.java b/java/sca/modules/binding-gdata2-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/consumerprovider/CustomerClient.java new file mode 100644 index 0000000000..1d42c9b1a4 --- /dev/null +++ b/java/sca/modules/binding-gdata2-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/consumerprovider/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.gdata.consumerprovider; + +public interface CustomerClient { + + void testCustomerCollection() throws Exception; +} diff --git a/java/sca/modules/binding-gdata2-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/consumerprovider/CustomerClientImpl.java b/java/sca/modules/binding-gdata2-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/consumerprovider/CustomerClientImpl.java new file mode 100644 index 0000000000..d6261618bf --- /dev/null +++ b/java/sca/modules/binding-gdata2-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/consumerprovider/CustomerClientImpl.java @@ -0,0 +1,117 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.gdata.consumerprovider; + +import com.google.gdata.data.BaseEntry; +import com.google.gdata.data.BaseFeed; +import com.google.gdata.data.DateTime; +import com.google.gdata.data.Entry; +import com.google.gdata.data.Feed; +import com.google.gdata.data.Person; +import com.google.gdata.data.PlainTextConstruct; +import com.google.gdata.data.Source; +import com.google.gdata.data.extensions.EventEntry; +import com.google.gdata.data.extensions.When; +import org.apache.tuscany.sca.binding.gdata.collection.Collection; +import org.osoa.sca.annotations.Reference; +import org.osoa.sca.annotations.Scope; + +@Scope("COMPOSITE") +public class CustomerClientImpl implements CustomerClient { + + @Reference + public Collection resourceCollection; + + public void testCustomerCollection() throws Exception { + + System.out.println( + "\n//--------------------------" + + "\n// Get the Feed" + + "\n//--------------------------\n"); + + BaseFeed feed = resourceCollection.getFeed(); + + System.out.println("Feed content - " + feed.getUpdated().toString() + ":\n"); + for (BaseEntry e : feed.getEntries()) { + System.out.println("# " + e.getTitle().getPlainText()); + } + + System.out.println( + "\n//--------------------------" + + "\n// Post a new Entry" + + "\n//--------------------------\n"); + + EventEntry entry = new EventEntry(); + + entry.setTitle(new PlainTextConstruct("Activity")); + entry.setContent(new PlainTextConstruct("Reading the book Beautiful Code")); + + Person author = new Person("GSoC Student 2008", null, "gsocstudent2008@gmail.com"); + entry.getAuthors().add(author); + + DateTime startTime = DateTime.parseDateTime("2008-06-19T15:00:00-08:00"); + DateTime endTime = DateTime.parseDateTime("2008-06-19T17:00:00-08:00"); + When eventTimes = new When(); + eventTimes.setStartTime(startTime); + eventTimes.setEndTime(endTime); + entry.addTime(eventTimes); + + BaseEntry returnedEntry = resourceCollection.post(entry); + + System.out.println("# " + returnedEntry.getTitle().getPlainText()); + + System.out.println( + "\n//--------------------------" + + "\n// Get an Entry" + + "\n//--------------------------\n"); + + BaseEntry searchedEntry = resourceCollection.get(returnedEntry.getId()); + System.out.println("# " + searchedEntry.getTitle().getPlainText()); + + + System.out.println( + "\n//--------------------------" + + "\n// Update an Entry" + + "\n//--------------------------\n"); + + searchedEntry.setTitle(new PlainTextConstruct("Activity (opcional)")); + BaseEntry updatedEntry = resourceCollection.put(searchedEntry.getId(), searchedEntry); + + System.out.println("# " + updatedEntry.getTitle().getPlainText()); + + System.out.println( + "\n//--------------------------" + + "\n// Delete an Entry" + + "\n//--------------------------\n"); + + resourceCollection.delete(updatedEntry.getId()); + + System.out.println( + "\n//--------------------------" + + "\n// Execute a query" + + "\n//--------------------------\n"); + + feed = (Feed)(Source) resourceCollection.query("GSoC"); + + System.out.println("Feed content - " + feed.getUpdated().toString() + ":\n"); + for (BaseEntry e : feed.getEntries()) { + System.out.println("# " + e.getTitle().getPlainText()); + } + } +} diff --git a/java/sca/modules/binding-gdata2-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/consumerprovider/CustomerCollectionImpl.java b/java/sca/modules/binding-gdata2-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/consumerprovider/CustomerCollectionImpl.java new file mode 100644 index 0000000000..8233d01dd9 --- /dev/null +++ b/java/sca/modules/binding-gdata2-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/consumerprovider/CustomerCollectionImpl.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.gdata.consumerprovider; + +import com.google.gdata.data.BaseEntry; +import com.google.gdata.data.BaseFeed; +import com.google.gdata.data.DateTime; +import com.google.gdata.data.Entry; +import com.google.gdata.data.Feed; +import com.google.gdata.data.PlainTextConstruct; +import java.util.ArrayList; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; +import java.util.TimeZone; +import java.util.UUID; +import org.apache.tuscany.sca.binding.gdata.collection.Collection; +import org.apache.tuscany.sca.implementation.data.collection.NotFoundException; +import org.osoa.sca.annotations.Scope; + +@Scope("COMPOSITE") +public class CustomerCollectionImpl implements Collection { + + private Map entries; + + public CustomerCollectionImpl() { + entries = new HashMap(); + + BaseEntry entry = new Entry(); + entry.setId("urn:uuid:customer-0"); + entry.setTitle(new PlainTextConstruct("An exampling entry - GSoC")); + + entries.put(entry.getId(), entry); + } + + public BaseFeed getFeed() { + System.out.println(">>> CustomerCollectionImpl.getFeed"); + + BaseFeed feed = new Feed(); + feed.setTitle(new PlainTextConstruct("Customers Feed")); + feed.setSubtitle(new PlainTextConstruct("This is a sample feed")); + feed.setUpdated(new DateTime()); + + //FIX-ME + //feed.addHtmlLink("", "", ""); //feed.addLink(""); + //feed.addHtmlLink("", "self", ""); //feed.addLink("", "self"); + feed.addHtmlLink("http://localhost:8086/customer", "", ""); + + feed.setEntries(new ArrayList(entries.values())); + + return feed; + } + + public BaseFeed query(String queryString) { + System.out.println(">>> CustomerCollectionImpl.query collection " + queryString); + return getFeed(); + } + + public BaseEntry post(BaseEntry entry) { + System.out.println(">>> CustomerCollectionImpl.post entry=" + entry.getTitle().getPlainText()); + + String id = "urn:uuid:customer-" + UUID.randomUUID().toString(); + entry.setId(id); + + //FIX-ME + entry.addHtmlLink("" + id, "edit", ""); + entry.addHtmlLink("" + id, "alternate", ""); + + DateTime dateTime = new DateTime(new Date(), TimeZone.getTimeZone("America/Los_Angeles")); + entry.setUpdated(dateTime); + + entries.put(id, entry); + + System.out.println(">>> CustomerCollectionImpl.post return id=" + id); + + return entry; + } + + public BaseEntry get(String id) throws NotFoundException { + System.out.println(">>> CustomerCollectionImpl.get id=" + id); + + return entries.get(id); + } + + public BaseEntry put(String id, BaseEntry entry) throws NotFoundException { + System.out.println(">>> CustomerCollectionImpl.put id=" + id + " entry=" + entry.getTitle()); + + DateTime dateTime = new DateTime(new Date(), TimeZone.getTimeZone("America/Los_Angeles")); + entry.setUpdated(dateTime); + + entries.put(id, entry); + + return entries.get(id); + } + + public void delete(String id) throws NotFoundException { + System.out.println(">>> CustomerCollectionImpl.delete id=" + id); + entries.remove(id); + } +} diff --git a/java/sca/modules/binding-gdata2-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/consumerprovider/Provider.java b/java/sca/modules/binding-gdata2-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/consumerprovider/Provider.java new file mode 100644 index 0000000000..9beca538df --- /dev/null +++ b/java/sca/modules/binding-gdata2-runtime/src/test/java/org/apache/tuscany/sca/binding/gdata/consumerprovider/Provider.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.gdata.consumerprovider; + +import org.apache.tuscany.sca.host.embedded.SCADomain; + +public class Provider { + + public static void main(String[] args) throws Exception { + + SCADomain scaDomain = SCADomain.newInstance("org/apache/tuscany/sca/binding/gdata/Provider.composite"); + + System.out.println("Ready for consultings..."); + System.in.read(); + + scaDomain.close(); + } +} diff --git a/java/sca/modules/binding-gdata2-runtime/src/test/resources/org/apache/tuscany/sca/binding/gdata/CalendarConsumer.composite b/java/sca/modules/binding-gdata2-runtime/src/test/resources/org/apache/tuscany/sca/binding/gdata/CalendarConsumer.composite new file mode 100644 index 0000000000..a208852f16 --- /dev/null +++ b/java/sca/modules/binding-gdata2-runtime/src/test/resources/org/apache/tuscany/sca/binding/gdata/CalendarConsumer.composite @@ -0,0 +1,32 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/java/sca/modules/binding-gdata2-runtime/src/test/resources/org/apache/tuscany/sca/binding/gdata/Consumer.composite b/java/sca/modules/binding-gdata2-runtime/src/test/resources/org/apache/tuscany/sca/binding/gdata/Consumer.composite new file mode 100644 index 0000000000..e381f458b6 --- /dev/null +++ b/java/sca/modules/binding-gdata2-runtime/src/test/resources/org/apache/tuscany/sca/binding/gdata/Consumer.composite @@ -0,0 +1,32 @@ + + + + + + + + + + + + diff --git a/java/sca/modules/binding-gdata2-runtime/src/test/resources/org/apache/tuscany/sca/binding/gdata/Provider.composite b/java/sca/modules/binding-gdata2-runtime/src/test/resources/org/apache/tuscany/sca/binding/gdata/Provider.composite new file mode 100644 index 0000000000..e7ddb38ff0 --- /dev/null +++ b/java/sca/modules/binding-gdata2-runtime/src/test/resources/org/apache/tuscany/sca/binding/gdata/Provider.composite @@ -0,0 +1,33 @@ + + + + + + + + + + + + + diff --git a/java/sca/modules/binding-gdata2/LICENSE b/java/sca/modules/binding-gdata2/LICENSE new file mode 100644 index 0000000000..6e529a25c4 --- /dev/null +++ b/java/sca/modules/binding-gdata2/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/java/sca/modules/binding-gdata2/NOTICE b/java/sca/modules/binding-gdata2/NOTICE new file mode 100644 index 0000000000..1325efd8bf --- /dev/null +++ b/java/sca/modules/binding-gdata2/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2008 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/java/sca/modules/binding-gdata2/pom.xml b/java/sca/modules/binding-gdata2/pom.xml new file mode 100644 index 0000000000..b0747685d3 --- /dev/null +++ b/java/sca/modules/binding-gdata2/pom.xml @@ -0,0 +1,73 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 2.0-SNAPSHOT + ../pom.xml + + + tuscany-binding-gdata2 + Apache Tuscany SCA Gdata Binding Extension GSOC + + + + org.apache.tuscany.sca + tuscany-assembly + 2.0-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-assembly-xml + 2.0-SNAPSHOT + + + + junit + junit + 4.5 + test + + + + + + + + + org.apache.felix + maven-bundle-plugin + + + + ${tuscany.version} + org.apache.tuscany.sca.binding.atom + ${pom.name} + org.apache.tuscany.sca.binding.atom* + + + + + + + diff --git a/java/sca/modules/binding-gdata2/src/main/java/org/apache/tuscany/sca/binding/gdata/GDataBinding.java b/java/sca/modules/binding-gdata2/src/main/java/org/apache/tuscany/sca/binding/gdata/GDataBinding.java new file mode 100644 index 0000000000..c1868f05dc --- /dev/null +++ b/java/sca/modules/binding-gdata2/src/main/java/org/apache/tuscany/sca/binding/gdata/GDataBinding.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.gdata; + +import org.apache.tuscany.sca.assembly.Binding; + +/** + * GData binding model. + * + * @version $Rev$ $Date$ + */ +public interface GDataBinding extends Binding { + + /** + * Returns the title of the Atom collection. + * @return + */ + String getTitle(); + + /** + * Sets the title of the Atom collection. + * @param title + */ + void setTitle(String title); + + /* + * Returns the username of a Google account + * @return + */ + String getUsername(); + + /* + * Sets the username of a Google account + * @param username + */ + void setUsername(String username); + + /* + * Returns the password of a Google account + * @return + */ + String getPassword(); + + /* + * Sets the password of a Google account + * @param password + */ + void setPassword(String password); + + /* + * Retruns the name of the Google service to which we are connecting. Sample names of services might include "cl" (Calendar), "mail" (GMail), or "blogger" (Blogger) + * @return + */ + String getServiceType(); + + /* + * Sets the name of the Google service to which we are connecting. Sample names of services might include "cl" (Calendar), "mail" (GMail), or "blogger" (Blogger) + * @param serviceType + */ + void setServiceType(String serviceType); +} diff --git a/java/sca/modules/binding-gdata2/src/main/java/org/apache/tuscany/sca/binding/gdata/GDataBindingFactory.java b/java/sca/modules/binding-gdata2/src/main/java/org/apache/tuscany/sca/binding/gdata/GDataBindingFactory.java new file mode 100644 index 0000000000..ec2f179fdb --- /dev/null +++ b/java/sca/modules/binding-gdata2/src/main/java/org/apache/tuscany/sca/binding/gdata/GDataBindingFactory.java @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.gdata; + +/** + * Factory for the GData binding + * + * @version $Rev$ $Date$ + */ +public interface GDataBindingFactory { + + /** + * Creates a new Atom binding. + * @return the new Atom binding + */ + GDataBinding createAtomBinding(); + +} diff --git a/java/sca/modules/binding-gdata2/src/main/java/org/apache/tuscany/sca/binding/gdata/GDataImplementationProcessor.java b/java/sca/modules/binding-gdata2/src/main/java/org/apache/tuscany/sca/binding/gdata/GDataImplementationProcessor.java new file mode 100644 index 0000000000..5797629bed --- /dev/null +++ b/java/sca/modules/binding-gdata2/src/main/java/org/apache/tuscany/sca/binding/gdata/GDataImplementationProcessor.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.gdata; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.assembly.xml.Constants; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.service.ContributionResolveException; +import org.apache.tuscany.sca.monitor.Monitor; + +public class GDataImplementationProcessor implements StAXArtifactProcessor { + + private GDataBindingFactory gdataFactory; + protected static final QName BINDING_GDATA = new QName(Constants.SCA10_TUSCANY_NS, "binding.gdata"); + + public GDataImplementationProcessor(ModelFactoryExtensionPoint modelFactories, Monitor monitor) { + + this.gdataFactory = (GDataBindingFactory) modelFactories.getFactory(GDataBindingFactory.class); + } + + public GDataBinding read(XMLStreamReader reader) { + + assert BINDING_GDATA.equals(reader.getName()); + + GDataBinding gdataBinding = gdataFactory.createAtomBinding(); + + /* + * + */ + + String uri = reader.getAttributeValue(null, "uri"); + String serviceType = reader.getAttributeValue(null, "serviceType"); + String login = reader.getAttributeValue(null, "username"); + String password = reader.getAttributeValue(null, "password"); + + gdataBinding.setURI(uri); + gdataBinding.setServiceType(serviceType); + gdataBinding.setUsername(login); + gdataBinding.setPassword(password); + + return gdataBinding; + } + + public void write(GDataBinding gdataBinding, XMLStreamWriter writer) throws XMLStreamException { + if (gdataBinding != null) { + writer.writeStartElement(BINDING_GDATA.getNamespaceURI(), BINDING_GDATA.getLocalPart()); + + if (gdataBinding.getURI() != null) { + writer.writeAttribute("uri", gdataBinding.getURI()); + } + + if (gdataBinding.getServiceType() != null) { + writer.writeAttribute("serviceType", gdataBinding.getServiceType()); + } + if (gdataBinding.getUsername() != null) { + writer.writeAttribute("username", gdataBinding.getUsername()); + } + if (gdataBinding.getPassword() != null) { + writer.writeAttribute("password", gdataBinding.getPassword()); + } + + writer.writeEndElement(); + } + } + + public QName getArtifactType() { + return BINDING_GDATA; + } + + public void resolve(GDataBinding arg0, ModelResolver arg1) throws ContributionResolveException { + } + + public Class getModelType() { + return GDataBinding.class; + } +} diff --git a/java/sca/modules/binding-gdata2/src/main/java/org/apache/tuscany/sca/binding/gdata/impl/GDataBindingFactoryImpl.java b/java/sca/modules/binding-gdata2/src/main/java/org/apache/tuscany/sca/binding/gdata/impl/GDataBindingFactoryImpl.java new file mode 100644 index 0000000000..e0c3bfbe78 --- /dev/null +++ b/java/sca/modules/binding-gdata2/src/main/java/org/apache/tuscany/sca/binding/gdata/impl/GDataBindingFactoryImpl.java @@ -0,0 +1,36 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.gdata.impl; + +import org.apache.tuscany.sca.binding.gdata.GDataBinding; +import org.apache.tuscany.sca.binding.gdata.GDataBindingFactory; + +/** + * Factory for the GData binding model. + * + * @version $Rev$ $Date$ + */ +public class GDataBindingFactoryImpl implements GDataBindingFactory { + + public GDataBinding createAtomBinding() { + return new GDataBindingImpl(); + } + +} diff --git a/java/sca/modules/binding-gdata2/src/main/java/org/apache/tuscany/sca/binding/gdata/impl/GDataBindingImpl.java b/java/sca/modules/binding-gdata2/src/main/java/org/apache/tuscany/sca/binding/gdata/impl/GDataBindingImpl.java new file mode 100644 index 0000000000..baba882c4c --- /dev/null +++ b/java/sca/modules/binding-gdata2/src/main/java/org/apache/tuscany/sca/binding/gdata/impl/GDataBindingImpl.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.gdata.impl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.sca.binding.gdata.GDataBinding; +import org.apache.tuscany.sca.policy.Intent; +import org.apache.tuscany.sca.policy.IntentAttachPointType; +import org.apache.tuscany.sca.policy.PolicySet; +import org.apache.tuscany.sca.policy.PolicySetAttachPoint; + +/** + * Implementation of the GData binding model. + * + * @version $Rev$ $Date$ + */ +class GDataBindingImpl implements GDataBinding, PolicySetAttachPoint { + + private String password; + private String username; + private String name; + private String serviceType; + private String uri; + private String title; + private List requiredIntents = new ArrayList(); + private List policySets = new ArrayList(); + private IntentAttachPointType intentAttachPointType; + private List applicablePolicySets = new ArrayList(); + + public List getApplicablePolicySets() { + return applicablePolicySets; + } + + public String getName() { + return name; + } + + public String getURI() { + return uri; + } + + public void setName(String name) { + this.name = name; + } + + public void setURI(String uri) { + this.uri = uri; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public boolean isUnresolved() { + // The binding is always resolved + return false; + } + + public void setUnresolved(boolean unresolved) { + // The binding is always resolved + } + + public List getPolicySets() { + return policySets; + } + + public List getRequiredIntents() { + return requiredIntents; + } + + public IntentAttachPointType getType() { + return intentAttachPointType; + } + + public void setType(IntentAttachPointType intentAttachPointType) { + this.intentAttachPointType = intentAttachPointType; + } + + @Override + public Object clone() throws CloneNotSupportedException { + return super.clone(); + } + + public void setPolicySets(List policySets) { + this.policySets = policySets; + } + + public void setRequiredIntents(List intents) { + this.requiredIntents = intents; + } + + public String getUsername() { + return this.username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getPassword() { + return this.password; + } + + public void setPassword(String password) { + this.password = password; + } + + public String getServiceType() { + return this.serviceType; + } + + public void setServiceType(String serviceType) { + this.serviceType = serviceType; + } +} diff --git a/java/sca/modules/binding-gdata2/src/main/resources/META-INF/services/org.apache.tuscany.sca.binding.gdata.GDataBindingFactory b/java/sca/modules/binding-gdata2/src/main/resources/META-INF/services/org.apache.tuscany.sca.binding.gdata.GDataBindingFactory new file mode 100644 index 0000000000..48be99b507 --- /dev/null +++ b/java/sca/modules/binding-gdata2/src/main/resources/META-INF/services/org.apache.tuscany.sca.binding.gdata.GDataBindingFactory @@ -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.gdata.impl.GDataBindingFactoryImpl \ No newline at end of file diff --git a/java/sca/modules/binding-gdata2/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor b/java/sca/modules/binding-gdata2/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor new file mode 100644 index 0000000000..92aad3d44d --- /dev/null +++ b/java/sca/modules/binding-gdata2/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor @@ -0,0 +1,21 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# Implementation class for the artifact processor extension + +#org.apache.tuscany.sca.assembly.xml.DefaultBeanModelProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.0#binding.gdata,model=org.apache.tuscany.sca.binding.gdata.GDataBinding,factory=org.apache.tuscany.sca.binding.gdata.GDataBindingFactory +org.apache.tuscany.sca.binding.gdata.GDataImplementationProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.0#binding.gdata,model=org.apache.tuscany.sca.binding.gdata.GDataBinding,factory=org.apache.tuscany.sca.binding.gdata.GDataBindingFactory \ No newline at end of file diff --git a/java/sca/modules/core-spring/LICENSE b/java/sca/modules/core-spring/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/java/sca/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/java/sca/modules/core-spring/NOTICE b/java/sca/modules/core-spring/NOTICE new file mode 100644 index 0000000000..fdfa0e9faa --- /dev/null +++ b/java/sca/modules/core-spring/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2008 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/java/sca/modules/core-spring/pom.xml b/java/sca/modules/core-spring/pom.xml new file mode 100644 index 0000000000..15156bd980 --- /dev/null +++ b/java/sca/modules/core-spring/pom.xml @@ -0,0 +1,126 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 2.0-SNAPSHOT + ../pom.xml + + tuscany-core-spring + Apache Tuscany SCA Spring-based Core Runtime + + + + + org.apache.tuscany.sca + tuscany-assembly + 2.0-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-interface-java + 2.0-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-implementation-java + 2.0-SNAPSHOT + + + + org.springframework + spring-core + 2.5.5 + + + + org.springframework + spring-beans + 2.5.5 + + + + org.springframework + spring-context + 2.5.5 + + + + org.apache.tuscany.sca + tuscany-sca-api + 2.0-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-assembly-xml + 2.0-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-interface-java-xml + 2.0-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-implementation-java-xml + 2.0-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-contribution-impl + 2.0-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-binding-sca + 2.0-SNAPSHOT + + + + + + + + + org.apache.felix + maven-bundle-plugin + + + + ${tuscany.version} + org.apache.tuscany.sca.core.spring + ${pom.name} + org.apache.tuscany.sca.core.spring* + + + + + + + diff --git a/java/sca/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/assembly/impl/BeanAssemblyFactory.java b/java/sca/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/assembly/impl/BeanAssemblyFactory.java new file mode 100644 index 0000000000..94bd5c8cf2 --- /dev/null +++ b/java/sca/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.ConfiguredOperation; +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.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 ConfiguredOperation createConfiguredOperation() { + return defaultFactory.createConfiguredOperation(); + } + +} diff --git a/java/sca/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/assembly/impl/BeanComponentImpl.java b/java/sca/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/assembly/impl/BeanComponentImpl.java new file mode 100644 index 0000000000..f2c517b092 --- /dev/null +++ b/java/sca/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/assembly/impl/BeanComponentImpl.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.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.AbstractBeanDefinition; +import org.springframework.beans.factory.support.GenericBeanDefinition; + +/** + * An implementation of the SCA assembly Component interface backed by a Spring + * Bean definition. + * + * @version $Rev$ $Date$ + */ +public class BeanComponentImpl extends GenericBeanDefinition implements Component, Cloneable { + private List applicablePolicySets = new ArrayList(); + + 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 AbstractBeanDefinition cloneBeanDefinition() { + BeanComponentImpl clone = (BeanComponentImpl)super.cloneBeanDefinition(); + clone.getProperties().clear(); + try { + 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; + } catch (CloneNotSupportedException e) { + //throw new CloneNotSupportedException(e.getMessage()); + } + 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; + } + + public void setPolicySets(List policySets) { + this.policySets = policySets; + } + + public void setRequiredIntents(List intents) { + this.requiredIntents = intents; + } + + public List getApplicablePolicySets() { + return applicablePolicySets; + } + +} diff --git a/java/sca/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/assembly/impl/BeanReferenceImpl.java b/java/sca/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/assembly/impl/BeanReferenceImpl.java new file mode 100644 index 0000000000..7b747372b4 --- /dev/null +++ b/java/sca/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/assembly/impl/BeanReferenceImpl.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.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 wrapping 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(); + if (name.startsWith("/")) { + name = name.substring(1); + } + 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/java/sca/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/context/ModelResolverImpl.java b/java/sca/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/context/ModelResolverImpl.java new file mode 100644 index 0000000000..b275bfa9a7 --- /dev/null +++ b/java/sca/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 wrapping 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/java/sca/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/context/SCADomainContext.java b/java/sca/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/context/SCADomainContext.java new file mode 100644 index 0000000000..8fa5f4cd53 --- /dev/null +++ b/java/sca/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/context/SCADomainContext.java @@ -0,0 +1,192 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.spring.context; + +import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; + +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.transform.TransformerFactory; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory; +import org.apache.tuscany.sca.assembly.SCABindingFactory; +import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException; +import org.apache.tuscany.sca.assembly.builder.impl.CompositeBuilderImpl; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.service.ContributionException; +import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; +import org.apache.tuscany.sca.core.UtilityExtensionPoint; +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.interfacedef.InterfaceContractMapper; +import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.monitor.Problem; +import org.apache.tuscany.sca.policy.DefaultIntentAttachPointTypeFactory; +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 + DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + ModelFactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class); + AssemblyFactory assemblyFactory = new BeanAssemblyFactory(new DefaultAssemblyFactory(), beanFactory); + modelFactories.addFactory(assemblyFactory); + UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class); + InterfaceContractMapper mapper = utilities.getUtility(InterfaceContractMapper.class); + JavaInterfaceFactory javaFactory = modelFactories.getFactory(JavaInterfaceFactory.class); + PolicyFactory policyFactory = modelFactories.getFactory(PolicyFactory.class); + SCABindingFactory scaBindingFactory = modelFactories.getFactory(SCABindingFactory.class); + 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 + StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); + StAXArtifactProcessor compositeProcessor = staxProcessors.getProcessor(Composite.class); + + // Create a resolver + //FIXME The ClassLoader should be passed in + ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); + ModelResolverImpl resolver = new ModelResolverImpl(classLoader); + + try { + XMLInputFactory inputFactory = XMLInputFactory.newInstance(); + + // Read the composite files + List composites = new ArrayList(); + for (String compositeFile: compositeFiles) { + InputStream is = classLoader.getResourceAsStream(compositeFile); + XMLStreamReader reader = inputFactory.createXMLStreamReader(is); + Composite composite = compositeProcessor.read(reader); + resolver.addModel(composite); + composites.add(composite); + } + + for (Composite composite: composites) { + + // Resolve the composite + compositeProcessor.resolve(composite, resolver); + } + + // Wire the top level component's composite + DocumentBuilderFactory documentBuilderFactory = modelFactories.getFactory(DocumentBuilderFactory.class); + TransformerFactory transformerFactory = modelFactories.getFactory(TransformerFactory.class); + buildComposite(composites.get(0), assemblyFactory, scaBindingFactory, + documentBuilderFactory, transformerFactory, mapper); + + } catch (ContributionException e) { + throw new RuntimeException(e); + } catch (CompositeBuilderException e) { + throw new RuntimeException(e); + } catch (XMLStreamException e) { + throw new RuntimeException(e); + } + } + + private void buildComposite(Composite composite, AssemblyFactory assemblyFactory, + SCABindingFactory scaBindingFactory, + DocumentBuilderFactory documentBuilderFactory, + TransformerFactory transformerFactory, + InterfaceContractMapper interfaceContractMapper) throws CompositeBuilderException { + + Monitor monitor = new Monitor() { + + public void problem(Problem problem) { + System.out.println("Composite assembly problem: " + problem.toString()); + } + public List getProblems() { + return null; + } + }; + + // Configure and wire the composite + CompositeBuilderImpl compositeUtil = new CompositeBuilderImpl(assemblyFactory, scaBindingFactory, new DefaultIntentAttachPointTypeFactory(), + documentBuilderFactory, transformerFactory, interfaceContractMapper, monitor); + compositeUtil.build(composite); + + } + + public B getService(Class businessInterface, String serviceName) { + Object bean = beanFactory.getBean(serviceName); + return businessInterface.cast(bean); + } + +} diff --git a/java/sca/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/implementation/java/impl/BeanBaseJavaImplementationImpl.java b/java/sca/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/implementation/java/impl/BeanBaseJavaImplementationImpl.java new file mode 100644 index 0000000000..49abfb4162 --- /dev/null +++ b/java/sca/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/implementation/java/impl/BeanBaseJavaImplementationImpl.java @@ -0,0 +1,211 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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.ConfiguredOperation; +import org.apache.tuscany.sca.assembly.ConstrainingType; +import org.apache.tuscany.sca.assembly.Property; +import org.apache.tuscany.sca.assembly.Reference; +import org.apache.tuscany.sca.assembly.Service; +import org.apache.tuscany.sca.implementation.java.BaseJavaImplementation; +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.AbstractBeanDefinition; +import org.springframework.beans.factory.support.GenericBeanDefinition; + +/** + * An implementation of the SCA assembly JavaImplementation interface backed by a Spring + * Bean definition. + * + * @version $Rev$ $Date$ + */ +public class BeanBaseJavaImplementationImpl extends GenericBeanDefinition 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; + + private List applicablePolicySets = new ArrayList(); + private List configuredOperations = new ArrayList(); + private List policySets = new ArrayList(); + private List requiredIntents = new ArrayList(); + private IntentAttachPointType type = null; + + 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 AbstractBeanDefinition cloneBeanDefinition() { + BeanBaseJavaImplementationImpl clone = (BeanBaseJavaImplementationImpl)super.cloneBeanDefinition(); + clone.getServices().clear(); + try { + 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; + } catch (CloneNotSupportedException e) { + //throw new CloneNotSupportedException(e.getMessage()); + } + 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; + } + + public List getApplicablePolicySets() { + return applicablePolicySets; + } + + public List getConfiguredOperations() { + return configuredOperations; + } + + public List getPolicySets() { + return policySets; + } + + public List getRequiredIntents() { + return requiredIntents; + } + + public IntentAttachPointType getType() { + return type; + } + + public void setType(IntentAttachPointType type) { + this.type = type; + } +} diff --git a/java/sca/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/implementation/java/impl/BeanJavaImplementationFactory.java b/java/sca/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/java/sca/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/java/sca/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/implementation/java/impl/BeanJavaImplementationImpl.java b/java/sca/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/implementation/java/impl/BeanJavaImplementationImpl.java new file mode 100644 index 0000000000..7fc82d8711 --- /dev/null +++ b/java/sca/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/implementation/java/impl/BeanJavaImplementationImpl.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.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.Collection; +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.apache.tuscany.sca.policy.util.PolicyHandlerTuple; +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; + private List policyHandlerClassNames = null; + + 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; + } + + public List getPolicyHandlerClassNames() { + return policyHandlerClassNames; + } + + public void setPolicyHandlerClassNames(List policyHandlerClassNames) { + this.policyHandlerClassNames = policyHandlerClassNames; + } +} diff --git a/java/sca/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/implementation/java/impl/BeanJavaInterfaceContractImpl.java b/java/sca/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/java/sca/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/java/sca/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/implementation/java/impl/BeanJavaInterfaceFactory.java b/java/sca/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/java/sca/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/java/sca/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/implementation/java/impl/BeanJavaInterfaceImpl.java b/java/sca/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/implementation/java/impl/BeanJavaInterfaceImpl.java new file mode 100644 index 0000000000..6c3afdb129 --- /dev/null +++ b/java/sca/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/implementation/java/impl/BeanJavaInterfaceImpl.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.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.interfacedef.java.impl.JavaInterfaceImpl; +import org.apache.tuscany.sca.policy.Intent; + +/** + * An alternate implementation of the SCA Java assembly model JavaInterface + * interface. + * + * @version $Rev$ $Date$ + */ +public class BeanJavaInterfaceImpl extends JavaInterfaceImpl 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() { + } + + @Override + public String getName() { + if (isUnresolved()) { + return className; + } + else { + return javaClass.getName(); + } + } + + @Override + public void setName(String className) { + if (!isUnresolved()) + throw new IllegalStateException(); + this.className = className; + } + + @Override + public Class getJavaClass() { + return javaClass; + } + + @Override + public void setJavaClass(Class javaClass) { + this.javaClass = javaClass; + } + + @Override + public Class getCallbackClass() { + return callbackClass; + } + + @Override + public void setCallbackClass(Class callbackClass) { + this.callbackClass = callbackClass; + } + + @Override + public boolean isConversational() { + return conversational; + } + + @Override + public boolean isRemotable() { + return remotable; + } + + @Override + public void setConversational(boolean conversational) { + this.conversational = conversational; + } + + @Override + public void setRemotable(boolean local) { + this.remotable = local; + } + + @Override + public List getRequiredIntents() { + return requiredIntents; + } + + public List getExtensions() { + return extensions; + } + + @Override + public List getOperations() { + return operations; + } + + @Override + public boolean isUnresolved() { + return unresolved; + } + + @Override + public void setUnresolved(boolean undefined) { + this.unresolved = undefined; + } + + @Override + public void resetDataBinding(String dataBinding) { + } + + @Deprecated + @Override + public void setDefaultDataBinding(String dataBinding) { + } + + @Override + public boolean isDynamic() { + return false; + } + + @Override + public Object clone() throws CloneNotSupportedException { + return super.clone(); + } +} diff --git a/java/sca/modules/core-spring/src/test/java/calculator/AddService.java b/java/sca/modules/core-spring/src/test/java/calculator/AddService.java new file mode 100644 index 0000000000..f3a24ed6b2 --- /dev/null +++ b/java/sca/modules/core-spring/src/test/java/calculator/AddService.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 calculator; + +/** + * The Add Service interface. + * + * @version $Rev$ $Date$ + */ +public interface AddService { + + double add(double n1, double n2); + +} diff --git a/java/sca/modules/core-spring/src/test/java/calculator/AddServiceImpl.java b/java/sca/modules/core-spring/src/test/java/calculator/AddServiceImpl.java new file mode 100644 index 0000000000..61654ea811 --- /dev/null +++ b/java/sca/modules/core-spring/src/test/java/calculator/AddServiceImpl.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 calculator; + +import org.osoa.sca.annotations.EagerInit; +import org.osoa.sca.annotations.Scope; + +/** + * An implementation of the Add service + * + * @version $Rev$ $Date$ + */ +@Scope("COMPOSITE") +@EagerInit +public class AddServiceImpl implements AddService { + + public double add(double n1, double n2) { + return n1 + n2; + } + +} diff --git a/java/sca/modules/core-spring/src/test/java/calculator/CalculatorClient.java b/java/sca/modules/core-spring/src/test/java/calculator/CalculatorClient.java new file mode 100644 index 0000000000..73aa028084 --- /dev/null +++ b/java/sca/modules/core-spring/src/test/java/calculator/CalculatorClient.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 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. + * + * @version $Rev$ $Date$ + */ +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/java/sca/modules/core-spring/src/test/java/calculator/CalculatorService.java b/java/sca/modules/core-spring/src/test/java/calculator/CalculatorService.java new file mode 100644 index 0000000000..e0cf23dc17 --- /dev/null +++ b/java/sca/modules/core-spring/src/test/java/calculator/CalculatorService.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 calculator; + +/** + * The Calculator service interface. + * + * @version $Rev$ $Date$ + */ +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/java/sca/modules/core-spring/src/test/java/calculator/CalculatorServiceImpl.java b/java/sca/modules/core-spring/src/test/java/calculator/CalculatorServiceImpl.java new file mode 100644 index 0000000000..c1fceb575d --- /dev/null +++ b/java/sca/modules/core-spring/src/test/java/calculator/CalculatorServiceImpl.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 calculator; + +import org.osoa.sca.annotations.Reference; +import org.osoa.sca.annotations.Scope; + +/** + * An implementation of the Calculator service. + * + * @version $Rev$ $Date$ + */ +@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/java/sca/modules/core-spring/src/test/java/calculator/DivideService.java b/java/sca/modules/core-spring/src/test/java/calculator/DivideService.java new file mode 100644 index 0000000000..7c69b10b25 --- /dev/null +++ b/java/sca/modules/core-spring/src/test/java/calculator/DivideService.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 calculator; + +/** + * The Divide Service interface. + * + * @version $Rev$ $Date$ + */ +public interface DivideService { + + double divide(double n1, double n2); + +} diff --git a/java/sca/modules/core-spring/src/test/java/calculator/DivideServiceImpl.java b/java/sca/modules/core-spring/src/test/java/calculator/DivideServiceImpl.java new file mode 100644 index 0000000000..e1f35f99b5 --- /dev/null +++ b/java/sca/modules/core-spring/src/test/java/calculator/DivideServiceImpl.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.Scope; + +/** + * An implementation of the Divide service. + * + * @version $Rev$ $Date$ + */ +@Scope("COMPOSITE") +public class DivideServiceImpl implements DivideService { + + public double divide(double n1, double n2) { + return n1 / n2; + } + +} diff --git a/java/sca/modules/core-spring/src/test/java/calculator/MultiplyService.java b/java/sca/modules/core-spring/src/test/java/calculator/MultiplyService.java new file mode 100644 index 0000000000..686542c18e --- /dev/null +++ b/java/sca/modules/core-spring/src/test/java/calculator/MultiplyService.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 calculator; + +/** + * The Multiply Service interface. + * + * @version $Rev$ $Date$ + */ +public interface MultiplyService { + + double multiply(double n1, double n2); + +} diff --git a/java/sca/modules/core-spring/src/test/java/calculator/MultiplyServiceImpl.java b/java/sca/modules/core-spring/src/test/java/calculator/MultiplyServiceImpl.java new file mode 100644 index 0000000000..d621407908 --- /dev/null +++ b/java/sca/modules/core-spring/src/test/java/calculator/MultiplyServiceImpl.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.Scope; + +/** + * An implementation of the Multiply service. + * + * @version $Rev$ $Date$ + */ +@Scope("COMPOSITE") +public class MultiplyServiceImpl implements MultiplyService { + + public double multiply(double n1, double n2) { + return n1 * n2; + } + +} diff --git a/java/sca/modules/core-spring/src/test/java/calculator/NestedCalculatorClient.java b/java/sca/modules/core-spring/src/test/java/calculator/NestedCalculatorClient.java new file mode 100644 index 0000000000..e8e4a6f71b --- /dev/null +++ b/java/sca/modules/core-spring/src/test/java/calculator/NestedCalculatorClient.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 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. + * + * @version $Rev$ $Date$ + */ +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/java/sca/modules/core-spring/src/test/java/calculator/SubtractService.java b/java/sca/modules/core-spring/src/test/java/calculator/SubtractService.java new file mode 100644 index 0000000000..30632688f9 --- /dev/null +++ b/java/sca/modules/core-spring/src/test/java/calculator/SubtractService.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 calculator; + +/** + * The Subtract Service interface. + * + * @version $Rev$ $Date$ + */ +public interface SubtractService { + + double subtract(double n1, double n2); + +} diff --git a/java/sca/modules/core-spring/src/test/java/calculator/SubtractServiceImpl.java b/java/sca/modules/core-spring/src/test/java/calculator/SubtractServiceImpl.java new file mode 100644 index 0000000000..4fed0a8c6a --- /dev/null +++ b/java/sca/modules/core-spring/src/test/java/calculator/SubtractServiceImpl.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.Scope; + +/** + * An implementation of the subtract service. + * + * @version $Rev$ $Date$ + */ +@Scope("COMPOSITE") +public class SubtractServiceImpl implements SubtractService { + + public double subtract(double n1, double n2) { + return n1 - n2; + } + +} diff --git a/java/sca/modules/core-spring/src/test/java/org/apache/tuscany/sca/core/spring/CalculatorTestCase.java b/java/sca/modules/core-spring/src/test/java/org/apache/tuscany/sca/core/spring/CalculatorTestCase.java new file mode 100644 index 0000000000..44b447cc64 --- /dev/null +++ b/java/sca/modules/core-spring/src/test/java/org/apache/tuscany/sca/core/spring/CalculatorTestCase.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.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. + * + * @version $Rev$ $Date$ + */ +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/java/sca/modules/core-spring/src/test/java/org/apache/tuscany/sca/core/spring/NestedCalculatorTestCaseFIXME.java b/java/sca/modules/core-spring/src/test/java/org/apache/tuscany/sca/core/spring/NestedCalculatorTestCaseFIXME.java new file mode 100644 index 0000000000..baf73ac197 --- /dev/null +++ b/java/sca/modules/core-spring/src/test/java/org/apache/tuscany/sca/core/spring/NestedCalculatorTestCaseFIXME.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.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. + * + * @version $Rev$ $Date$ + */ +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/java/sca/modules/core-spring/src/test/resources/org/apache/tuscany/sca/core/spring/Calculator.composite b/java/sca/modules/core-spring/src/test/resources/org/apache/tuscany/sca/core/spring/Calculator.composite new file mode 100644 index 0000000000..6d998ba035 --- /dev/null +++ b/java/sca/modules/core-spring/src/test/resources/org/apache/tuscany/sca/core/spring/Calculator.composite @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/java/sca/modules/core-spring/src/test/resources/org/apache/tuscany/sca/core/spring/InnerCalculator.composite b/java/sca/modules/core-spring/src/test/resources/org/apache/tuscany/sca/core/spring/InnerCalculator.composite new file mode 100644 index 0000000000..8b043f2b4f --- /dev/null +++ b/java/sca/modules/core-spring/src/test/resources/org/apache/tuscany/sca/core/spring/InnerCalculator.composite @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/java/sca/modules/core-spring/src/test/resources/org/apache/tuscany/sca/core/spring/InnerOperations.composite b/java/sca/modules/core-spring/src/test/resources/org/apache/tuscany/sca/core/spring/InnerOperations.composite new file mode 100644 index 0000000000..d7d1124050 --- /dev/null +++ b/java/sca/modules/core-spring/src/test/resources/org/apache/tuscany/sca/core/spring/InnerOperations.composite @@ -0,0 +1,57 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/java/sca/modules/core-spring/src/test/resources/org/apache/tuscany/sca/core/spring/OuterCalculator.composite b/java/sca/modules/core-spring/src/test/resources/org/apache/tuscany/sca/core/spring/OuterCalculator.composite new file mode 100644 index 0000000000..c2b6cced36 --- /dev/null +++ b/java/sca/modules/core-spring/src/test/resources/org/apache/tuscany/sca/core/spring/OuterCalculator.composite @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/java/sca/modules/data-engine-helper/LICENSE b/java/sca/modules/data-engine-helper/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/java/sca/modules/data-engine-helper/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/java/sca/modules/data-engine-helper/NOTICE b/java/sca/modules/data-engine-helper/NOTICE new file mode 100644 index 0000000000..fdfa0e9faa --- /dev/null +++ b/java/sca/modules/data-engine-helper/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2008 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/java/sca/modules/data-engine-helper/pom.xml b/java/sca/modules/data-engine-helper/pom.xml new file mode 100644 index 0000000000..ba01e8fa24 --- /dev/null +++ b/java/sca/modules/data-engine-helper/pom.xml @@ -0,0 +1,142 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 2.0-SNAPSHOT + ../pom.xml + + tuscany-data-engine-helper + Apache Tuscany SCA Data Engine Helper + + + + apache.incubator + http://people.apache.org/repo/m2-incubating-repository + + + + + + org.apache.tuscany.das + tuscany-das-rdb + 1.0-SNAPSHOT + compile + + + + org.apache.tuscany.sca + tuscany-assembly + 2.0-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-core + 2.0-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-interface + 2.0-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-assembly-xml + 2.0-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-contribution-impl + 2.0-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-sca-api + 2.0-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-databinding + 2.0-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-implementation-java-runtime + 2.0-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-host-embedded + 2.0-SNAPSHOT + + + + junit + junit + 3.8.1 + test + + + + org.easymock + easymock + 2.2 + test + + + + org.apache.derby + derby + 10.3.1.4 + test + + + + + ${artifactId} + + + + org.apache.felix + maven-bundle-plugin + + + + ${tuscany.version} + org.apache.tuscany.sca.data.engine.helper + ${pom.name} + org.apache.tuscany.sca.data.engine* + + + + + + + diff --git a/java/sca/modules/data-engine-helper/src/main/java/org/apache/tuscany/sca/data/engine/ConnectionInfoArtifactProcessor.java b/java/sca/modules/data-engine-helper/src/main/java/org/apache/tuscany/sca/data/engine/ConnectionInfoArtifactProcessor.java new file mode 100644 index 0000000000..99709857b8 --- /dev/null +++ b/java/sca/modules/data-engine-helper/src/main/java/org/apache/tuscany/sca/data/engine/ConnectionInfoArtifactProcessor.java @@ -0,0 +1,197 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.data.engine; + +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.builder.impl.ProblemImpl; +import org.apache.tuscany.sca.assembly.xml.Constants; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.contribution.service.ContributionResolveException; +import org.apache.tuscany.sca.contribution.service.ContributionWriteException; +import org.apache.tuscany.sca.data.engine.config.ConnectionInfo; +import org.apache.tuscany.sca.data.engine.config.ConnectionProperties; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.monitor.Problem; +import org.apache.tuscany.sca.monitor.Problem.Severity; + +/** + * Implements a StAX artifact processor for ConnectionInfo. + * This processor is shared between implementation.das and implementation.data component type implementations, + * and can be used for other applications that require database connectivity information. + * + * The artifact processor is responsible for processing + * elements in SCA assembly XML composite files. + * + * @version $Rev$ $Date$ + */ +public class ConnectionInfoArtifactProcessor implements StAXArtifactProcessor { + public static final QName CONNECTION_INFO = new QName(Constants.SCA10_TUSCANY_NS, "connectionInfo"); + private static final QName CONNECTION_PROPERTIES = new QName(Constants.SCA10_TUSCANY_NS, "connectionProperties"); + + private Monitor monitor; + public ConnectionInfoArtifactProcessor(ModelFactoryExtensionPoint modelFactories, Monitor monitor) { + this.monitor = monitor; + } + + public QName getArtifactType() { + // Returns the QName of the XML element processed by this processor + return CONNECTION_INFO; + } + + /** + * Report a exception. + * + * @param problems + * @param message + * @param model + */ + private void error(String message, Object model, Exception ex) { + if (monitor != null) { + Problem problem = new ProblemImpl(this.getClass().getName(), "dataengine-helper-validation-messages", Severity.ERROR, model, message, ex); + monitor.problem(problem); + } + } + + public Class getModelType() { + // Returns the type of model processed by this processor + return ConnectionInfo.class; + } + + /* + * + * + * + * + * + * + * + * + * + */ + public ConnectionInfo read(XMLStreamReader reader) throws ContributionReadException { + assert CONNECTION_INFO.equals(reader.getName()); + + // Create a ConnectionInfo from the component type model + ConnectionInfo connectionInfo = new ConnectionInfo(); + + /* + * + */ + String dataSource = reader.getAttributeValue(null, "datasource"); // exclusive with connection properties + if (dataSource != null && dataSource.length() > 0) { + connectionInfo.setDataSource(dataSource); + } else { + try { + int event = reader.next(); + while (event == XMLStreamConstants.CHARACTERS) { + event = reader.next(); + } + } catch (XMLStreamException e) { + ContributionReadException ce = new ContributionReadException(e); + error("ContributionReadException", reader, ce); + throw ce; + } + + QName element = reader.getName(); + + assert CONNECTION_PROPERTIES.equals(element); + + /* + * + */ + + String driverClass = reader.getAttributeValue(null, "driverClass"); + String databaseURL = reader.getAttributeValue(null, "databaseURL"); + String username = reader.getAttributeValue(null, "username"); + String password = reader.getAttributeValue(null, "password"); + String loginTimeout = reader.getAttributeValue(null, "loginTimeout"); + + // FIXME: validation sending info to monitor.... + ConnectionProperties connectionProperties = new ConnectionProperties(); + connectionProperties.setDriverClass(driverClass); + connectionProperties.setDatabaseURL(databaseURL); + connectionProperties.setUsername(username); + connectionProperties.setPassword(password); + if (loginTimeout != null) { + connectionProperties.setLoginTimeout(Integer.parseInt(loginTimeout)); + } + + connectionInfo.setConnectionProperties(connectionProperties); + } + + return connectionInfo; + } + + public void resolve(ConnectionInfo impl, ModelResolver resolver) throws ContributionResolveException { + + } + + public void write(ConnectionInfo connectionInfo, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException { + + writer.writeStartElement(CONNECTION_INFO.getNamespaceURI(), CONNECTION_INFO.getLocalPart()); + + if (connectionInfo.getDataSource() != null) { + writer.writeAttribute("dataSource", connectionInfo.getDataSource()); + } + + ConnectionProperties connectionProperties = connectionInfo.getConnectionProperties(); + if (connectionProperties != null) { + writer.writeStartElement(CONNECTION_PROPERTIES.getNamespaceURI(), CONNECTION_PROPERTIES.getLocalPart()); + + if (connectionProperties.getDriverClass() != null) { + writer.writeAttribute("driverClass", connectionProperties.getDriverClass()); + } + if (connectionProperties.getDatabaseURL() != null) { + writer.writeAttribute("databaseURL", connectionProperties.getDatabaseURL()); + } + if (connectionProperties.getUsername() != null) { + writer.writeAttribute("username", connectionProperties.getUsername()); + } + if (connectionProperties.getPassword() != null) { + writer.writeAttribute("password", connectionProperties.getPassword()); + } + if (connectionProperties.getLoginTimeout() != null) { + writer.writeAttribute("loginTimeout", String.valueOf(connectionProperties.getLoginTimeout())); + } + + writer.writeEndElement(); + } + + + writer.writeEndElement(); + + } +} diff --git a/java/sca/modules/data-engine-helper/src/main/java/org/apache/tuscany/sca/data/engine/DataAccessEngine.java b/java/sca/modules/data-engine-helper/src/main/java/org/apache/tuscany/sca/data/engine/DataAccessEngine.java new file mode 100644 index 0000000000..aef9ac3261 --- /dev/null +++ b/java/sca/modules/data-engine-helper/src/main/java/org/apache/tuscany/sca/data/engine/DataAccessEngine.java @@ -0,0 +1,286 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.data.engine; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.tuscany.das.rdb.Command; +import org.apache.tuscany.das.rdb.DAS; + +import commonj.sdo.DataObject; +import commonj.sdo.Property; + +/** + * Facade to hide DAS implementation details of handling commands + * + * @version $Rev$ $Date$ + */ +public class DataAccessEngine { + private final DAS das; + + public DataAccessEngine(DAS das) { + this.das = das; + } + + public DataObject executeGet(ArrayList keyVals, String table, String key) {//TODO need to consider compound keys + try { + String sqlQuery = "select * from " + table.toUpperCase(); + List keys = null; + + if(key == null) { + if(keyVals != null && keyVals.size() == 1) { + sqlQuery += " where ID = " + keyVals.get(0); + } + } else {//can be other than ID , can be compound keys + keys = getKeys(key); + if(keyVals.size() != keys.size()) { + throw new RuntimeException("One or more PK values missing"); + } + + sqlQuery += " where "; + + for(int i=0; i executeGetAll(String table, String key) { + try { + String sqlQuery = "select * from " + table.toUpperCase(); + Command command = this.das.createCommand(sqlQuery); + DataObject result = command.executeQuery(); + List keys = getKeys(key); + List resultDataObjects = result.getList(table); + + return getMappedDataObjects(resultDataObjects, keys); + } catch (Exception e) { + //e.printStackTrace(); + throw new RuntimeException(e); + } + } + + public Map executeQuery(String queryString, String table, String key) { + try { + Command command = this.das.createCommand(queryString); + DataObject result = command.executeQuery(); + List keys = getKeys(key); + List resultDataObjects = result.getList(table); + + return getMappedDataObjects(resultDataObjects, keys); + } catch (Exception e) { + //e.printStackTrace(); + throw new RuntimeException(e); + } + } + + //origDataObject should be with change summary. table, pk is already known to DAS, so no need to have these here + public void executePut(DataObject origDataObject) { + this.das.applyChanges(origDataObject); + return; + } + + //return PK/s + public ArrayList executePost(DataObject origDataObject, String table, String key){ + //TODO check that PKs are present before insert - this is not correct for auto incr PKs, so let it be upto user whether to send PK or not + /*List keys = getKeys(key); + for(int i=0; i keys = getKeys(key); + for(int i=0; i keys = null; + + if(key == null) { + if(keyVals != null && keyVals.size() == 1) { + sqlQuery += " where ID = " + keyVals.get(0); + } + } else {//can be other than ID , can be compound keys + keys = getKeys(key); + if(keyVals.size() != keys.size()) { + throw new RuntimeException("One or more PK values missing"); + } + + sqlQuery += " where "; + + for(int i=0; i resultDOs = result.getList(table); + if(resultDOs != null) { + for(int i=0; i getMappedDataObjects(List resultDataObjects, List keys) { + Map resultMap = new HashMap(); + ArrayList keyCols = null; + for(int j=0; j(); + for(int i=0; i getKeys(String key) { + String[] keys = key.split(","); + return Arrays.asList(keys); + } + + public DataObject executeCommand(String commandName) { + try { + Command command = this.das.getCommand(commandName); + return command.executeQuery(); + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } + + public DataObject executeCommand(String commandName, String xPath) { + DataObject root = executeCommand(commandName); + return root.getDataObject(xPath); + } +} diff --git a/java/sca/modules/data-engine-helper/src/main/java/org/apache/tuscany/sca/data/engine/DataAccessEngineManager.java b/java/sca/modules/data-engine-helper/src/main/java/org/apache/tuscany/sca/data/engine/DataAccessEngineManager.java new file mode 100644 index 0000000000..572c190037 --- /dev/null +++ b/java/sca/modules/data-engine-helper/src/main/java/org/apache/tuscany/sca/data/engine/DataAccessEngineManager.java @@ -0,0 +1,141 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.data.engine; + +import java.io.InputStream; +import java.util.List; + +import org.apache.tuscany.das.rdb.ConfigHelper; +import org.apache.tuscany.das.rdb.DAS; +import org.apache.tuscany.das.rdb.config.wrapper.MappingWrapper; +import org.apache.tuscany.sca.data.engine.config.ConnectionInfo; + +/** + * The DataAccessEngineManager acts like a registry and factory for DAS instances + * It holds DAS by it's config file name, reusing the same DAS for all components + * using the same config file. + * + * @version $Rev$ $Date$ + */ +public class DataAccessEngineManager { + //private final Map registry = new HashMap(); + + public DataAccessEngineManager() { + super(); + } + + protected DAS initializeDAS(String config, ConnectionInfo connectionInfo, String table, String pkColumns) throws MissingConfigFileException { + //load the config file + //System.out.println("Initializing DAS"); + + ConfigHelper configHelper; + + if(config == null) { + //no config information + configHelper = new ConfigHelper(); + } else { + //initialize the config helper by loading config file + configHelper = new ConfigHelper(this.getConfigStream(config)); + } + + //add additional connectionInfo if provided in the SCA Composite file + if( connectionInfo != null) { + String dataSource = connectionInfo.getDataSource(); + if(dataSource != null && dataSource.length() > 0) { + configHelper.addConnectionInfo(dataSource); + } else { + String driverClass = connectionInfo.getConnectionProperties().getDriverClass(); + String connectionURL = connectionInfo.getConnectionProperties().getDatabaseURL(); + String userName = connectionInfo.getConnectionProperties().getUsername(); + String password = connectionInfo.getConnectionProperties().getPassword(); + int loginTimeout = connectionInfo.getConnectionProperties().getLoginTimeout(); + + configHelper.addConnectionInfo(driverClass, connectionURL, userName, password, loginTimeout); + } + + } + + if(table != null && pkColumns != null) { + MappingWrapper configWrapper = new MappingWrapper(configHelper.getConfig()); + List pkColsList = DataAccessEngine.getKeys(pkColumns); + for(int i=0; i + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 2.0-SNAPSHOT + ../pom.xml + + tuscany-implementation-bpel-jbpm + Apache Tuscany SCA BPEL jBPM Implementation Extension + + + org.apache.tuscany.sca + tuscany-assembly + 2.0-SNAPSHOT + + + org.apache.tuscany.sca + tuscany-implementation-bpel + 2.0-SNAPSHOT + + + org.apache.tuscany.sca + tuscany-core + 2.0-SNAPSHOT + + + org.apache.tuscany.sca + tuscany-interface + 2.0-SNAPSHOT + + + org.apache.tuscany.sca + tuscany-assembly-xml + 2.0-SNAPSHOT + + + org.apache.tuscany.sca + tuscany-contribution-impl + 2.0-SNAPSHOT + + + org.apache.tuscany.sca + tuscany-sca-api + 2.0-SNAPSHOT + + + org.apache.tuscany.sca + tuscany-databinding + 2.0-SNAPSHOT + + + org.apache.tuscany.sca + tuscany-databinding-sdo + 2.0-SNAPSHOT + + + org.apache.tuscany.sca + tuscany-implementation-java-runtime + 2.0-SNAPSHOT + + + org.apache.tuscany.sca + tuscany-host-embedded + 2.0-SNAPSHOT + + + org.apache.tuscany.sca + tuscany-interface-wsdl + 2.0-SNAPSHOT + + + org.apache.tuscany.sca + tuscany-interface-wsdl-xml + 2.0-SNAPSHOT + + + org.apache.tuscany.sdo + tuscany-sdo-impl + 1.1.1 + compile + + + stax + stax-api + + + + + junit + junit + 3.8.1 + test + + + org.easymock + easymock + 2.2 + test + + + + + + + + org.apache.felix + maven-bundle-plugin + + + + ${tuscany.version} + org.apache.tuscany.sca.implementation.bpel.jbpm + ${pom.name} + org.apache.tuscany.sca.implementation.bpel.jbpm* + + + + + + diff --git a/java/sca/modules/implementation-bpel-jbpm/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.ImplementationProviderFactory b/java/sca/modules/implementation-bpel-jbpm/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.ImplementationProviderFactory new file mode 100644 index 0000000000..61d74d4c37 --- /dev/null +++ b/java/sca/modules/implementation-bpel-jbpm/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.ImplementationProviderFactory @@ -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 class for the implementation extension +# +# +# ==> Change this for JBPM +#org.apache.tuscany.sca.implementation.bpel.ode.provider.BPELImplementationProviderFactory;model=org.apache.tuscany.sca.implementation.bpel.BPELImplementation diff --git a/java/sca/modules/monitor-logging/LICENSE b/java/sca/modules/monitor-logging/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/java/sca/modules/monitor-logging/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/java/sca/modules/monitor-logging/NOTICE b/java/sca/modules/monitor-logging/NOTICE new file mode 100644 index 0000000000..fdfa0e9faa --- /dev/null +++ b/java/sca/modules/monitor-logging/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2008 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/java/sca/modules/monitor-logging/pom.xml b/java/sca/modules/monitor-logging/pom.xml new file mode 100644 index 0000000000..21c079ef48 --- /dev/null +++ b/java/sca/modules/monitor-logging/pom.xml @@ -0,0 +1,68 @@ + + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 2.0-SNAPSHOT + ../pom.xml + + + tuscany-monitor-logging + Apache Tuscany SCA Monitor Default Logging Implementation + + + + + org.apache.tuscany.sca + tuscany-monitor + 2.0-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-assembly + 2.0-SNAPSHOT + + + + + + + + + org.apache.felix + maven-bundle-plugin + + + + ${tuscany.version} + org.apache.tuscany.sca.monitor.logging + ${pom.name} + org.apache.tuscany.sca.monitor* + + + + + + + diff --git a/java/sca/modules/monitor-logging/src/main/java/org/apache/tuscany/sca/monitor/logging/impl/DefaultLoggingMonitorImpl.java b/java/sca/modules/monitor-logging/src/main/java/org/apache/tuscany/sca/monitor/logging/impl/DefaultLoggingMonitorImpl.java new file mode 100644 index 0000000000..8a9701b8fc --- /dev/null +++ b/java/sca/modules/monitor-logging/src/main/java/org/apache/tuscany/sca/monitor/logging/impl/DefaultLoggingMonitorImpl.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.monitor.logging.impl; + +import java.util.ArrayList; +import java.util.List; +import java.util.logging.Level; +import java.util.logging.Logger; + +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.monitor.Problem; +import org.apache.tuscany.sca.monitor.Problem.Severity; + + +/** + * A monitor for the watching for validation problems + * + * @version $Rev$ $Date$ + */ +public class DefaultLoggingMonitorImpl implements Monitor { + private static final Logger logger = Logger.getLogger(DefaultLoggingMonitorImpl.class.getName()); + + // Cache all the problem reported to monitor for further analysis + private List problemCache = new ArrayList(); + + public void problem(Problem problem) { + + Logger problemLogger = Logger.getLogger(problem.getSourceClassName(), problem.getBundleName()); + + if (problemLogger == null){ + logger.severe("Can't get logger " + problem.getSourceClassName()+ " with bundle " + problem.getBundleName()); + } + + if (problem.getSeverity() == Severity.INFO) { + problemCache.add(problem); + problemLogger.logp(Level.INFO, problem.getSourceClassName(), null, + problem.getMessageId(), problem.getMessageParams()); + } + else if (problem.getSeverity() == Severity.WARNING) { + problemCache.add(problem); + problemLogger.logp(Level.WARNING, problem.getSourceClassName(), null, + problem.getMessageId(), problem.getMessageParams()); + } + else if (problem.getSeverity() == Severity.ERROR) { + if (problem.getCause() != null) { + problemCache.add(problem); + problemLogger.logp(Level.SEVERE, problem.getSourceClassName(), + null, problem.getMessageId(), problem.getCause().toString()); + } else { + problemCache.add(problem); + problemLogger.logp(Level.SEVERE, problem.getSourceClassName(), null, + problem.getMessageId(), problem.getMessageParams()); + } + } + } + + public List getProblems(){ + return problemCache; + } + + public Problem getLastLoggedProblem() { + if (problemCache.isEmpty()) { + return null; + } + return problemCache.get(problemCache.size() - 1); + } + + public boolean isMessageLogged(String messageId) { + for (Problem problem : problemCache){ + if (problem.getMessageId().equals(messageId)){ + return true; + } + } + + return false; + } + + public Problem getProblem(String messageId) { + for (Problem problem : problemCache){ + if (problem.getMessageId().equals(messageId)){ + return problem; + } + } + + return null; + } +} diff --git a/java/sca/modules/monitor-logging/src/main/java/org/apache/tuscany/sca/monitor/logging/impl/MonitorFactoryImpl.java b/java/sca/modules/monitor-logging/src/main/java/org/apache/tuscany/sca/monitor/logging/impl/MonitorFactoryImpl.java new file mode 100644 index 0000000000..a3162a3267 --- /dev/null +++ b/java/sca/modules/monitor-logging/src/main/java/org/apache/tuscany/sca/monitor/logging/impl/MonitorFactoryImpl.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.monitor.logging.impl; + +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.monitor.MonitorFactory; + + +/** + * A factory for creating validation monitors + * + * @version $Rev$ $Date$ + */ +public class MonitorFactoryImpl implements MonitorFactory { + + private Monitor monitor = null; + + public Monitor createMonitor() { + if (monitor == null){ + monitor = new DefaultLoggingMonitorImpl(); + } + return monitor ; + } +} diff --git a/java/sca/modules/monitor-logging/src/main/resources/META-INF/services/org.apache.tuscany.sca.monitor.MonitorFactory b/java/sca/modules/monitor-logging/src/main/resources/META-INF/services/org.apache.tuscany.sca.monitor.MonitorFactory new file mode 100644 index 0000000000..b46d552fb5 --- /dev/null +++ b/java/sca/modules/monitor-logging/src/main/resources/META-INF/services/org.apache.tuscany.sca.monitor.MonitorFactory @@ -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.monitor.logging.impl.MonitorFactoryImpl diff --git a/java/sca/modules/monitor-logging/src/test/java/org/apache/tuscany/sca/monitor/MonitorTestCase.java b/java/sca/modules/monitor-logging/src/test/java/org/apache/tuscany/sca/monitor/MonitorTestCase.java new file mode 100644 index 0000000000..c5fa6c4da6 --- /dev/null +++ b/java/sca/modules/monitor-logging/src/test/java/org/apache/tuscany/sca/monitor/MonitorTestCase.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.monitor; + +import org.apache.tuscany.sca.assembly.builder.impl.ProblemImpl; +import org.apache.tuscany.sca.monitor.Problem.Severity; +import org.apache.tuscany.sca.monitor.logging.impl.MonitorFactoryImpl; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * Loads a monitor and adds some problems to it. + * + * @version $Rev$ $Date$ + */ +public class MonitorTestCase { + + private static MonitorFactory monitorFactory; + + @BeforeClass + public static void init() throws Exception { + monitorFactory = new MonitorFactoryImpl(); + } + + @AfterClass + public static void destroy() throws Exception { + monitorFactory = null; + } + + @Test + public void testCreateProblem() throws Exception { + String dummyModelObject = "DUMMY MODEL OBJECT"; + + Monitor monitor = monitorFactory.createMonitor(); + + Problem problem = null; + + problem = new ProblemImpl(this.getClass().getName(), + "tuscany-monitor-test-messages", + Severity.WARNING, + dummyModelObject, + "MESSAGE1" ); + monitor.problem(problem); + + String param = "Some Parameter"; + + problem = new ProblemImpl(this.getClass().getName(), + "tuscany-monitor-test-messages", + Severity.WARNING, + dummyModelObject, + "MESSAGE2", + param); + monitor.problem(problem); + + problem = new ProblemImpl(this.getClass().getName(), + "tuscany-monitor-test-messages", + Severity.WARNING, + dummyModelObject, + "MESSAGE3", + 8, + 9, + 4); + monitor.problem(problem); + + Exception ex = new IllegalStateException("TEST_MESSAGE"); + + problem = new ProblemImpl(this.getClass().getName(), + "tuscany-monitor-test-messages", + Severity.ERROR, + dummyModelObject, + "MESSAGE4", + ex); + monitor.problem(problem); + + } +} diff --git a/java/sca/modules/monitor-logging/src/test/resources/tuscany-monitor-test-messages.properties b/java/sca/modules/monitor-logging/src/test/resources/tuscany-monitor-test-messages.properties new file mode 100644 index 0000000000..523263da40 --- /dev/null +++ b/java/sca/modules/monitor-logging/src/test/resources/tuscany-monitor-test-messages.properties @@ -0,0 +1,24 @@ +# +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +# +MESSAGE1 = This is a test message with no params +MESSAGE2 = This is a test message with a string param {0} +MESSAGE3 = This is a test message with numbers {0}, {1}, {2} +MESSAGE4 = This is a test message with exception diff --git a/java/sca/modules/monitor-logging/src/test/resources/tuscany-monitor-test-messages_it.properties b/java/sca/modules/monitor-logging/src/test/resources/tuscany-monitor-test-messages_it.properties new file mode 100644 index 0000000000..523263da40 --- /dev/null +++ b/java/sca/modules/monitor-logging/src/test/resources/tuscany-monitor-test-messages_it.properties @@ -0,0 +1,24 @@ +# +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +# +MESSAGE1 = This is a test message with no params +MESSAGE2 = This is a test message with a string param {0} +MESSAGE3 = This is a test message with numbers {0}, {1}, {2} +MESSAGE4 = This is a test message with exception -- cgit v1.2.3