From 0f3f9b59b310833f31ba234ee4aefa808649833c Mon Sep 17 00:00:00 2001 From: lresende Date: Wed, 11 Nov 2009 23:06:50 +0000 Subject: Moving 1.x branches git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@835120 13f79535-47bb-0310-9956-ffa450edef68 --- .../modules/assembly-java-dsl/DISCLAIMER | 8 + .../modules/assembly-java-dsl/LICENSE | 205 +++ .../sca-java-0.91/modules/assembly-java-dsl/NOTICE | 6 + .../modules/assembly-java-dsl/pom.xml | 38 + .../tuscany/sca/assembly/dsl/AssemblyBuilder.java | 37 + .../tuscany/sca/assembly/dsl/ComponentBuilder.java | 34 + .../sca/assembly/dsl/ComponentPropertyBuilder.java | 28 + .../assembly/dsl/ComponentReferenceBuilder.java | 36 + .../sca/assembly/dsl/ComponentServiceBuilder.java | 32 + .../tuscany/sca/assembly/dsl/CompositeBuilder.java | 29 + .../sca/assembly/dsl/impl/AssemblyBuilderImpl.java | 70 + .../assembly/dsl/impl/ComponentBuilderImpl.java | 74 ++ .../dsl/impl/ComponentPropertyBuilderImpl.java | 40 + .../dsl/impl/ComponentReferenceBuilderImpl.java | 77 ++ .../dsl/impl/ComponentServiceBuilderImpl.java | 62 + .../assembly/dsl/impl/CompositeBuilderImpl.java | 62 + .../sca/assembly/dsl/AccountDataService.java | 24 + .../sca/assembly/dsl/AccountDataServiceImpl.java | 24 + .../tuscany/sca/assembly/dsl/AccountService.java | 24 + .../sca/assembly/dsl/AccountServiceImpl.java | 24 + .../tuscany/sca/assembly/dsl/BigBankBuilder.java | 59 + .../sca/assembly/dsl/BigBankBuilderTestCase.java | 38 + .../sca/assembly/dsl/StockQuoteService.java | 24 + .../sca-java-0.91/modules/assembly-xml/.checkstyle | 24 + .../sca-java-0.91/modules/assembly-xml/.pmd | 20 + .../sca-java-0.91/modules/assembly-xml/.ruleset | 190 +++ .../sca-java-0.91/modules/assembly-xml/DISCLAIMER | 8 + .../sca-java-0.91/modules/assembly-xml/LICENSE | 205 +++ .../sca-java-0.91/modules/assembly-xml/NOTICE | 6 + .../sca-java-0.91/modules/assembly-xml/pom.xml | 58 + .../sca/assembly/xml/BaseArtifactProcessor.java | 686 ++++++++++ .../xml/ComponentTypeDocumentProcessor.java | 94 ++ .../sca/assembly/xml/ComponentTypeProcessor.java | 271 ++++ .../assembly/xml/CompositeDocumentProcessor.java | 93 ++ .../sca/assembly/xml/CompositeProcessor.java | 498 ++++++++ .../apache/tuscany/sca/assembly/xml/Constants.java | 74 ++ .../xml/ConstrainingTypeDocumentProcessor.java | 93 ++ .../assembly/xml/ConstrainingTypeProcessor.java | 205 +++ .../org/apache/tuscany/sca/assembly/xml/XAttr.java | 122 ++ .../tuscany/sca/assembly/xml/ReadAllTestCase.java | 159 +++ .../sca/assembly/xml/ReadDocumentTestCase.java | 113 ++ .../tuscany/sca/assembly/xml/ReadTestCase.java | 104 ++ .../tuscany/sca/assembly/xml/ResolveTestCase.java | 117 ++ .../tuscany/sca/assembly/xml/StAXPerfTest.java | 105 ++ .../sca/assembly/xml/TestModelResolver.java | 63 + .../tuscany/sca/assembly/xml/WireTestCase.java | 126 ++ .../tuscany/sca/assembly/xml/WriteAllTestCase.java | 115 ++ .../tuscany/sca/assembly/xml/Calculator.composite | 53 + .../xml/CalculatorComponent.constrainingType | 34 + .../sca/assembly/xml/CalculatorImpl.componentType | 31 + .../sca/assembly/xml/TestAllCalculator.composite | 119 ++ .../sca/assembly/xml/TestAllDivide.composite | 56 + .../sca-java-0.91/modules/assembly/.checkstyle | 24 + .../branches/sca-java-0.91/modules/assembly/.pmd | 21 + .../sca-java-0.91/modules/assembly/.ruleset | 190 +++ .../sca-java-0.91/modules/assembly/DISCLAIMER | 8 + .../sca-java-0.91/modules/assembly/LICENSE | 205 +++ .../branches/sca-java-0.91/modules/assembly/NOTICE | 6 + .../sca-java-0.91/modules/assembly/pom.xml | 44 + .../tuscany/sca/assembly/AbstractContract.java | 62 + .../tuscany/sca/assembly/AbstractProperty.java | 122 ++ .../tuscany/sca/assembly/AbstractReference.java | 43 + .../tuscany/sca/assembly/AbstractService.java | 28 + .../tuscany/sca/assembly/AssemblyFactory.java | 156 +++ .../java/org/apache/tuscany/sca/assembly/Base.java | 51 + .../org/apache/tuscany/sca/assembly/Binding.java | 58 + .../org/apache/tuscany/sca/assembly/Callback.java | 40 + .../org/apache/tuscany/sca/assembly/Component.java | 133 ++ .../tuscany/sca/assembly/ComponentProperty.java | 80 ++ .../tuscany/sca/assembly/ComponentReference.java | 64 + .../tuscany/sca/assembly/ComponentService.java | 49 + .../apache/tuscany/sca/assembly/ComponentType.java | 80 ++ .../org/apache/tuscany/sca/assembly/Composite.java | 108 ++ .../tuscany/sca/assembly/CompositeReference.java | 37 + .../tuscany/sca/assembly/CompositeService.java | 42 + .../tuscany/sca/assembly/ConstrainingType.java | 72 ++ .../org/apache/tuscany/sca/assembly/Contract.java | 63 + .../sca/assembly/DefaultAssemblyFactory.java | 31 + .../sca/assembly/DefaultSCABindingFactory.java | 31 + .../tuscany/sca/assembly/Implementation.java | 28 + .../apache/tuscany/sca/assembly/Multiplicity.java | 49 + .../org/apache/tuscany/sca/assembly/Property.java | 41 + .../org/apache/tuscany/sca/assembly/Reference.java | 64 + .../apache/tuscany/sca/assembly/SCABinding.java | 32 + .../tuscany/sca/assembly/SCABindingFactory.java | 36 + .../org/apache/tuscany/sca/assembly/Service.java | 37 + .../org/apache/tuscany/sca/assembly/Visitable.java | 37 + .../org/apache/tuscany/sca/assembly/Visitor.java | 36 + .../java/org/apache/tuscany/sca/assembly/Wire.java | 67 + .../assembly/builder/ComponentPreProcessor.java | 28 + .../sca/assembly/builder/CompositeBuilder.java | 40 + .../builder/CompositeBuilderException.java | 45 + .../assembly/builder/CompositeBuilderMonitor.java | 36 + .../tuscany/sca/assembly/builder/Problem.java | 45 + .../builder/impl/CompositeBuilderImpl.java | 1344 ++++++++++++++++++++ .../sca/assembly/builder/impl/ProblemImpl.java | 98 ++ .../sca/assembly/builder/impl/PropertyUtil.java | 189 +++ .../sca/assembly/builder/impl/ReferenceUtil.java | 94 ++ .../sca/assembly/impl/AbstractPropertyImpl.java | 102 ++ .../sca/assembly/impl/AbstractReferenceImpl.java | 46 + .../sca/assembly/impl/AbstractServiceImpl.java | 36 + .../sca/assembly/impl/AssemblyFactoryImpl.java | 121 ++ .../apache/tuscany/sca/assembly/impl/BaseImpl.java | 58 + .../tuscany/sca/assembly/impl/CallbackImpl.java | 62 + .../tuscany/sca/assembly/impl/ComponentImpl.java | 157 +++ .../sca/assembly/impl/ComponentPropertyImpl.java | 78 ++ .../sca/assembly/impl/ComponentReferenceImpl.java | 72 ++ .../sca/assembly/impl/ComponentServiceImpl.java | 60 + .../sca/assembly/impl/ComponentTypeImpl.java | 151 +++ .../tuscany/sca/assembly/impl/CompositeImpl.java | 136 ++ .../sca/assembly/impl/CompositeReferenceImpl.java | 51 + .../sca/assembly/impl/CompositeServiceImpl.java | 51 + .../sca/assembly/impl/ConstrainingTypeImpl.java | 116 ++ .../tuscany/sca/assembly/impl/ContractImpl.java | 59 + .../tuscany/sca/assembly/impl/PropertyImpl.java | 51 + .../tuscany/sca/assembly/impl/ReferenceImpl.java | 95 ++ .../sca/assembly/impl/SCABindingFactoryImpl.java | 36 + .../tuscany/sca/assembly/impl/SCABindingImpl.java | 91 ++ .../tuscany/sca/assembly/impl/ServiceImpl.java | 79 ++ .../apache/tuscany/sca/assembly/impl/WireImpl.java | 76 ++ .../tuscany/sca/assembly/util/PrintUtil.java | 172 +++ .../sca/assembly/AssemblyFactoryTestCase.java | 212 +++ .../apache/tuscany/sca/assembly/TestBinding.java | 69 + .../tuscany/sca/assembly/TestImplementation.java | 62 + .../apache/tuscany/sca/assembly/TestInterface.java | 42 + .../sca/assembly/TestInterfaceContract.java | 41 + .../apache/tuscany/sca/assembly/TestOperation.java | 31 + .../builder/impl/CompositeBuilderTestCase.java | 135 ++ .../sca-java-0.91/modules/binding-ajax/DISCLAIMER | 8 + .../sca-java-0.91/modules/binding-ajax/LICENSE | 205 +++ .../sca-java-0.91/modules/binding-ajax/NOTICE | 6 + .../sca-java-0.91/modules/binding-ajax/pom.xml | 76 ++ .../tuscany/sca/binding/ajax/AjaxBinding.java | 32 + .../sca/binding/ajax/AjaxBindingActivator.java | 56 + .../tuscany/sca/binding/ajax/AjaxInvoker.java | 88 ++ .../sca/binding/ajax/AjaxInvokerFactory.java | 69 + .../tuscany/sca/binding/ajax/AjaxService.java | 66 + .../tuscany/sca/binding/ajax/AjaxServlet.java | 444 +++++++ .../org.apache.tuscany.sca.spi.BindingActivator | 19 + .../sca-java-0.91/modules/binding-ejb/DISCLAIMER | 8 + .../sca-java-0.91/modules/binding-ejb/LICENSE | 205 +++ .../sca-java-0.91/modules/binding-ejb/NOTICE | 6 + .../sca-java-0.91/modules/binding-ejb/pom.xml | 456 +++++++ .../apache/tuscany/sca/binding/ejb/EJBBinding.java | 102 ++ .../sca/binding/ejb/EJBBindingActivator.java | 53 + .../tuscany/sca/binding/ejb/EJBTargetInvoker.java | 79 ++ .../sca/binding/ejb/java2idl/AttributeMode.java | 62 + .../sca/binding/ejb/java2idl/AttributeType.java | 136 ++ .../sca/binding/ejb/java2idl/ClassType.java | 61 + .../sca/binding/ejb/java2idl/ConstantType.java | 68 + .../sca/binding/ejb/java2idl/ContainerType.java | 791 ++++++++++++ .../sca/binding/ejb/java2idl/ExceptionType.java | 73 ++ .../tuscany/sca/binding/ejb/java2idl/IDLType.java | 65 + .../tuscany/sca/binding/ejb/java2idl/IDLUtil.java | 464 +++++++ .../ejb/java2idl/IDLViolationException.java | 50 + .../sca/binding/ejb/java2idl/InterfaceType.java | 158 +++ .../tuscany/sca/binding/ejb/java2idl/Java2IDL.java | 51 + .../sca/binding/ejb/java2idl/Java2IDLUtil.java | 403 ++++++ .../sca/binding/ejb/java2idl/OperationType.java | 106 ++ .../sca/binding/ejb/java2idl/ParameterType.java | 63 + .../sca/binding/ejb/java2idl/PrimitiveType.java | 66 + .../sca/binding/ejb/java2idl/ValueMemberType.java | 55 + .../sca/binding/ejb/java2idl/ValueType.java | 271 ++++ .../tuscany/sca/binding/ejb/util/EJBHandler.java | 420 ++++++ .../tuscany/sca/binding/ejb/util/EJBLocator.java | 511 ++++++++ .../sca/binding/ejb/util/EJBObjectFactory.java | 188 +++ .../sca/binding/ejb/util/EJBStubHelper.java | 69 + .../sca/binding/ejb/util/InterfaceInfo.java | 125 ++ .../binding/ejb/util/JavaReflectionAdapter.java | 155 +++ .../tuscany/sca/binding/ejb/util/MethodInfo.java | 176 +++ .../sca/binding/ejb/util/NamingEndpoint.java | 118 ++ .../org.apache.tuscany.sca.spi.BindingActivator | 19 + .../src/test/java/account/BankManagerFacade.java | 33 + .../src/test/java/account/Customer.java | 37 + .../src/test/java/account/CustomerImpl.java | 55 + .../samples/bank/ejb/BankManagerFacade.java | 44 + .../samples/bank/ejb/BankManagerFacadeHome.java | 44 + .../binding/ejb/tests/EJBReferenceTestCase.java | 56 + .../tuscany/sca/binding/ejb/tests/MockServer.java | 75 ++ .../sca/binding/ejb/tests/SocketTracer.java | 113 ++ .../src/test/resources/account/account.composite | 32 + .../sca-java-0.91/modules/binding-feed/DISCLAIMER | 8 + .../sca-java-0.91/modules/binding-feed/LICENSE | 205 +++ .../sca-java-0.91/modules/binding-feed/NOTICE | 6 + .../sca-java-0.91/modules/binding-feed/pom.xml | 93 ++ .../binding/feed/DefaultFeedBindingFactory.java | 32 + .../org/apache/tuscany/sca/binding/feed/Feed.java | 42 + .../tuscany/sca/binding/feed/FeedBinding.java | 41 + .../sca/binding/feed/FeedBindingFactory.java | 33 + .../sca/binding/feed/impl/FeedBindingImpl.java | 85 ++ .../binding/feed/module/FeedModuleActivator.java | 64 + .../binding/feed/provider/FeedBindingInvoker.java | 79 ++ .../binding/feed/provider/FeedBindingListener.java | 89 ++ .../feed/provider/FeedBindingProviderFactory.java | 57 + .../provider/FeedReferenceBindingProvider.java | 63 + .../feed/provider/FeedServiceBindingProvider.java | 77 ++ .../sca/binding/feed/xml/AtomBindingProcessor.java | 79 ++ .../sca/binding/feed/xml/RssBindingProcessor.java | 79 ++ .../org.apache.tuscany.sca.core.ModuleActivator | 18 + .../modules/binding-jsonrpc/DISCLAIMER | 8 + .../sca-java-0.91/modules/binding-jsonrpc/LICENSE | 205 +++ .../sca-java-0.91/modules/binding-jsonrpc/NOTICE | 6 + .../sca-java-0.91/modules/binding-jsonrpc/pom.xml | 103 ++ .../sca/binding/jsonrpc/JSONRPCBinding.java | 31 + .../binding/jsonrpc/JSONRPCBindingActivator.java | 52 + .../sca/binding/jsonrpc/JSONRPCService.java | 118 ++ .../sca/binding/jsonrpc/JSONRPCServiceServlet.java | 160 +++ .../tuscany/sca/binding/jsonrpc/JavaToSmd.java | 54 + .../binding/jsonrpc/ScaDomainScriptServlet.java | 113 ++ .../org.apache.tuscany.sca.spi.BindingActivator | 18 + .../apache/tuscany/sca/binding/jsonrpc/jsonrpc.js | 493 +++++++ .../apache/tuscany/sca/binding/jsonrpc/Echo.java | 29 + .../sca/binding/jsonrpc/EchoComponentImpl.java | 34 + .../binding/jsonrpc/JSONRPCServiceTestCase.java | 65 + .../src/test/resources/JSONRPCBinding.composite | 34 + .../sca-java-0.91/modules/binding-rmi/.ruleset | 190 +++ .../sca-java-0.91/modules/binding-rmi/DISCLAIMER | 8 + .../sca-java-0.91/modules/binding-rmi/LICENSE | 205 +++ .../sca-java-0.91/modules/binding-rmi/NOTICE | 6 + .../sca-java-0.91/modules/binding-rmi/pom.xml | 59 + .../apache/tuscany/sca/binding/rmi/RMIBinding.java | 73 ++ .../sca/binding/rmi/RMIBindingActivator.java | 51 + .../sca/binding/rmi/RMIReferenceInvoker.java | 74 ++ .../binding/rmi/RMIReferenceInvokerFactory.java | 59 + .../apache/tuscany/sca/binding/rmi/RMIService.java | 178 +++ .../org.apache.tuscany.sca.spi.BindingActivator | 18 + .../src/test/java/helloworld/HelloWorldImpl.java | 37 + .../test/java/helloworld/HelloWorldRmiImpl.java | 48 + .../test/java/helloworld/HelloWorldRmiService.java | 29 + .../test/java/helloworld/HelloWorldService.java | 29 + .../tuscany/sca/binding/rmi/BindingTestCase.java | 63 + .../test/resources/HelloWorldImpl.componentType | 23 + .../test/resources/HelloWorldRmiImpl.componentType | 27 + .../src/test/resources/RMIBindingTest.composite | 43 + .../modules/binding-ws-axis2/DISCLAIMER | 8 + .../sca-java-0.91/modules/binding-ws-axis2/LICENSE | 205 +++ .../sca-java-0.91/modules/binding-ws-axis2/NOTICE | 6 + .../sca-java-0.91/modules/binding-ws-axis2/pom.xml | 181 +++ .../binding-ws-axis2/src/main/assembly/axis2.xml | 306 +++++ .../binding/axis2/Axis2AsyncBindingInvoker.java | 74 ++ .../sca/binding/axis2/Axis2BindingInvoker.java | 146 +++ .../binding/axis2/Axis2BindingProviderFactory.java | 58 + .../axis2/Axis2CallbackInvocationHandler.java | 53 + .../sca/binding/axis2/Axis2ModuleActivator.java | 70 + .../binding/axis2/Axis2OneWayBindingInvoker.java | 58 + .../axis2/Axis2ReferenceBindingProvider.java | 267 ++++ .../sca/binding/axis2/Axis2ReferenceCallback.java | 54 + .../axis2/Axis2ReferenceCallbackTargetInvoker.java | 108 ++ .../binding/axis2/Axis2ServiceBindingProvider.java | 418 ++++++ .../axis2/Axis2ServiceCallbackTargetInvoker.java | 105 ++ .../axis2/Axis2ServiceInMessageReceiver.java | 65 + .../Axis2ServiceInOutAsyncMessageReceiver.java | 128 ++ .../Axis2ServiceInOutSyncMessageReceiver.java | 75 ++ .../sca/binding/axis2/Axis2ServiceServlet.java | 300 +++++ .../sca/binding/axis2/TuscanyAxisConfigurator.java | 44 + .../sca/binding/axis2/TuscanyDispatcher.java | 101 ++ .../sca/binding/axis2/TuscanyListingAgent.java | 334 +++++ .../org.apache.tuscany.sca.core.ModuleActivator | 18 + .../sca/binding/axis2/engine/config/axis2.xml | 411 ++++++ .../sca/binding/axis2/Axis2ReferenceTestCase.java | 83 ++ .../sca/binding/axis2/Axis2ServiceTestCase.java | 104 ++ .../apache/tuscany/sca/binding/axis2/Greeter.java | 31 + .../sca/binding/axis2/GreetingCallback.java | 24 + .../sca/binding/axis2/itests/HelloWorld.java | 29 + .../binding/axis2/itests/HelloWorldComponent.java | 33 + .../axis2/itests/HelloWorldMultiService.java | 51 + .../sca/binding/axis2/itests/HelloWorldOM.java | 30 + .../sca/binding/axis2/itests/HelloWorldOM2.java | 30 + .../axis2/itests/HelloWorldOMComponent.java | 34 + .../binding/axis2/itests/HelloWorldOMService.java | 40 + .../binding/axis2/itests/HelloWorldOMTestCase.java | 56 + .../binding/axis2/itests/HelloWorldService.java | 28 + .../axis2/itests/HelloWorldTestCaseFIXME.java | 44 + .../itests/QuestionMarkWSDLTestCaseFIXME.java | 100 ++ .../endpoints/AbstractHelloWorldOMTestCase.java | 62 + .../endpoints/DefaultMultiServiceTestCase.java | 24 + .../endpoints/DefaultSingleServiceTestCase.java | 24 + .../itests/endpoints/WSDLExplicitURITestCase.java | 24 + .../itests/endpoints/WSDLRelativeURITestCase.java | 24 + .../sca/binding/axis2/itests/HelloWorld.composite | 45 + .../itests/endpoints/DefaultMultiService.composite | 51 + .../endpoints/DefaultSingleService.composite | 51 + .../itests/endpoints/WSDLExplicitURI.composite | 49 + .../itests/endpoints/WSDLRelativeURI.composite | 49 + .../endpoints/helloworld-om-relative-uri.wsdl | 78 ++ .../binding/axis2/itests/helloworld-om-uri.wsdl | 78 ++ .../binding/axis2/itests/helloworld-om.composite | 44 + .../sca/binding/axis2/itests/helloworld-om.wsdl | 78 ++ .../sca/binding/axis2/itests/helloworld.wsdl | 80 ++ .../axis2/itests/questionmark-wsdl.composite | 38 + .../modules/binding-ws-xml/.checkstyle | 24 + .../sca-java-0.91/modules/binding-ws-xml/.pmd | 20 + .../sca-java-0.91/modules/binding-ws-xml/.ruleset | 190 +++ .../modules/binding-ws-xml/DISCLAIMER | 8 + .../sca-java-0.91/modules/binding-ws-xml/LICENSE | 205 +++ .../sca-java-0.91/modules/binding-ws-xml/NOTICE | 6 + .../sca-java-0.91/modules/binding-ws-xml/pom.xml | 61 + .../binding/ws/xml/WebServiceBindingProcessor.java | 334 +++++ .../sca/binding/ws/xml/WebServiceConstants.java | 35 + .../tuscany/sca/binding/ws/xml/ReadTestCase.java | 121 ++ .../tuscany/sca/binding/ws/xml/WriteTestCase.java | 112 ++ .../sca/binding/ws/xml/Calculator.composite | 58 + .../binding/ws/xml/CalculatorImpl.componentType | 40 + .../apache/tuscany/sca/binding/ws/xml/example.wsdl | 26 + .../sca/binding/ws/xml/invalid-stockquote.wsdl | 58 + .../org/apache/tuscany/sca/binding/ws/xml/ipo.xsd | 136 ++ .../tuscany/sca/binding/ws/xml/stockquote.wsdl | 58 + .../apache/tuscany/sca/binding/ws/xml/test1.wsdl | 45 + .../apache/tuscany/sca/binding/ws/xml/test1.xsd | 33 + .../apache/tuscany/sca/binding/ws/xml/test2.wsdl | 63 + .../sca/binding/ws/xml/unwrapped-stockquote.wsdl | 76 ++ .../sca-java-0.91/modules/binding-ws/.checkstyle | 24 + .../branches/sca-java-0.91/modules/binding-ws/.pmd | 20 + .../sca-java-0.91/modules/binding-ws/.ruleset | 190 +++ .../sca-java-0.91/modules/binding-ws/DISCLAIMER | 8 + .../sca-java-0.91/modules/binding-ws/LICENSE | 205 +++ .../sca-java-0.91/modules/binding-ws/NOTICE | 6 + .../sca-java-0.91/modules/binding-ws/pom.xml | 66 + .../ws/DefaultWebServiceBindingFactory.java | 30 + .../tuscany/sca/binding/ws/WebServiceBinding.java | 194 +++ .../sca/binding/ws/WebServiceBindingFactory.java | 35 + .../ws/impl/WebServiceBindingFactoryImpl.java | 35 + .../sca/binding/ws/impl/WebServiceBindingImpl.java | 242 ++++ .../sca-java-0.91/modules/commonj-api/DISCLAIMER | 8 + .../sca-java-0.91/modules/commonj-api/LICENSE | 205 +++ .../sca-java-0.91/modules/commonj-api/NOTICE | 6 + .../sca-java-0.91/modules/commonj-api/pom.xml | 46 + .../java/commonj/timers/CancelTimerListener.java | 38 + .../java/commonj/timers/StopTimerListener.java | 38 + .../src/main/java/commonj/timers/Timer.java | 41 + .../main/java/commonj/timers/TimerListener.java | 38 + .../src/main/java/commonj/timers/TimerManager.java | 79 ++ .../src/main/java/commonj/work/RemoteWorkItem.java | 39 + .../src/main/java/commonj/work/Work.java | 39 + .../java/commonj/work/WorkCompletedException.java | 73 ++ .../src/main/java/commonj/work/WorkEvent.java | 45 + .../src/main/java/commonj/work/WorkException.java | 50 + .../src/main/java/commonj/work/WorkItem.java | 39 + .../src/main/java/commonj/work/WorkListener.java | 44 + .../src/main/java/commonj/work/WorkManager.java | 51 + .../java/commonj/work/WorkRejectedException.java | 50 + .../modules/contribution-impl/.checkstyle | 25 + .../sca-java-0.91/modules/contribution-impl/.pmd | 20 + .../modules/contribution-impl/.ruleset | 190 +++ .../modules/contribution-impl/DISCLAIMER | 8 + .../modules/contribution-impl/LICENSE | 205 +++ .../sca-java-0.91/modules/contribution-impl/NOTICE | 6 + .../modules/contribution-impl/pom.xml | 45 + .../sca/contribution/impl/ArtifactImpl.java | 71 ++ .../contribution/impl/ContributionExportImpl.java | 52 + .../contribution/impl/ContributionFactoryImpl.java | 51 + .../sca/contribution/impl/ContributionImpl.java | 74 ++ .../contribution/impl/ContributionImportImpl.java | 61 + .../contribution/impl/DeployedArtifactImpl.java | 43 + .../impl/FolderContributionProcessor.java | 120 ++ .../impl/InvalidFolderContributionException.java | 41 + .../InvalidFolderContributionURIException.java | 41 + .../processor/impl/JarContributionProcessor.java | 94 ++ .../resolver/impl/ModelResolverImpl.java | 92 ++ .../service/impl/ArtifactTypeDescriberImpl.java | 106 ++ .../impl/ContributionMetadataLoaderImpl.java | 132 ++ .../service/impl/ContributionRepositoryImpl.java | 266 ++++ .../service/impl/ContributionServiceImpl.java | 340 +++++ .../impl/InvalidContributionMetadataException.java | 57 + .../impl/InvalidContributionURIException.java | 57 + .../service/impl/InvalidValueException.java | 46 + .../service/impl/PackageTypeDescriberImpl.java | 98 ++ .../sca/contribution/service/util/FileHelper.java | 704 ++++++++++ .../sca/contribution/service/util/IOHelper.java | 182 +++ ...FolderContributionPackageProcessorTestCase.java | 45 + .../JarContributionPackageProcessorTestCase.java | 52 + .../resolver/ArtifactResolverTestCase.java | 102 ++ .../services/ContentTypeDescriberImplTestCase.java | 53 + .../ContributionMetadataLoaderTestCase.java | 96 ++ .../services/ContributionRepositoryTestCase.java | 79 ++ .../services/PackageTypeDescriberImplTestCase.java | 52 + .../resources/deployables/sample-calculator.jar | Bin 0 -> 26901 bytes .../resources/repository/sample-calculator.jar | Bin 0 -> 29164 bytes .../src/test/resources/test.composite | 22 + .../contribution-impl/src/test/resources/test.ext | 0 .../sca-java-0.91/modules/contribution/.checkstyle | 24 + .../sca-java-0.91/modules/contribution/.pmd | 20 + .../sca-java-0.91/modules/contribution/.ruleset | 190 +++ .../sca-java-0.91/modules/contribution/DISCLAIMER | 8 + .../sca-java-0.91/modules/contribution/LICENSE | 205 +++ .../sca-java-0.91/modules/contribution/NOTICE | 6 + .../sca-java-0.91/modules/contribution/pom.xml | 44 + .../apache/tuscany/sca/contribution/Artifact.java | 57 + .../tuscany/sca/contribution/ContentType.java | 56 + .../tuscany/sca/contribution/Contribution.java | 91 ++ .../sca/contribution/ContributionExport.java | 61 + .../sca/contribution/ContributionFactory.java | 55 + .../sca/contribution/ContributionImport.java | 75 ++ .../tuscany/sca/contribution/DeployedArtifact.java | 43 + .../contribution/processor/ArtifactProcessor.java | 48 + .../processor/ArtifactProcessorExtensionPoint.java | 58 + .../processor/ContributionPostProcessor.java | 37 + .../ContributionPostProcessorExtensionPoint.java | 42 + .../DefaultArtifactProcessorExtensionPoint.java | 66 + .../DefaultPackageProcessorExtensionPoint.java | 51 + ...DefaultStAXArtifactProcessorExtensionPoint.java | 46 + .../DefaultURLArtifactProcessorExtensionPoint.java | 46 + .../processor/ExtensiblePackageProcessor.java | 76 ++ .../processor/ExtensibleStAXArtifactProcessor.java | 178 +++ .../processor/ExtensibleURLArtifactProcessor.java | 98 ++ .../contribution/processor/PackageProcessor.java | 67 + .../processor/PackageProcessorExtensionPoint.java | 50 + .../processor/StAXArtifactProcessor.java | 63 + .../StAXArtifactProcessorExtensionPoint.java | 29 + .../processor/URLArtifactProcessor.java | 52 + .../URLArtifactProcessorExtensionPoint.java | 29 + .../sca/contribution/resolver/ClassReference.java | 103 ++ .../sca/contribution/resolver/ModelResolver.java | 66 + .../service/AbstractContributionException.java | 124 ++ .../service/ContributionException.java | 55 + .../service/ContributionMetadataLoader.java | 42 + .../ContributionMetadataLoaderException.java | 54 + .../service/ContributionReadException.java | 94 ++ .../service/ContributionRepository.java | 93 ++ .../service/ContributionResolveException.java | 41 + .../service/ContributionRuntimeException.java | 44 + .../contribution/service/ContributionService.java | 104 ++ .../service/ContributionWireException.java | 42 + .../service/ContributionWriteException.java | 61 + .../service/InvalidConfigurationException.java | 33 + .../sca/contribution/service/TypeDescriber.java | 38 + .../service/UnrecognizedElementException.java | 48 + .../service/UnsupportedContentTypeException.java | 49 + .../modules/core-databinding/.checkstyle | 25 + .../sca-java-0.91/modules/core-databinding/.pmd | 20 + .../modules/core-databinding/.ruleset | 190 +++ .../modules/core-databinding/DISCLAIMER | 8 + .../sca-java-0.91/modules/core-databinding/LICENSE | 205 +++ .../sca-java-0.91/modules/core-databinding/NOTICE | 6 + .../sca-java-0.91/modules/core-databinding/pom.xml | 82 ++ .../module/DataBindingModuleActivator.java | 151 +++ .../DataBindingJavaInterfaceProcessor.java | 135 ++ .../Exception2ExceptionTransformer.java | 126 ++ .../transformers/Input2InputTransformer.java | 204 +++ .../transformers/Output2OutputTransformer.java | 185 +++ .../wire/DataBindingRuntimeWireProcessor.java | 150 +++ .../wire/DataTransformationInteceptor.java | 224 ++++ .../org.apache.tuscany.sca.core.ModuleActivator | 18 + .../DataBindingJavaInterfaceProcessorTestCase.java | 83 ++ .../transformers/IDLTransformerTestCase.java.fixme | 229 ++++ .../sca-java-0.91/modules/core-spi/.checkstyle | 24 + .../branches/sca-java-0.91/modules/core-spi/.pmd | 20 + .../sca-java-0.91/modules/core-spi/.ruleset | 190 +++ .../sca-java-0.91/modules/core-spi/DISCLAIMER | 8 + .../sca-java-0.91/modules/core-spi/LICENSE | 205 +++ .../branches/sca-java-0.91/modules/core-spi/NOTICE | 6 + .../sca-java-0.91/modules/core-spi/pom.xml | 111 ++ .../modules/core-spi/src/doc/Context Model.emx | 673 ++++++++++ .../sca/core/DefaultExtensionPointRegistry.java | 69 + .../core/DefaultModelFactoryExtensionPoint.java | 67 + .../tuscany/sca/core/ExtensionPointRegistry.java | 50 + .../sca/core/ModelFactoryExtensionPoint.java | 54 + .../apache/tuscany/sca/core/ModuleActivator.java | 68 + .../java/org/apache/tuscany/sca/event/Event.java | 33 + .../org/apache/tuscany/sca/event/EventFilter.java | 35 + .../apache/tuscany/sca/event/EventPublisher.java | 55 + .../tuscany/sca/event/RuntimeEventListener.java | 35 + .../org/apache/tuscany/sca/event/TrueFilter.java | 37 + .../apache/tuscany/sca/invocation/Interceptor.java | 40 + .../tuscany/sca/invocation/InvocationChain.java | 83 ++ .../org/apache/tuscany/sca/invocation/Invoker.java | 36 + .../org/apache/tuscany/sca/invocation/Message.java | 132 ++ .../tuscany/sca/invocation/MessageFactory.java | 36 + .../tuscany/sca/management/ManagementService.java | 39 + .../sca/provider/BindingProviderFactory.java | 60 + .../DefaultProviderFactoryExtensionPoint.java | 76 ++ .../sca/provider/ImplementationProvider.java | 68 + .../provider/ImplementationProviderFactory.java | 42 + .../tuscany/sca/provider/ProviderFactory.java | 36 + .../provider/ProviderFactoryExtensionPoint.java | 55 + .../sca/provider/ReferenceBindingProvider.java | 68 + .../sca/provider/ServiceBindingProvider.java | 52 + .../DefaultWireProcessorExtensionPoint.java | 63 + .../tuscany/sca/runtime/EndpointReference.java | 64 + .../tuscany/sca/runtime/RuntimeComponent.java | 45 + .../sca/runtime/RuntimeComponentReference.java | 80 ++ .../sca/runtime/RuntimeComponentService.java | 92 ++ .../apache/tuscany/sca/runtime/RuntimeWire.java | 66 + .../tuscany/sca/runtime/RuntimeWireProcessor.java | 35 + .../RuntimeWireProcessorExtensionPoint.java | 53 + .../sca/store/DuplicateRecordException.java | 45 + .../apache/tuscany/sca/store/RecoveryListener.java | 46 + .../java/org/apache/tuscany/sca/store/Store.java | 96 ++ .../apache/tuscany/sca/store/StoreException.java | 46 + .../tuscany/sca/store/StoreExpirationEvent.java | 71 ++ .../org/apache/tuscany/sca/store/StoreMonitor.java | 71 ++ .../tuscany/sca/store/StoreReadException.java | 45 + .../tuscany/sca/store/StoreWriteException.java | 45 + .../tuscany/sca/work/NotificationListener.java | 66 + .../org/apache/tuscany/sca/work/WorkScheduler.java | 52 + .../tuscany/sca/work/WorkSchedulerException.java | 47 + .../apache/tuscany/spi/util/stax/test.composite | 34 + .../sca-java-0.91/modules/core-spring/DISCLAIMER | 8 + .../sca-java-0.91/modules/core-spring/LICENSE | 205 +++ .../sca-java-0.91/modules/core-spring/NOTICE | 6 + .../sca-java-0.91/modules/core-spring/pom.xml | 94 ++ .../spring/assembly/impl/BeanAssemblyFactory.java | 135 ++ .../spring/assembly/impl/BeanComponentImpl.java | 211 +++ .../spring/assembly/impl/BeanReferenceImpl.java | 65 + .../sca/core/spring/context/ModelResolverImpl.java | 88 ++ .../sca/core/spring/context/SCADomainContext.java | 195 +++ .../java/impl/BeanBaseJavaImplementationImpl.java | 182 +++ .../java/impl/BeanJavaImplementationFactory.java | 43 + .../java/impl/BeanJavaImplementationImpl.java | 164 +++ .../java/impl/BeanJavaInterfaceContractImpl.java | 34 + .../java/impl/BeanJavaInterfaceFactory.java | 44 + .../java/impl/BeanJavaInterfaceImpl.java | 122 ++ .../src/test/java/calculator/AddService.java | 25 + .../src/test/java/calculator/AddServiceImpl.java | 35 + .../src/test/java/calculator/CalculatorClient.java | 41 + .../test/java/calculator/CalculatorService.java | 34 + .../java/calculator/CalculatorServiceImpl.java | 71 ++ .../src/test/java/calculator/DivideService.java | 25 + .../test/java/calculator/DivideServiceImpl.java | 33 + .../src/test/java/calculator/MultiplyService.java | 25 + .../test/java/calculator/MultiplyServiceImpl.java | 33 + .../java/calculator/NestedCalculatorClient.java | 44 + .../src/test/java/calculator/SubtractService.java | 25 + .../test/java/calculator/SubtractServiceImpl.java | 33 + .../sca/core/spring/CalculatorTestCase.java | 54 + .../sca/core/spring/NestedCalculatorTestCase.java | 57 + .../tuscany/sca/core/spring/Calculator.composite | 52 + .../sca/core/spring/InnerCalculator.composite | 42 + .../sca/core/spring/InnerOperations.composite | 57 + .../sca/core/spring/OuterCalculator.composite | 41 + .../sca-java-0.91/modules/core/.checkstyle | 24 + .../branches/sca-java-0.91/modules/core/.pmd | 20 + .../branches/sca-java-0.91/modules/core/.ruleset | 190 +++ .../branches/sca-java-0.91/modules/core/DISCLAIMER | 8 + .../branches/sca-java-0.91/modules/core/LICENSE | 205 +++ .../branches/sca-java-0.91/modules/core/NOTICE | 6 + .../branches/sca-java-0.91/modules/core/pom.xml | 64 + .../sca/core/component/CallableReferenceImpl.java | 59 + .../sca/core/component/CallbackReferenceImpl.java | 33 + .../sca/core/component/ComponentContextImpl.java | 93 ++ .../core/component/ComponentContextProvider.java | 44 + .../sca/core/component/RequestContextImpl.java | 54 + .../sca/core/component/ServiceReferenceImpl.java | 51 + .../tuscany/sca/core/event/BaseEventPublisher.java | 89 ++ .../tuscany/sca/core/event/ComponentStart.java | 54 + .../tuscany/sca/core/event/ComponentStop.java | 53 + .../tuscany/sca/core/event/ConversationEnd.java | 53 + .../tuscany/sca/core/event/ConversationStart.java | 52 + .../tuscany/sca/core/event/HttpSessionEnd.java | 53 + .../tuscany/sca/core/event/HttpSessionStart.java | 52 + .../apache/tuscany/sca/core/event/RequestEnd.java | 45 + .../tuscany/sca/core/event/RequestStart.java | 45 + .../core/invocation/AbstractInvocationHandler.java | 104 ++ .../invocation/CallbackInterfaceInterceptor.java | 57 + .../core/invocation/CallbackWireObjectFactory.java | 47 + .../core/invocation/ExtensibleWireProcessor.java | 44 + .../sca/core/invocation/InvocationChainImpl.java | 126 ++ .../invocation/JDKCallbackInvocationHandler.java | 95 ++ .../sca/core/invocation/JDKInvocationHandler.java | 115 ++ .../sca/core/invocation/JDKProxyService.java | 78 ++ .../sca/core/invocation/MessageFactoryImpl.java | 36 + .../tuscany/sca/core/invocation/MessageImpl.java | 117 ++ .../invocation/NoMethodForOperationException.java | 43 + .../core/invocation/NonBlockingInterceptor.java | 174 +++ .../core/invocation/ProxyCreationException.java | 48 + .../tuscany/sca/core/invocation/ProxyFactory.java | 61 + .../sca/core/invocation/ThreadMessageContext.java | 68 + .../sca/core/invocation/WireObjectFactory.java | 55 + .../sca/core/runtime/ActivationException.java | 37 + .../sca/core/runtime/CompositeActivator.java | 70 + .../sca/core/runtime/CompositeActivatorImpl.java | 655 ++++++++++ .../sca/core/runtime/EndpointReferenceImpl.java | 128 ++ .../sca/core/runtime/RuntimeAssemblyFactory.java | 61 + .../sca/core/runtime/RuntimeComponentImpl.java | 128 ++ .../runtime/RuntimeComponentReferenceImpl.java | 86 ++ .../core/runtime/RuntimeComponentServiceImpl.java | 109 ++ .../core/runtime/RuntimeSCABindingProvider.java | 55 + .../runtime/RuntimeSCABindingProviderFactory.java | 51 + .../tuscany/sca/core/runtime/RuntimeWireImpl.java | 66 + .../sca/core/scope/AbstractScopeContainer.java | 146 +++ .../sca/core/scope/CompositeScopeContainer.java | 70 + .../core/scope/CompositeScopeContainerFactory.java | 40 + .../core/scope/ConversationalScopeContainer.java | 182 +++ .../scope/ConversationalScopeContainerFactory.java | 47 + .../sca/core/scope/HttpSessionScopeContainer.java | 81 ++ .../scope/HttpSessionScopeContainerFactory.java | 44 + .../sca/core/scope/RequestScopeContainer.java | 85 ++ .../core/scope/RequestScopeContainerFactory.java | 40 + .../tuscany/sca/core/scope/ScopeRegistryImpl.java | 68 + .../sca/core/scope/StatelessScopeContainer.java | 54 + .../core/scope/StatelessScopeContainerFactory.java | 40 + .../apache/tuscany/sca/core/store/MemoryStore.java | 195 +++ .../org/apache/tuscany/sca/core/util/IOHelper.java | 182 +++ .../apache/tuscany/sca/core/work/Jsr237Work.java | 63 + .../tuscany/sca/core/work/Jsr237WorkScheduler.java | 167 +++ .../sca/core/work/ThreadPoolWorkManager.java | 220 ++++ .../tuscany/sca/core/work/WorkEventImpl.java | 74 ++ .../apache/tuscany/sca/core/work/WorkItemImpl.java | 166 +++ .../sca/factory/ObjectCreationException.java | 47 + .../apache/tuscany/sca/factory/ObjectFactory.java | 35 + .../sca/factory/SingletonObjectFactory.java | 38 + .../tuscany/sca/scope/AbstractLifecycle.java | 77 ++ .../tuscany/sca/scope/CoreRuntimeException.java | 45 + .../apache/tuscany/sca/scope/InstanceWrapper.java | 45 + .../org/apache/tuscany/sca/scope/Lifecycle.java | 69 + .../tuscany/sca/scope/PersistenceException.java | 43 + .../java/org/apache/tuscany/sca/scope/Scope.java | 63 + .../apache/tuscany/sca/scope/ScopeContainer.java | 93 ++ .../tuscany/sca/scope/ScopeContainerFactory.java | 32 + .../apache/tuscany/sca/scope/ScopeIdentifier.java | 35 + .../tuscany/sca/scope/ScopeNotFoundException.java | 31 + .../apache/tuscany/sca/scope/ScopeRegistry.java | 43 + .../sca/scope/ScopedImplementationProvider.java | 64 + .../tuscany/sca/scope/ScopedRuntimeComponent.java | 40 + .../sca/scope/TargetDestructionException.java | 44 + .../sca/scope/TargetInitializationException.java | 44 + .../sca/scope/TargetInvocationException.java | 45 + .../sca/scope/TargetInvokerCreationException.java | 44 + .../tuscany/sca/scope/TargetNotFoundException.java | 44 + .../sca/scope/TargetResolutionException.java | 44 + .../DefaultExtensionPointRegistryTestCase.java | 51 + .../sca/core/event/BaseEventPublisherTestCase.java | 98 ++ .../tuscany/sca/core/event/EventTestCase.java | 69 + .../sca/core/mock/component/AsyncTarget.java | 31 + .../sca/core/mock/component/BadContextPojo.java | 28 + .../sca/core/mock/component/BadNamePojo.java | 26 + .../sca/core/mock/component/BasicInterface.java | 30 + .../core/mock/component/BasicInterfaceImpl.java | 66 + .../mock/component/CompositeScopeComponent.java | 31 + .../component/CompositeScopeComponentImpl.java | 40 + .../CompositeScopeDestroyOnlyComponent.java | 36 + .../CompositeScopeInitDestroyComponent.java | 39 + .../component/CompositeScopeInitOnlyComponent.java | 42 + .../component/ConversationalScopeComponent.java | 29 + .../ConversationalScopeComponentImpl.java | 29 + .../ConversationalScopeDestroyOnlyComponent.java | 37 + .../ConversationalScopeInitDestroyComponent.java | 38 + .../ConversationalScopeInitOnlyComponent.java | 38 + .../sca/core/mock/component/OrderException.java | 40 + .../core/mock/component/OrderedDependentPojo.java | 29 + .../mock/component/OrderedDependentPojoImpl.java | 36 + .../core/mock/component/OrderedEagerInitPojo.java | 60 + .../sca/core/mock/component/OrderedInitPojo.java | 28 + .../core/mock/component/OrderedInitPojoImpl.java | 61 + .../sca/core/mock/component/OtherTarget.java | 31 + .../sca/core/mock/component/OtherTargetImpl.java | 39 + .../core/mock/component/RequestScopeComponent.java | 30 + .../RequestScopeDestroyOnlyComponent.java | 38 + .../RequestScopeInitDestroyComponent.java | 38 + .../component/RequestScopeInitOnlyComponent.java | 39 + .../core/mock/component/SessionScopeComponent.java | 30 + .../mock/component/SessionScopeComponentImpl.java | 30 + .../SessionScopeInitDestroyComponent.java | 36 + .../component/SessionScopeInitOnlyComponent.java | 37 + .../sca/core/mock/component/SimpleTarget.java | 30 + .../sca/core/mock/component/SimpleTargetImpl.java | 41 + .../tuscany/sca/core/mock/component/Source.java | 37 + .../sca/core/mock/component/SourceImpl.java | 63 + .../core/mock/component/StatelessComponent.java | 30 + .../mock/component/StatelessComponentImpl.java | 27 + .../tuscany/sca/core/mock/component/Target.java | 32 + .../sca/core/mock/component/TargetImpl.java | 38 + .../core/scope/AbstractScopeContainerTestCase.java | 70 + .../sca/core/store/MemoryStoreTestCase.java | 165 +++ .../wire/CallbackInterfaceInterceptorTestCase.java | 55 + .../sca/core/wire/InvocationChainImplTestCase.java | 66 + .../core/wire/NonBlockingInterceptorTestCase.java | 72 ++ .../tuscany/sca/factory/AssertionTestCase.java | 38 + .../factory/SingletonObjectFactoryTestCase.java | 33 + .../apache/tuscany/sca/scope/ScopeTestCase.java | 61 + .../modules/databinding-axiom/.ruleset | 191 +++ .../modules/databinding-axiom/DISCLAIMER | 8 + .../modules/databinding-axiom/LICENSE | 205 +++ .../sca-java-0.91/modules/databinding-axiom/NOTICE | 6 + .../modules/databinding-axiom/pom.xml | 91 ++ .../sca/databinding/axiom/AxiomDataBinding.java | 64 + .../databinding/axiom/AxiomExceptionHandler.java | 61 + .../tuscany/sca/databinding/axiom/AxiomHelper.java | 64 + .../sca/databinding/axiom/OMElement2Object.java | 37 + .../sca/databinding/axiom/OMElement2String.java | 59 + .../axiom/OMElement2XMLStreamReader.java | 47 + .../databinding/axiom/OMElementWrapperHandler.java | 70 + .../sca/databinding/axiom/Object2OMElement.java | 52 + .../sca/databinding/axiom/String2OMElement.java | 57 + .../axiom/XMLStreamReader2OMElement.java | 60 + .../module/AxiomDataBindingModuleActivator.java | 61 + .../org.apache.tuscany.sca.core.ModuleActivator | 18 + .../axiom/AxiomExceptionHandlerTestCase.java | 108 ++ .../sca/databinding/axiom/OMElementTestCase.java | 103 ++ .../databinding-axiom/src/test/resources/ipo.xml | 51 + .../databinding-axiom/src/test/resources/ipo.xsd | 137 ++ .../src/test/resources/order.wsdl | 76 ++ .../modules/databinding-jaxb/.ruleset | 191 +++ .../modules/databinding-jaxb/DISCLAIMER | 8 + .../sca-java-0.91/modules/databinding-jaxb/LICENSE | 205 +++ .../sca-java-0.91/modules/databinding-jaxb/NOTICE | 6 + .../sca-java-0.91/modules/databinding-jaxb/pom.xml | 147 +++ .../tuscany/sca/databinding/jaxb/JAXB2Node.java | 69 + .../sca/databinding/jaxb/JAXBContextHelper.java | 176 +++ .../sca/databinding/jaxb/JAXBDataBinding.java | 114 ++ .../sca/databinding/jaxb/JAXBExceptionHandler.java | 107 ++ .../sca/databinding/jaxb/JAXBWrapperHandler.java | 123 ++ .../jaxb/JAXWSJavaInterfaceProcessor.java | 101 ++ .../tuscany/sca/databinding/jaxb/Node2JAXB.java | 66 + .../tuscany/sca/databinding/jaxb/Reader2JAXB.java | 67 + .../sca/databinding/jaxb/XMLStreamReader2JAXB.java | 67 + .../module/JAXBDataBindingModuleActivator.java | 63 + .../org.apache.tuscany.sca.core.ModuleActivator | 18 + .../databinding/jaxb/JAXBDataBindingTestCase.java | 128 ++ .../jaxb/JAXBExceptionHandlerTestCase.java | 80 ++ .../tuscany/databinding/jaxb/JAXBTestCase.java | 160 +++ .../jaxb/JAXBWrapperHandlerTestCase.java | 71 ++ .../databinding/jaxb/fault/InvalidSymbolFault.java | 78 ++ .../jaxb/fault/InvalidSymbolFault_Exception.java | 63 + .../databinding-jaxb/src/test/resources/ipo.xsd | 136 ++ .../modules/databinding-sdo-axiom/.checkstyle | 25 + .../modules/databinding-sdo-axiom/.ruleset | 191 +++ .../modules/databinding-sdo-axiom/DISCLAIMER | 8 + .../modules/databinding-sdo-axiom/LICENSE | 205 +++ .../modules/databinding-sdo-axiom/NOTICE | 6 + .../modules/databinding-sdo-axiom/pom.xml | 131 ++ .../databinding/sdo2om/DataObject2OMElement.java | 88 ++ .../databinding/sdo2om/DataObjectSerializer.java | 427 +++++++ .../sca/databinding/sdo2om/SDODataSource.java | 85 ++ .../databinding/sdo2om/XMLDocument2OMElement.java | 61 + .../sdo2om/module/SDOAxiomModuleActivator.java | 48 + .../org.apache.tuscany.sca.core.ModuleActivator | 18 + .../sdo2om/DataObject2OMElementTestCase.java | 57 + .../sdo2om/SDOTransformerTestCaseBase.java | 79 ++ .../sdo2om/XMLDocument2OMElementTestCase.java | 62 + .../src/test/resources/ipo.xsd | 136 ++ .../src/test/resources/stock.xsd | 33 + .../modules/databinding-sdo/.checkstyle | 25 + .../sca-java-0.91/modules/databinding-sdo/.ruleset | 191 +++ .../modules/databinding-sdo/DISCLAIMER | 8 + .../sca-java-0.91/modules/databinding-sdo/LICENSE | 205 +++ .../sca-java-0.91/modules/databinding-sdo/NOTICE | 6 + .../sca-java-0.91/modules/databinding-sdo/pom.xml | 119 ++ .../sca/databinding/sdo/DataObject2String.java | 58 + .../sdo/DataObject2XMLStreamReader.java | 68 + .../sdo/DuplicateHelperContextException.java | 37 + .../databinding/sdo/HelperContextProcessor.java | 110 ++ .../sca/databinding/sdo/HelperContextRegistry.java | 52 + .../databinding/sdo/HelperContextRegistryImpl.java | 49 + .../tuscany/sca/databinding/sdo/ImportSDO.java | 78 ++ .../sca/databinding/sdo/ImportSDOProcessor.java | 193 +++ .../sca/databinding/sdo/SDOContextHelper.java | 106 ++ .../sca/databinding/sdo/SDODataBinding.java | 122 ++ .../sca/databinding/sdo/SDOExceptionHandler.java | 124 ++ .../sca/databinding/sdo/SDOSimpleTypeMapper.java | 67 + .../sca/databinding/sdo/SDOWrapperHandler.java | 99 ++ .../sca/databinding/sdo/String2DataObject.java | 55 + .../sca/databinding/sdo/XMLDocument2String.java | 59 + .../sdo/XMLDocument2XMLStreamReader.java | 64 + .../sdo/XMLStreamReader2DataObject.java | 64 + .../sdo/XMLStreamReader2XMLDocument.java | 59 + .../sca/databinding/sdo/api/HelperContext.java | 37 + .../sdo/module/SDODataBindingModuleActivator.java | 80 ++ .../org.apache.tuscany.sca.core.ModuleActivator | 18 + .../sdo/fault/InvalidSymbolFault_Exception.java | 67 + .../databinding/sdo/DataObject2StringTestCase.java | 64 + .../sdo/DataObject2XMLStreamReaderTestCase.java | 58 + .../sdo/HelperContextProcessorTestCase.java | 83 ++ .../sdo/ImportSDOProcessorTestCase.java | 85 ++ .../databinding/sdo/SDODataBindingTestCase.java | 110 ++ .../sdo/SDOExceptionHandlerTestCase.java | 82 ++ .../sdo/SDOTransformerTestCaseBase.java | 79 ++ .../databinding/sdo/SDOWrapperHandlerTestCase.java | 61 + .../sca/databinding/sdo/TestModelResolver.java | 63 + .../sdo/XMLDocument2XMLStreamReaderTestCase.java | 61 + .../databinding-sdo/src/test/resources/ipo.xsd | 136 ++ .../src/test/resources/model/sca-core.xsd | 233 ++++ .../resources/model/sca-implementation-mock.xsd | 43 + .../databinding-sdo/src/test/resources/stock.xsd | 33 + .../databinding-sdo/src/test/resources/wrapper.xml | 27 + .../databinding-sdo/src/test/resources/wrapper.xsd | 38 + .../sca-java-0.91/modules/databinding/.checkstyle | 25 + .../sca-java-0.91/modules/databinding/.pmd | 20 + .../sca-java-0.91/modules/databinding/.ruleset | 190 +++ .../sca-java-0.91/modules/databinding/DISCLAIMER | 8 + .../sca-java-0.91/modules/databinding/LICENSE | 205 +++ .../sca-java-0.91/modules/databinding/NOTICE | 6 + .../sca-java-0.91/modules/databinding/pom.xml | 51 + .../tuscany/sca/databinding/DataBinding.java | 99 ++ .../sca/databinding/DataBindingExtensionPoint.java | 71 ++ .../apache/tuscany/sca/databinding/DataPipe.java | 44 + .../DefaultDataBindingExtensionPoint.java | 116 ++ .../DefaultTransformerExtensionPoint.java | 90 ++ .../tuscany/sca/databinding/ExceptionHandler.java | 57 + .../apache/tuscany/sca/databinding/Mediator.java | 67 + .../tuscany/sca/databinding/PullTransformer.java | 36 + .../tuscany/sca/databinding/PushTransformer.java | 34 + .../tuscany/sca/databinding/SimpleTypeMapper.java | 44 + .../sca/databinding/TransformationContext.java | 79 ++ .../sca/databinding/TransformationException.java | 63 + .../tuscany/sca/databinding/Transformer.java | 49 + .../sca/databinding/TransformerExtensionPoint.java | 76 ++ .../tuscany/sca/databinding/WrapperHandler.java | 55 + .../sca/databinding/annotation/DataBinding.java | 44 + .../sca/databinding/impl/BaseDataBinding.java | 149 +++ .../sca/databinding/impl/BaseTransformer.java | 62 + .../tuscany/sca/databinding/impl/DOMHelper.java | 69 + .../sca/databinding/impl/DirectedGraph.java | 357 ++++++ .../databinding/impl/Group2GroupTransformer.java | 91 ++ .../sca/databinding/impl/GroupDataBinding.java | 96 ++ .../impl/Java2SimpleTypeTransformer.java | 60 + .../tuscany/sca/databinding/impl/MediatorImpl.java | 167 +++ .../sca/databinding/impl/PipedTransformer.java | 66 + .../impl/SimpleType2JavaTransformer.java | 63 + .../sca/databinding/impl/SimpleTypeMapperImpl.java | 392 ++++++ .../impl/TransformationContextImpl.java | 112 ++ .../sca/databinding/impl/XSDDataTypeConverter.java | 941 ++++++++++++++ .../javabeans/DOMNode2JavaBeanTransformer.java | 75 ++ .../javabeans/Java2XMLMapperException.java | 67 + .../javabeans/JavaBean2DOMNodeTransformer.java | 67 + .../javabeans/JavaBean2XMLStreamReader.java | 53 + .../javabeans/JavaBean2XMLTransformer.java | 226 ++++ .../javabeans/JavaBeansDataBinding.java | 104 ++ .../javabeans/XML2JavaBeanTransformer.java | 295 +++++ .../javabeans/XML2JavaMapperException.java | 74 ++ .../tuscany/sca/databinding/xml/BeanUtil.java | 196 +++ .../sca/databinding/xml/DOMDataBinding.java | 51 + .../sca/databinding/xml/DOMWrapperHandler.java | 78 ++ .../sca/databinding/xml/DOMXMLStreamReader.java | 129 ++ .../xml/DelegatingNamespaceContext.java | 310 +++++ .../sca/databinding/xml/InputSource2Node.java | 62 + .../sca/databinding/xml/InputSource2SAX.java | 60 + .../sca/databinding/xml/InputStream2Node.java | 64 + .../sca/databinding/xml/InputStream2SAX.java | 59 + .../xml/NameValueArrayStreamReader.java | 403 ++++++ .../databinding/xml/NameValuePairStreamReader.java | 347 +++++ .../tuscany/sca/databinding/xml/NamedProperty.java | 59 + .../databinding/xml/NilElementStreamReader.java | 279 ++++ .../sca/databinding/xml/Node2OutputStream.java | 63 + .../tuscany/sca/databinding/xml/Node2String.java | 57 + .../tuscany/sca/databinding/xml/Node2Writer.java | 62 + .../sca/databinding/xml/Node2XMLStreamReader.java | 56 + .../tuscany/sca/databinding/xml/Reader2Node.java | 62 + .../tuscany/sca/databinding/xml/Reader2SAX.java | 55 + .../tuscany/sca/databinding/xml/SAX2DOM.java | 244 ++++ .../tuscany/sca/databinding/xml/SAX2DOMPipe.java | 64 + .../databinding/xml/Source2ResultTransformer.java | 58 + .../sca/databinding/xml/StAX2SAXAdapter.java | 256 ++++ .../sca/databinding/xml/StAXDataBinding.java | 52 + .../tuscany/sca/databinding/xml/StAXHelper.java | 86 ++ .../sca/databinding/xml/StreamDataPipe.java | 54 + .../tuscany/sca/databinding/xml/String2Node.java | 57 + .../tuscany/sca/databinding/xml/String2SAX.java | 56 + .../databinding/xml/String2XMLStreamReader.java | 52 + .../databinding/xml/WrappingXMLStreamReader.java | 230 ++++ .../sca/databinding/xml/Writer2ReaderDataPipe.java | 53 + .../databinding/xml/XMLDocumentStreamReader.java | 451 +++++++ .../databinding/xml/XMLFragmentStreamReader.java | 53 + .../xml/XMLFragmentStreamReaderImpl.java | 857 +++++++++++++ .../sca/databinding/xml/XMLGroupDataBinding.java | 58 + .../sca/databinding/xml/XMLStreamReader2Node.java | 59 + .../sca/databinding/xml/XMLStreamReader2SAX.java | 70 + .../databinding/xml/XMLStreamReader2String.java | 52 + .../sca/databinding/xml/XMLStreamSerializer.java | 285 +++++ .../tuscany/sca/databinding/xml/XMLStreamable.java | 37 + .../sca/databinding/xml/XMLStringDataBinding.java | 51 + .../databinding/extension/DOMHelperTestCase.java | 56 + .../extension/DataBindingExtensionTestCase.java | 86 ++ .../SimpleTypeMapperExtensionTestCase.java | 120 ++ .../extension/TransformerExtensionTestCase.java | 75 ++ .../extension/XSDDataTypeConverterTestCase.java | 62 + .../impl/DataBindingRegistryImplTestCase.java | 100 ++ .../sca/databinding/impl/DataBindingTestCase.java | 45 + .../databinding/impl/DirectedGraphTestCase.java | 89 ++ .../sca/databinding/impl/MediatorImplTestCase.java | 119 ++ .../impl/TransformerRegistryImplTestCase.java | 107 ++ .../sca/databinding/xml/DOM2StAXTestCase.java | 89 ++ .../sca/databinding/xml/DataPipeTestCase.java | 89 ++ .../xml/JavaBean2XMLStreamReaderTestCase.java | 133 ++ .../sca/databinding/xml/Node2StringTestCase.java | 35 + .../xml/PushTransformationTestCase.java | 81 ++ .../sca/databinding/xml/StAXHelperTestCase.java | 47 + .../databinding/xml/TraxTransformerTestCase.java | 99 ++ .../apache/tuscany/sca/databinding/impl/ipo.xsd | 136 ++ .../apache/tuscany/sca/databinding/impl/order.wsdl | 76 ++ .../org/apache/tuscany/sca/databinding/xml/foo.xml | 22 + .../modules/extension-helper/DISCLAIMER | 8 + .../sca-java-0.91/modules/extension-helper/LICENSE | 205 +++ .../sca-java-0.91/modules/extension-helper/NOTICE | 6 + .../sca-java-0.91/modules/extension-helper/pom.xml | 69 + .../apache/tuscany/sca/spi/BindingActivator.java | 67 + .../apache/tuscany/sca/spi/ComponentLifecycle.java | 28 + .../tuscany/sca/spi/ImplementationActivator.java | 62 + .../org/apache/tuscany/sca/spi/InvokerFactory.java | 29 + .../tuscany/sca/spi/impl/BindingSCDLProcessor.java | 155 +++ .../tuscany/sca/spi/impl/BindingsActivator.java | 250 ++++ .../tuscany/sca/spi/impl/DiscoveryUtils.java | 134 ++ .../impl/ImplementationImplementationProvider.java | 91 ++ .../sca/spi/impl/ImplementationsActivator.java | 138 ++ .../apache/tuscany/sca/spi/impl/PojoBinding.java | 36 + .../tuscany/sca/spi/impl/PojoImplementation.java | 42 + .../apache/tuscany/sca/spi/impl/SCDLProcessor.java | 241 ++++ .../tuscany/sca/spi/utils/AbstractBinding.java | 77 ++ .../sca/spi/utils/AbstractImplementation.java | 127 ++ .../spi/utils/AbstractStAXArtifactProcessor.java | 114 ++ .../utils/DefaultPropertyValueObjectFactory.java | 229 ++++ .../sca/spi/utils/DynamicImplementation.java | 92 ++ .../sca/spi/utils/PropertyValueObjectFactory.java | 29 + .../tuscany/sca/spi/utils/ResourceHelper.java | 70 + .../org.apache.tuscany.sca.core.ModuleActivator | 20 + .../modules/host-embedded/.checkstyle | 24 + .../sca-java-0.91/modules/host-embedded/.pmd | 21 + .../sca-java-0.91/modules/host-embedded/.ruleset | 190 +++ .../sca-java-0.91/modules/host-embedded/DISCLAIMER | 8 + .../sca-java-0.91/modules/host-embedded/LICENSE | 205 +++ .../sca-java-0.91/modules/host-embedded/NOTICE | 6 + .../sca-java-0.91/modules/host-embedded/pom.xml | 72 ++ .../tuscany/sca/host/embedded/SCADomain.java | 267 ++++ .../tuscany/sca/host/embedded/SCADomainBean.java | 111 ++ .../sca/host/embedded/SCATestCaseRunner.java | 213 ++++ .../sca/host/embedded/impl/DefaultSCADomain.java | 351 +++++ .../sca/host/embedded/impl/EmbeddedSCADomain.java | 287 +++++ .../sca/host/embedded/impl/ReallySmallRuntime.java | 178 +++ .../embedded/impl/ReallySmallRuntimeBuilder.java | 281 ++++ .../host-embedded/src/test/java/crud/CRUD.java | 56 + .../src/test/java/crud/CRUDImplementation.java | 51 + .../test/java/crud/CRUDImplementationFactory.java | 36 + .../crud/DefaultCRUDImplementationFactory.java | 51 + .../test/java/crud/backend/ResourceManager.java | 92 ++ .../java/crud/impl/CRUDImplementationImpl.java | 138 ++ .../crud/impl/CRUDImplementationProcessor.java | 97 ++ .../test/java/crud/module/CRUDModuleActivator.java | 79 ++ .../crud/provider/CRUDImplementationProvider.java | 73 ++ .../CRUDImplementationProviderFactory.java | 48 + .../src/test/java/crud/provider/CRUDInvoker.java | 79 ++ .../sca/host/embedded/SCADomainBeanTestCase.java | 62 + .../sca/host/embedded/SCADomainTestCase.java | 61 + .../embedded/impl/DefaultSCADomainTestCase.java | 51 + .../embedded/impl/EmbeddedSCADomainTestCase.java | 114 ++ .../sca/host/embedded/impl/TestModelResolver.java | 104 ++ .../org.apache.tuscany.sca.core.ModuleActivator | 18 + .../src/test/resources/crud.composite | 30 + .../host-embedded/src/test/resources/test.txt | 16 + .../sca-java-0.91/modules/host-http/DISCLAIMER | 8 + .../sca-java-0.91/modules/host-http/LICENSE | 205 +++ .../sca-java-0.91/modules/host-http/NOTICE | 6 + .../sca-java-0.91/modules/host-http/pom.xml | 46 + .../tuscany/sca/http/DefaultResourceServlet.java | 85 ++ .../sca/http/DefaultServletHostExtensionPoint.java | 45 + .../tuscany/sca/http/ExtensibleServletHost.java | 53 + .../org/apache/tuscany/sca/http/ServletHost.java | 53 + .../sca/http/ServletHostExtensionPoint.java | 51 + .../tuscany/sca/http/ServletMappingException.java | 44 + .../http/module/HTTPRuntimeModuleActivator.java | 46 + .../org.apache.tuscany.sca.core.ModuleActivator | 18 + .../sca-java-0.91/modules/host-rmi/DISCLAIMER | 8 + .../sca-java-0.91/modules/host-rmi/LICENSE | 205 +++ .../branches/sca-java-0.91/modules/host-rmi/NOTICE | 6 + .../sca-java-0.91/modules/host-rmi/pom.xml | 38 + .../org/apache/tuscany/sca/rmi/DefaultRMIHost.java | 129 ++ .../java/org/apache/tuscany/sca/rmi/RMIHost.java | 88 ++ .../apache/tuscany/sca/rmi/RMIHostException.java | 45 + .../tuscany/sca/rmi/RMIHostRuntimeException.java | 45 + .../sca/rmi/module/RMIRuntimeModuleActivator.java | 43 + .../org.apache.tuscany.sca.core.ModuleActivator | 18 + .../tuscany/sca/rmi/RMIHostImplTestCase.java | 73 ++ .../sca-java-0.91/modules/host-webapp/DISCLAIMER | 8 + .../sca-java-0.91/modules/host-webapp/LICENSE | 205 +++ .../sca-java-0.91/modules/host-webapp/NOTICE | 6 + .../sca-java-0.91/modules/host-webapp/pom.xml | 53 + .../apache/tuscany/sca/webapp/SCADomainHelper.java | 68 + .../tuscany/sca/webapp/TuscanyContextListener.java | 51 + .../apache/tuscany/sca/webapp/TuscanyServlet.java | 63 + .../tuscany/sca/webapp/WebAppModuleActivator.java | 46 + .../tuscany/sca/webapp/WebAppServletHost.java | 100 ++ .../org.apache.tuscany.sca.core.ModuleActivator | 18 + .../sca-java-0.91/modules/http-jetty/.ruleset | 190 +++ .../sca-java-0.91/modules/http-jetty/DISCLAIMER | 8 + .../sca-java-0.91/modules/http-jetty/LICENSE | 205 +++ .../sca-java-0.91/modules/http-jetty/NOTICE | 6 + .../sca-java-0.91/modules/http-jetty/pom.xml | 57 + .../sca/http/jetty/JettyDefaultServlet.java | 62 + .../apache/tuscany/sca/http/jetty/JettyLogger.java | 87 ++ .../apache/tuscany/sca/http/jetty/JettyServer.java | 299 +++++ .../jetty/module/JettyRuntimeModuleActivator.java | 54 + .../org.apache.tuscany.sca.core.ModuleActivator | 18 + .../sca/http/jetty/JettyServerTestCase.java | 254 ++++ .../src/test/resources/content/test.html | 21 + .../sca-java-0.91/modules/http-tomcat/.ruleset | 190 +++ .../sca-java-0.91/modules/http-tomcat/DISCLAIMER | 8 + .../sca-java-0.91/modules/http-tomcat/LICENSE | 205 +++ .../sca-java-0.91/modules/http-tomcat/NOTICE | 6 + .../sca-java-0.91/modules/http-tomcat/pom.xml | 83 ++ .../tuscany/sca/http/tomcat/ServletWrapper.java | 56 + .../sca/http/tomcat/TomcatDefaultServlet.java | 70 + .../tuscany/sca/http/tomcat/TomcatServer.java | 249 ++++ .../module/TomcatRuntimeModuleActivator.java | 54 + .../org.apache.tuscany.sca.core.ModuleActivator | 18 + .../sca/http/tomcat/TomcatServerTestCase.java | 254 ++++ .../src/test/resources/content/test.html | 21 + .../implementation-java-runtime/.checkstyle | 24 + .../modules/implementation-java-runtime/.pmd | 20 + .../modules/implementation-java-runtime/.ruleset | 190 +++ .../modules/implementation-java-runtime/DISCLAIMER | 8 + .../modules/implementation-java-runtime/LICENSE | 205 +++ .../modules/implementation-java-runtime/NOTICE | 6 + .../modules/implementation-java-runtime/pom.xml | 68 + .../java/context/InstanceFactory.java | 43 + .../java/context/InstanceFactoryProvider.java | 49 + .../context/JavaPropertyValueObjectFactory.java | 204 +++ .../java/context/ReflectiveInstanceFactory.java | 86 ++ .../java/context/ReflectiveInstanceWrapper.java | 56 + .../context/TargetMethodNotFoundException.java | 45 + .../injection/ArrayMultiplicityObjectFactory.java | 54 + .../java/injection/ContextInjector.java | 32 + .../injection/ConversationIDObjectFactory.java | 32 + .../java/injection/EventInvoker.java | 34 + .../java/injection/FieldInjector.java | 57 + .../java/injection/InjectionRuntimeException.java | 45 + .../implementation/java/injection/Injector.java | 35 + .../java/injection/InvalidAccessorException.java | 42 + .../injection/InvalidResourceTypeException.java | 46 + .../java/injection/JNDIObjectFactory.java | 50 + .../injection/ListMultiplicityObjectFactory.java | 50 + .../java/injection/MethodEventInvoker.java | 55 + .../java/injection/MethodInjector.java | 55 + .../java/injection/NoAccessorException.java | 39 + .../injection/NoMultiplicityTypeException.java | 42 + .../java/injection/ObjectCallbackException.java | 44 + .../java/injection/PojoObjectFactory.java | 120 ++ .../injection/RequestContextObjectFactory.java | 40 + .../java/injection/ResourceHost.java | 46 + .../java/injection/ResourceNotFoundException.java | 46 + .../java/injection/ResourceObjectFactory.java | 87 ++ .../injection/ResourceResolutionException.java | 43 + .../java/injection/SingletonObjectFactory.java | 39 + .../InvalidConversationSequenceException.java | 45 + .../java/invocation/JavaComponentInfo.java | 415 ++++++ .../invocation/JavaImplementationProvider.java | 174 +++ .../JavaImplementationProviderFactory.java | 56 + .../java/invocation/JavaTargetInvoker.java | 159 +++ .../NoConversationalContractException.java | 34 + .../java/invocation/PassByValueInvoker.java | 117 ++ .../invocation/PojoComponentContextFactory.java | 40 + .../java/invocation/PojoConfiguration.java | 218 ++++ .../java/invocation/TargetInvoker.java | 69 + .../java/invocation/TargetInvokerInvoker.java | 49 + .../java/module/JavaRuntimeModuleActivator.java | 136 ++ .../java/monitor/ExceptionFormatter.java | 34 + .../java/monitor/ExceptionFormatterImpl.java | 43 + .../java/monitor/FormatterRegistry.java | 42 + .../java/monitor/InvalidLevelException.java | 64 + .../java/monitor/JavaLoggingMonitorFactory.java | 118 ++ .../java/monitor/MonitorFactory.java | 51 + .../java/monitor/MonitorFactoryUtil.java | 77 ++ .../java/monitor/NullMonitorFactory.java | 66 + .../java/monitor/ProxyMonitorFactory.java | 231 ++++ .../org.apache.tuscany.sca.core.ModuleActivator | 18 + .../implementation/java/context/ModelHelper.java | 99 ++ .../java/context/MultiplicityTestCase.java | 34 + .../context/ReflectiveInstanceWrapperTestCase.java | 83 ++ .../CallbackWireObjectFactoryTestCase.java | 54 + .../java/injection/FieldInjectorTestCase.java | 48 + .../java/injection/JNDIObjectFactoryTestCase.java | 61 + .../java/injection/MethodEventInvokerTestCase.java | 72 ++ .../java/injection/MethodInjectorTestCase.java | 79 ++ .../java/injection/PojoObjectFactoryTestCase.java | 76 ++ .../RequestContextObjectFactoryTestCase.java | 33 + .../injection/ResourceObjectFactoryTestCase.java | 89 ++ .../injection/SingletonObjectFactoryTestCase.java | 33 + .../integration/AbstractConversationTestCase.java | 51 + .../ConversationIdleExpireTestCase.java.FIXME | 149 +++ .../ConversationMaxAgeExpireTestCase.java.FIXME | 153 +++ .../ConversationStartStopEndTestCase.java.FIXME | 147 +++ .../ReferenceInjectionTestCase.java.FIXME | 79 ++ .../sca/implementation/java/mock/AsyncTarget.java | 31 + .../implementation/java/mock/BadContextPojo.java | 28 + .../sca/implementation/java/mock/BadNamePojo.java | 26 + .../implementation/java/mock/BasicInterface.java | 30 + .../java/mock/BasicInterfaceImpl.java | 66 + .../java/mock/CompositeScopeComponent.java | 31 + .../java/mock/CompositeScopeComponentImpl.java | 40 + .../mock/CompositeScopeDestroyOnlyComponent.java | 36 + .../mock/CompositeScopeInitDestroyComponent.java | 39 + .../java/mock/CompositeScopeInitOnlyComponent.java | 42 + .../java/mock/ConversationalScopeComponent.java | 29 + .../mock/ConversationalScopeComponentImpl.java | 29 + .../ConversationalScopeDestroyOnlyComponent.java | 37 + .../ConversationalScopeInitDestroyComponent.java | 38 + .../mock/ConversationalScopeInitOnlyComponent.java | 38 + .../java/mock/MockFactory.java.FIXME | 214 ++++ .../java/mock/MockStaticInvoker.java | 94 ++ .../java/mock/MockSyncInterceptor.java | 52 + .../implementation/java/mock/OrderException.java | 40 + .../java/mock/OrderedDependentPojo.java | 29 + .../java/mock/OrderedDependentPojoImpl.java | 36 + .../java/mock/OrderedEagerInitPojo.java | 60 + .../implementation/java/mock/OrderedInitPojo.java | 28 + .../java/mock/OrderedInitPojoImpl.java | 61 + .../sca/implementation/java/mock/OtherTarget.java | 31 + .../implementation/java/mock/OtherTargetImpl.java | 39 + .../java/mock/RequestScopeComponent.java | 30 + .../mock/RequestScopeDestroyOnlyComponent.java | 38 + .../mock/RequestScopeInitDestroyComponent.java | 38 + .../java/mock/RequestScopeInitOnlyComponent.java | 39 + .../java/mock/SessionScopeComponent.java | 30 + .../java/mock/SessionScopeComponentImpl.java | 30 + .../mock/SessionScopeInitDestroyComponent.java | 36 + .../java/mock/SessionScopeInitOnlyComponent.java | 37 + .../sca/implementation/java/mock/SimpleTarget.java | 30 + .../implementation/java/mock/SimpleTargetImpl.java | 41 + .../sca/implementation/java/mock/Source.java | 37 + .../sca/implementation/java/mock/SourceImpl.java | 63 + .../java/mock/StatelessComponent.java | 30 + .../java/mock/StatelessComponentImpl.java | 27 + .../sca/implementation/java/mock/Target.java | 32 + .../sca/implementation/java/mock/TargetImpl.java | 38 + .../java/monitor/ExceptionFormatterTestCase.java | 57 + .../java/monitor/JavaLoggingTestCase.java | 152 +++ .../sca/implementation/java/util/Bean1.java | 45 + .../sca/implementation/java/util/Bean2.java | 47 + .../java/util/JavaIntrospectionHelperTestCase.java | 182 +++ .../sca/implementation/java/util/SuperBean.java | 48 + .../modules/implementation-java-xml/.checkstyle | 24 + .../modules/implementation-java-xml/.pmd | 20 + .../modules/implementation-java-xml/.ruleset | 190 +++ .../modules/implementation-java-xml/DISCLAIMER | 8 + .../modules/implementation-java-xml/LICENSE | 205 +++ .../modules/implementation-java-xml/NOTICE | 6 + .../modules/implementation-java-xml/pom.xml | 57 + .../apache/tuscany/api/annotation/LogLevel.java | 41 + .../org/apache/tuscany/api/annotation/Monitor.java | 34 + .../apache/tuscany/api/annotation/Resource.java | 49 + ...DefaultJavaClassIntrospectorExtensionPoint.java | 48 + .../introspect/DuplicatePropertyException.java | 32 + .../ExtensibleJavaClassIntrospector.java | 126 ++ .../java/introspect/IllegalPropertyException.java | 38 + .../java/introspect/IntrospectionException.java | 60 + .../java/introspect/JavaClassIntrospector.java | 42 + .../JavaClassIntrospectorExtensionPoint.java | 49 + .../java/introspect/JavaClassVisitor.java | 125 ++ .../introspect/impl/AbstractPropertyProcessor.java | 167 +++ .../impl/AllowsPassByReferenceProcessor.java | 50 + .../impl/AmbiguousConstructorException.java | 40 + .../java/introspect/impl/BaseJavaClassVisitor.java | 64 + .../java/introspect/impl/ConstructorProcessor.java | 81 ++ .../java/introspect/impl/ContextProcessor.java | 80 ++ .../introspect/impl/ConversationProcessor.java | 136 ++ .../java/introspect/impl/DestroyProcessor.java | 57 + .../impl/DuplicateConstructorException.java | 41 + .../impl/DuplicateDestructorException.java | 35 + .../introspect/impl/DuplicateInitException.java | 35 + .../impl/DuplicateReferenceException.java | 35 + .../impl/DuplicateResourceException.java | 36 + .../java/introspect/impl/EagerInitProcessor.java | 56 + .../introspect/impl/HeuristicPojoProcessor.java | 658 ++++++++++ .../impl/IllegalCallbackReferenceException.java | 40 + .../introspect/impl/IllegalContextException.java | 40 + .../impl/IllegalDestructorException.java | 40 + .../java/introspect/impl/IllegalInitException.java | 40 + .../introspect/impl/IllegalReferenceException.java | 40 + .../introspect/impl/IllegalResourceException.java | 40 + .../impl/IllegalServiceDefinitionException.java | 35 + .../java/introspect/impl/InitProcessor.java | 57 + .../impl/InvalidConstructorException.java | 36 + .../impl/InvalidConversationalImplementation.java | 39 + .../introspect/impl/InvalidPropertyException.java | 35 + .../introspect/impl/InvalidReferenceException.java | 42 + .../introspect/impl/InvalidResourceException.java | 40 + .../java/introspect/impl/InvalidServiceType.java | 48 + .../introspect/impl/JavaIntrospectionHelper.java | 448 +++++++ .../introspect/impl/NoConstructorException.java | 37 + .../java/introspect/impl/PolicyProcessor.java | 164 +++ .../java/introspect/impl/PropertyProcessor.java | 44 + .../java/introspect/impl/ReferenceProcessor.java | 171 +++ .../java/introspect/impl/ResourceProcessor.java | 134 ++ .../java/introspect/impl/ScopeProcessor.java | 60 + .../java/introspect/impl/ServiceProcessor.java | 159 +++ .../impl/ServiceTypeNotFoundException.java | 35 + .../impl/UnknownContextTypeException.java | 33 + .../java/xml/JavaImplementationConstants.java | 31 + .../java/xml/JavaImplementationProcessor.java | 188 +++ .../src/test/java/calculator/AddService.java | 25 + .../src/test/java/calculator/AddServiceImpl.java | 35 + .../test/java/calculator/CalculatorService.java | 34 + .../java/calculator/CalculatorServiceImpl.java | 71 ++ .../src/test/java/calculator/DivideService.java | 25 + .../test/java/calculator/DivideServiceImpl.java | 33 + .../src/test/java/calculator/MultiplyService.java | 25 + .../test/java/calculator/MultiplyServiceImpl.java | 33 + .../src/test/java/calculator/SubtractService.java | 25 + .../test/java/calculator/SubtractServiceImpl.java | 33 + .../DefaultJavaClassIntrospectorTestCase.java | 95 ++ .../introspect/impl/AbstractProcessorTest.java | 80 ++ .../impl/AbstractPropertyProcessorTestCase.java | 168 +++ .../AllowsPassByReferenceProcessorTestCase.java | 70 + .../impl/ConstructorProcessorTestCase.java | 197 +++ .../impl/ConstructorPropertyTestCase.java | 158 +++ .../impl/ConstructorReferenceTestCase.java | 166 +++ .../impl/ConstructorResourceTestCase.java | 153 +++ .../introspect/impl/ContextProcessorTestCase.java | 188 +++ .../impl/ConversationProcessorTestCase.java | 144 +++ .../introspect/impl/ConvertTimeMillisTestCase.java | 116 ++ .../introspect/impl/DestroyProcessorTestCase.java | 99 ++ .../impl/EagerInitProcessorTestCase.java | 59 + .../impl/HeuristicAndPropertyTestCase.java | 75 ++ .../impl/HeuristicConstructorTestCase.java | 315 +++++ .../impl/HeuristicPojoProcessorTestCase.java | 411 ++++++ .../HeutisticExtensibleConstructorTestCase.java | 153 +++ .../introspect/impl/InitProcessorTestCase.java | 99 ++ .../java/introspect/impl/ModelHelper.java | 99 ++ .../introspect/impl/PolicyProcessorTestCase.java | 406 ++++++ .../introspect/impl/PropertyProcessorTestCase.java | 213 ++++ .../impl/ReferenceProcessorTestCase.java | 224 ++++ .../introspect/impl/ResourceProcessorTestCase.java | 118 ++ .../introspect/impl/ScopeProcessorTestCase.java | 116 ++ .../introspect/impl/ServiceCallbackTestCase.java | 169 +++ .../introspect/impl/ServiceProcessorTestCase.java | 152 +++ .../sca/implementation/java/xml/ReadTestCase.java | 120 ++ .../implementation/java/xml/TestModelResolver.java | 88 ++ .../sca/implementation/java/xml/WriteTestCase.java | 97 ++ .../implementation/java/xml/Calculator.composite | 53 + .../modules/implementation-java/.checkstyle | 24 + .../sca-java-0.91/modules/implementation-java/.pmd | 21 + .../modules/implementation-java/.ruleset | 190 +++ .../modules/implementation-java/DISCLAIMER | 8 + .../modules/implementation-java/LICENSE | 205 +++ .../modules/implementation-java/NOTICE | 6 + .../modules/implementation-java/pom.xml | 38 + .../java/BaseJavaImplementation.java | 58 + .../java/DefaultJavaImplementationFactory.java | 31 + .../implementation/java/JavaImplementation.java | 186 +++ .../java/JavaImplementationFactory.java | 35 + .../java/impl/BaseJavaImplementationImpl.java | 84 ++ .../java/impl/JavaConstructorImpl.java | 53 + .../implementation/java/impl/JavaElementImpl.java | 223 ++++ .../java/impl/JavaImplementationFactoryImpl.java | 34 + .../java/impl/JavaImplementationImpl.java | 156 +++ .../java/impl/JavaParameterImpl.java | 35 + .../implementation/java/impl/JavaResourceImpl.java | 85 ++ .../implementation/java/impl/JavaScopeImpl.java | 63 + .../modules/implementation-resource/DISCLAIMER | 8 + .../modules/implementation-resource/LICENSE | 205 +++ .../modules/implementation-resource/NOTICE | 6 + .../modules/implementation-resource/pom.xml | 87 ++ .../DefaultHTTPResourceBindingFactory.java | 33 + .../sca/binding/resource/HTTPResourceBinding.java | 28 + .../resource/HTTPResourceBindingFactory.java | 33 + .../resource/impl/HTTPResourceBindingImpl.java | 77 ++ .../impl/HTTPResourceBindingProcessor.java | 73 ++ .../HTTPResourceBindingProviderFactory.java | 54 + .../HTTPResourceServiceBindingProvider.java | 96 ++ .../DefaultResourceImplementationFactory.java | 53 + .../sca/implementation/resource/Resource.java | 38 + .../resource/ResourceImplementation.java | 58 + .../resource/ResourceImplementationFactory.java | 34 + .../resource/impl/ResourceImplementationImpl.java | 154 +++ .../impl/ResourceImplementationProcessor.java | 111 ++ .../ResourceImplementationModuleActivator.java | 91 ++ .../provider/ResourceImplementationProvider.java | 57 + .../ResourceImplementationProviderFactory.java | 44 + .../resource/provider/ResourceInvoker.java | 43 + .../org.apache.tuscany.sca.core.ModuleActivator | 19 + .../resource/ResourceImplementationTestCase.java | 105 ++ .../src/test/resources/content/test.html | 21 + .../src/test/resources/resource.composite | 40 + .../modules/implementation-script/DISCLAIMER | 8 + .../modules/implementation-script/LICENSE | 251 ++++ .../modules/implementation-script/NOTICE | 17 + .../modules/implementation-script/pom.xml | 152 +++ .../script/ScriptImplementation.java | 70 + .../script/ScriptImplementationActivator.java | 45 + .../sca/implementation/script/ScriptInvoker.java | 71 ++ .../script/ScriptInvokerFactory.java | 124 ++ .../script/engines/TuscanyJRubyScriptEngine.java | 445 +++++++ ....apache.tuscany.sca.spi.ImplementationActivator | 18 + .../script/itests/AbstractSCATestCase.java | 48 + .../itests/dynamic/AbstractHelloWorldTestCase.java | 34 + .../script/itests/dynamic/HelloWorld.java | 27 + .../dynamic/JavaScriptDynamicRefTestCase.java | 25 + .../dynamic/JavaScriptHelloWorldTestCase.java | 30 + .../helloworld/AbstractHelloWorldTestCase.java | 34 + .../helloworld/GroovyHelloWorldTestCase.java | 25 + .../script/itests/helloworld/HelloWorld.java | 26 + .../script/itests/helloworld/HelloWorldProxy.java | 33 + .../itests/helloworld/JRubyHelloWorldTestCase.java | 25 + .../JavaScripInlineHelloWorldTestCase.java | 25 + .../helloworld/JavaScriptHelloWorldTestCase.java | 25 + .../helloworld/JythonHelloWorldTestCase.java | 25 + .../properties/AbstractHelloWorldTestCase.java | 34 + .../properties/GroovyHelloWorldTestCase.java | 25 + .../script/itests/properties/HelloWorld.java | 26 + .../script/itests/properties/HelloWorldProxy.java | 33 + .../itests/properties/JRubyHelloWorldTestCase.java | 24 + .../properties/JavaScriptHelloWorldTestCase.java | 25 + .../properties/JythonHelloWorldTestCase.java | 25 + .../itests/references/GroovyReferenceTestCase.java | 25 + .../script/itests/references/HelloWorldTarget.java | 30 + .../itests/references/JRubyReferenceTestCase.java | 25 + .../references/JavaScriptReferenceTestCase.java | 25 + .../itests/references/JythonReferenceTestCase.java | 25 + .../itests/dynamic/JavaScriptDynamicRef.composite | 34 + .../itests/dynamic/JavaScriptHelloWorld.composite | 29 + .../script/itests/dynamic/helloworld.js | 26 + .../script/itests/dynamic/helloworldProxy.js | 22 + .../itests/helloworld/GroovyHelloWorld.composite | 32 + .../itests/helloworld/JRubyHelloWorld.composite | 32 + .../helloworld/JavaScripInlineHelloWorld.composite | 33 + .../helloworld/JavaScriptHelloWorld.composite | 32 + .../itests/helloworld/JythonHelloWorld.composite | 32 + .../itests/helloworld/helloworld.componentType | 30 + .../script/itests/helloworld/helloworld.groovy | 22 + .../script/itests/helloworld/helloworld.js | 23 + .../script/itests/helloworld/helloworld.py | 20 + .../script/itests/helloworld/helloworld.rb | 21 + .../itests/properties/GroovyHelloWorld.composite | 32 + .../itests/properties/JRubyHelloWorld.composite | 32 + .../properties/JavaScriptHelloWorld.composite | 32 + .../itests/properties/JythonHelloWorld.composite | 32 + .../itests/properties/helloworld.componentType | 32 + .../script/itests/properties/helloworld.groovy | 22 + .../script/itests/properties/helloworld.js | 23 + .../script/itests/properties/helloworld.py | 20 + .../script/itests/properties/helloworld.rb | 21 + .../itests/references/GroovyReference.composite | 37 + .../itests/references/JRubyReference.composite | 37 + .../references/JavaScriptReference.composite | 37 + .../itests/references/JythonReference.composite | 37 + .../itests/references/reference.componentType | 31 + .../script/itests/references/reference.groovy | 22 + .../script/itests/references/reference.js | 22 + .../script/itests/references/reference.py | 20 + .../script/itests/references/reference.rb | 21 + .../modules/implementation-spring/.ruleset | 190 +++ .../modules/implementation-spring/DISCLAIMER | 8 + .../modules/implementation-spring/LICENSE | 205 +++ .../modules/implementation-spring/NOTICE | 6 + .../modules/implementation-spring/pom.xml | 109 ++ .../spring/SCAApplicationContext.java | 50 + .../spring/SCANamespaceHandlerResolver.java | 51 + .../spring/SCAParentApplicationContext.java | 283 +++++ .../implementation/spring/ScaNamespaceHandler.java | 39 + .../spring/ScaPropertyBeanDefinitionParser.java | 37 + .../spring/ScaReferenceBeanDefinitionParser.java | 38 + .../spring/ScaServiceBeanDefinitionParser.java | 38 + .../spring/SpringArtifactProcessor.java | 205 +++ .../spring/SpringBeanNotFoundException.java | 29 + .../spring/SpringImplementation.java | 146 +++ .../spring/SpringImplementationProvider.java | 98 ++ .../SpringImplementationProviderFactory.java | 67 + .../spring/SpringInvocationException.java | 29 + .../implementation/spring/SpringInvoker.java | 131 ++ .../spring/SpringModuleActivator.java | 131 ++ .../spring/SpringOperationNotFoundException.java | 30 + .../spring/SpringPropertyValueObjectFactory.java | 46 + .../spring/xml/SpringBeanElement.java | 60 + .../spring/xml/SpringBeanIntrospector.java | 156 +++ .../spring/xml/SpringPropertyElement.java | 46 + .../spring/xml/SpringSCAPropertyElement.java | 45 + .../spring/xml/SpringSCAReferenceElement.java | 47 + .../spring/xml/SpringSCAServiceElement.java | 53 + .../spring/xml/SpringXMLComponentTypeLoader.java | 575 +++++++++ .../org.apache.tuscany.sca.core.ModuleActivator | 18 + .../src/main/resources/META-INF/spring.handlers | 3 + .../src/main/resources/META-INF/spring.schemas | 1 + .../org/springframework/sca/xml/spring-sca.xsd | 101 ++ .../spring/itests/AbstractSCATestCase.java | 49 + .../helloworld/AbstractHelloWorldTestCase.java | 42 + .../spring/itests/helloworld/HelloWorld.java | 35 + .../spring/itests/helloworld/HelloWorldImpl.java | 38 + .../spring/itests/helloworld/HelloWorldProxy.java | 42 + .../SpringExplicitHelloWorldTestCase.java | 34 + .../SpringExplicitReferenceTestCase.java | 39 + .../helloworld/SpringHelloWorldTestCase.java | 32 + .../SpringImplicitReferenceTestCase.java | 42 + .../helloworld/SpringSCAPropertyTestCase.java | 39 + .../spring/itests/mock/TestBean.java | 31 + .../spring/itests/mock/TestBeanImpl.java | 42 + .../spring/itests/mock/TestHelloWorldBean.java | 40 + .../spring/itests/mock/TestReference.java | 27 + .../spring/itests/mock/TestReferenceBean.java | 57 + .../spring/itests/mock/TestSCAPropertyBean.java | 55 + .../sca/SpringExplicitHelloWorld-context.xml | 39 + .../sca/SpringExplicitReference-context.xml | 33 + .../META-INF/sca/SpringHelloWorld-context.xml | 31 + .../sca/SpringImplicitReference-context.xml | 34 + .../META-INF/sca/SpringSCAProperty-context.xml | 34 + .../META-INF/sca/testReferenceContext.xml | 33 + .../resources/META-INF/sca/testServiceContext.xml | 31 + .../helloworld/SpringExplicitHelloWorld.composite | 32 + .../helloworld/SpringExplicitReference.composite | 32 + .../itests/helloworld/SpringHelloWorld.composite | 32 + .../helloworld/SpringImplicitReference.composite | 39 + .../itests/helloworld/SpringSCAProperty.composite | 39 + .../src/test/resources/test.xml | 29 + .../modules/interface-java-runtime/DISCLAIMER | 8 + .../modules/interface-java-runtime/LICENSE | 205 +++ .../modules/interface-java-runtime/NOTICE | 6 + .../modules/interface-java-runtime/pom.xml | 43 + .../JavaInterfaceRuntimeModuleActivator.java | 63 + .../org.apache.tuscany.sca.core.ModuleActivator | 18 + .../modules/interface-java-xml/.checkstyle | 24 + .../sca-java-0.91/modules/interface-java-xml/.pmd | 20 + .../modules/interface-java-xml/.ruleset | 190 +++ .../modules/interface-java-xml/DISCLAIMER | 8 + .../modules/interface-java-xml/LICENSE | 205 +++ .../modules/interface-java-xml/NOTICE | 6 + .../modules/interface-java-xml/pom.xml | 56 + ...ultJavaInterfaceIntrospectorExtensionPoint.java | 47 + .../ExtensibleJavaInterfaceIntrospector.java | 147 +++ .../java/introspect/JavaInterfaceIntrospector.java | 39 + .../JavaInterfaceIntrospectorExtensionPoint.java | 50 + .../java/introspect/JavaInterfaceVisitor.java | 39 + .../sca/interfacedef/java/xml/JavaConstants.java | 32 + .../java/xml/JavaInterfaceProcessor.java | 157 +++ .../impl/ConversationalIntrospectionTestCase.java | 103 ++ ...JavaInterfaceProcessorRegistryImplTestCase.java | 102 ++ .../sca/interfacedef/java/xml/ReadTestCase.java | 126 ++ .../sca/interfacedef/java/xml/WriteTestCase.java | 117 ++ .../sca/interfacedef/java/xml/Calculator.composite | 53 + .../java/xml/CalculatorComponent.constrainingType | 34 + .../java/xml/CalculatorImpl.componentType | 31 + .../modules/interface-java/.checkstyle | 24 + .../sca-java-0.91/modules/interface-java/.pmd | 20 + .../sca-java-0.91/modules/interface-java/.ruleset | 190 +++ .../modules/interface-java/DISCLAIMER | 8 + .../sca-java-0.91/modules/interface-java/LICENSE | 205 +++ .../sca-java-0.91/modules/interface-java/NOTICE | 6 + .../sca-java-0.91/modules/interface-java/pom.xml | 39 + .../java/DefaultJavaInterfaceFactory.java | 31 + .../sca/interfacedef/java/JavaInterface.java | 71 ++ .../interfacedef/java/JavaInterfaceContract.java | 32 + .../interfacedef/java/JavaInterfaceFactory.java | 42 + .../java/impl/JavaInterfaceContractImpl.java | 34 + .../java/impl/JavaInterfaceFactoryImpl.java | 38 + .../interfacedef/java/impl/JavaInterfaceImpl.java | 94 ++ .../interfacedef/java/impl/JavaInterfaceUtil.java | 129 ++ .../java/impl/JavaInterfaceUtilTestCase.java | 114 ++ .../modules/interface-wsdl-runtime/DISCLAIMER | 8 + .../modules/interface-wsdl-runtime/LICENSE | 205 +++ .../modules/interface-wsdl-runtime/NOTICE | 6 + .../modules/interface-wsdl-runtime/pom.xml | 43 + .../WSDLInterfaceRuntimeModuleActivator.java | 59 + .../org.apache.tuscany.sca.core.ModuleActivator | 18 + .../modules/interface-wsdl-xml/.checkstyle | 24 + .../sca-java-0.91/modules/interface-wsdl-xml/.pmd | 20 + .../modules/interface-wsdl-xml/.ruleset | 190 +++ .../modules/interface-wsdl-xml/DISCLAIMER | 8 + .../modules/interface-wsdl-xml/LICENSE | 205 +++ .../modules/interface-wsdl-xml/NOTICE | 6 + .../modules/interface-wsdl-xml/pom.xml | 50 + .../DefaultWSDLInterfaceIntrospector.java | 66 + .../wsdl/introspect/InvalidWSDLException.java | 35 + .../wsdl/introspect/WSDLInterfaceIntrospector.java | 43 + .../wsdl/introspect/WSDLOperation.java | 556 ++++++++ .../sca/interfacedef/wsdl/xml/WSDLConstants.java | 35 + .../wsdl/xml/WSDLDocumentProcessor.java | 190 +++ .../wsdl/xml/WSDLInterfaceProcessor.java | 195 +++ .../wsdl/xml/XSDDocumentProcessor.java | 103 ++ .../DefaultWSDLInterfaceIntrospectorTestCase.java | 85 ++ .../wsdl/introspect/TestModelResolver.java | 63 + .../wsdl/introspect/WSDLOperationTestCase.java | 124 ++ .../introspect/WrapperStyleOperationTestCase.java | 81 ++ .../sca/interfacedef/wsdl/xml/ReadTestCase.java | 118 ++ .../sca/interfacedef/wsdl/xml/WSDLTestCase.java | 67 + .../sca/interfacedef/wsdl/xml/WriteTestCase.java | 108 ++ .../sca/interfacedef/wsdl/xml/Calculator.composite | 55 + .../wsdl/xml/CalculatorComponent.constrainingType | 36 + .../wsdl/xml/CalculatorImpl.componentType | 33 + .../tuscany/sca/interfacedef/wsdl/xml/example.wsdl | 26 + .../interfacedef/wsdl/xml/invalid-stockquote.wsdl | 58 + .../tuscany/sca/interfacedef/wsdl/xml/ipo.xsd | 136 ++ .../sca/interfacedef/wsdl/xml/stockquote.wsdl | 58 + .../tuscany/sca/interfacedef/wsdl/xml/test1.wsdl | 45 + .../tuscany/sca/interfacedef/wsdl/xml/test1.xsd | 33 + .../tuscany/sca/interfacedef/wsdl/xml/test2.wsdl | 63 + .../wsdl/xml/unwrapped-stockquote.wsdl | 76 ++ .../modules/interface-wsdl/.checkstyle | 24 + .../sca-java-0.91/modules/interface-wsdl/.pmd | 20 + .../sca-java-0.91/modules/interface-wsdl/.ruleset | 190 +++ .../modules/interface-wsdl/DISCLAIMER | 8 + .../sca-java-0.91/modules/interface-wsdl/LICENSE | 205 +++ .../sca-java-0.91/modules/interface-wsdl/NOTICE | 6 + .../sca-java-0.91/modules/interface-wsdl/pom.xml | 66 + .../sca/interfacedef/wsdl/DefaultWSDLFactory.java | 30 + .../sca/interfacedef/wsdl/WSDLDefinition.java | 78 ++ .../tuscany/sca/interfacedef/wsdl/WSDLFactory.java | 56 + .../sca/interfacedef/wsdl/WSDLInterface.java | 66 + .../interfacedef/wsdl/WSDLInterfaceContract.java | 43 + .../sca/interfacedef/wsdl/XSDefinition.java | 69 + .../interfacedef/wsdl/impl/WSDLDefinitionImpl.java | 99 ++ .../interfacedef/wsdl/impl/WSDLFactoryImpl.java | 50 + .../wsdl/impl/WSDLInterfaceContractImpl.java | 42 + .../interfacedef/wsdl/impl/WSDLInterfaceImpl.java | 93 ++ .../interfacedef/wsdl/impl/XSDefinitionImpl.java | 92 ++ .../sca-java-0.91/modules/interface/.checkstyle | 24 + .../branches/sca-java-0.91/modules/interface/.pmd | 20 + .../sca-java-0.91/modules/interface/.ruleset | 190 +++ .../sca-java-0.91/modules/interface/DISCLAIMER | 8 + .../sca-java-0.91/modules/interface/LICENSE | 205 +++ .../sca-java-0.91/modules/interface/NOTICE | 6 + .../sca-java-0.91/modules/interface/pom.xml | 31 + .../sca/interfacedef/ConversationSequence.java | 24 + .../apache/tuscany/sca/interfacedef/DataType.java | 89 ++ .../IncompatibleInterfaceContractException.java | 69 + .../apache/tuscany/sca/interfacedef/Interface.java | 93 ++ .../sca/interfacedef/InterfaceContract.java | 66 + .../sca/interfacedef/InterfaceContractMapper.java | 115 ++ .../sca/interfacedef/InvalidCallbackException.java | 34 + .../interfacedef/InvalidInterfaceException.java | 40 + .../interfacedef/InvalidOperationException.java | 42 + .../apache/tuscany/sca/interfacedef/Operation.java | 173 +++ .../interfacedef/OverloadedOperationException.java | 42 + .../sca/interfacedef/impl/DataTypeImpl.java | 188 +++ .../interfacedef/impl/InterfaceContractImpl.java | 51 + .../impl/InterfaceContractMapperImpl.java | 276 ++++ .../sca/interfacedef/impl/InterfaceImpl.java | 164 +++ .../sca/interfacedef/impl/OperationImpl.java | 294 +++++ .../tuscany/sca/interfacedef/util/ElementInfo.java | 60 + .../sca/interfacedef/util/FaultException.java | 82 ++ .../sca/interfacedef/util/JavaXMLMapper.java | 115 ++ .../tuscany/sca/interfacedef/util/TypeInfo.java | 72 ++ .../tuscany/sca/interfacedef/util/WrapperInfo.java | 140 ++ .../tuscany/sca/interfacedef/util/XMLType.java | 124 ++ .../impl/ContractCompatibilityTestCase.java | 366 ++++++ .../sca-java-0.91/modules/java2wsdl/DISCLAIMER | 8 + .../sca-java-0.91/modules/java2wsdl/LICENSE | 205 +++ .../sca-java-0.91/modules/java2wsdl/NOTICE | 6 + .../sca-java-0.91/modules/java2wsdl/pom.xml | 198 +++ .../java2wsdl/generate/GenerationParameters.java | 435 +++++++ .../tools/java2wsdl/generate/Java2WSDL.java | 81 ++ .../java2wsdl/generate/Java2WSDLGenerator.java | 46 + .../generate/Java2WSDLGeneratorFactory.java | 89 ++ .../java2wsdl/generate/Java2WSDLGeneratorImpl.java | 235 ++++ .../tools/java2wsdl/generate/SchemaBuilder.java | 524 ++++++++ .../java2wsdl/generate/TuscanyJava2OMBuilder.java | 521 ++++++++ .../generate/TuscanyJava2WSDLBuilder.java | 81 ++ .../generate/TuscanyJava2WSDLConstants.java | 51 + .../generate/TuscanyJava2WSDLOptionsValidator.java | 74 ++ .../java2wsdl/generate/TuscanySchemaGenerator.java | 410 ++++++ .../tools/java2wsdl/generate/TuscanyTypeTable.java | 225 ++++ .../generate/TuscanyWSDLTypesGenerator.java | 373 ++++++ .../tools/java2wsdl/generate/WSDLGenEvent.java | 38 + .../tools/java2wsdl/generate/WSDLGenListener.java | 39 + .../tuscany/tools/java2wsdl/util/XMLNameUtil.java | 143 +++ .../src/main/resources/META-INF/LICENSE.txt | 202 +++ .../src/main/resources/META-INF/README.txt | 35 + .../main/resources/RemotableInterfaceTemplate.xsl | 116 ++ .../tools/java2wsdl/generate/CustomerValue.java | 43 + .../java2wsdl/generate/CustomerWithAccount.java | 49 + .../generate/TuscanyJava2WSDLTestCase.java | 108 ++ .../tools/java2wsdl/generate/account/Account.java | 53 + .../java2wsdl/generate/customer/Customer.java | 30 + .../java2wsdl/generate/extra/GoldCustomer.java | 36 + .../java/org/soapinterop/CreditScoreDocLit.java | 25 + .../src/test/resources/AccountService.wsdl | 242 ++++ .../src/test/resources/CreditScoreDocLit.wsdl | 76 ++ .../java2wsdl/src/test/resources/helloworld.wsdl | 121 ++ .../java2wsdl/src/test/resources/interopdoc.wsdl | 180 +++ .../java2wsdl/src/test/resources/sequences.xsd | 100 ++ .../modules/maven-java2wsdl/DISCLAIMER | 8 + .../sca-java-0.91/modules/maven-java2wsdl/LICENSE | 205 +++ .../sca-java-0.91/modules/maven-java2wsdl/NOTICE | 6 + .../sca-java-0.91/modules/maven-java2wsdl/pom.xml | 45 + .../java2wsdl/plugin/Java2WSDLGeneratorMojo.java | 153 +++ .../modules/maven-wsdl2java/DISCLAIMER | 8 + .../sca-java-0.91/modules/maven-wsdl2java/LICENSE | 205 +++ .../sca-java-0.91/modules/maven-wsdl2java/NOTICE | 6 + .../sca-java-0.91/modules/maven-wsdl2java/pom.xml | 45 + .../wsdl2java/plugin/WSDL2JavaGeneratorMojo.java | 152 +++ .../tools/wsdl2java/plugin/WSDLFileOption.java | 92 ++ .../sca-java-0.91/modules/policy/DISCLAIMER | 8 + .../branches/sca-java-0.91/modules/policy/LICENSE | 205 +++ .../branches/sca-java-0.91/modules/policy/NOTICE | 6 + .../branches/sca-java-0.91/modules/policy/pom.xml | 38 + .../tuscany/sca/policy/DefaultPolicyFactory.java | 30 + .../java/org/apache/tuscany/sca/policy/Intent.java | 104 ++ .../tuscany/sca/policy/IntentAttachPoint.java | 37 + .../org/apache/tuscany/sca/policy/IntentMap.java | 87 ++ .../apache/tuscany/sca/policy/PolicyFactory.java | 47 + .../org/apache/tuscany/sca/policy/PolicySet.java | 100 ++ .../tuscany/sca/policy/PolicySetAttachPoint.java | 37 + .../apache/tuscany/sca/policy/impl/IntentImpl.java | 86 ++ .../tuscany/sca/policy/impl/IntentMapImpl.java | 73 ++ .../tuscany/sca/policy/impl/PolicyFactoryImpl.java | 45 + .../tuscany/sca/policy/impl/PolicySetImpl.java | 83 ++ .../tuscany/sca/policy/PolicyFactoryTestCase.java | 53 + .../branches/sca-java-0.91/modules/pom.xml | 109 ++ .../sca-java-0.91/modules/sca-api/DISCLAIMER | 8 + .../branches/sca-java-0.91/modules/sca-api/LICENSE | 205 +++ .../branches/sca-java-0.91/modules/sca-api/NOTICE | 6 + .../branches/sca-java-0.91/modules/sca-api/pom.xml | 59 + .../main/java/org/osoa/sca/CallableReference.java | 65 + .../main/java/org/osoa/sca/ComponentContext.java | 109 ++ .../src/main/java/org/osoa/sca/Constants.java | 34 + .../src/main/java/org/osoa/sca/Conversation.java | 41 + .../org/osoa/sca/ConversationEndedException.java | 67 + .../osoa/sca/NoRegisteredCallbackException.java | 68 + .../src/main/java/org/osoa/sca/RequestContext.java | 66 + .../main/java/org/osoa/sca/ServiceReference.java | 65 + .../java/org/osoa/sca/ServiceRuntimeException.java | 69 + .../org/osoa/sca/ServiceUnavailableException.java | 65 + .../sca/annotations/AllowsPassByReference.java | 39 + .../org/osoa/sca/annotations/Authentication.java | 69 + .../java/org/osoa/sca/annotations/Callback.java | 50 + .../org/osoa/sca/annotations/ComponentName.java | 36 + .../org/osoa/sca/annotations/Confidentiality.java | 69 + .../java/org/osoa/sca/annotations/Constructor.java | 36 + .../java/org/osoa/sca/annotations/Context.java | 39 + .../sca/annotations/ConversationAttributes.java | 57 + .../org/osoa/sca/annotations/ConversationID.java | 36 + .../org/osoa/sca/annotations/Conversational.java | 38 + .../java/org/osoa/sca/annotations/Destroy.java | 36 + .../java/org/osoa/sca/annotations/EagerInit.java | 36 + .../org/osoa/sca/annotations/EndsConversation.java | 35 + .../main/java/org/osoa/sca/annotations/Init.java | 37 + .../java/org/osoa/sca/annotations/Integrity.java | 69 + .../main/java/org/osoa/sca/annotations/Intent.java | 59 + .../main/java/org/osoa/sca/annotations/OneWay.java | 36 + .../java/org/osoa/sca/annotations/PolicySets.java | 46 + .../java/org/osoa/sca/annotations/Property.java | 52 + .../java/org/osoa/sca/annotations/Qualifier.java | 36 + .../java/org/osoa/sca/annotations/Reference.java | 51 + .../java/org/osoa/sca/annotations/Remotable.java | 37 + .../java/org/osoa/sca/annotations/Requires.java | 57 + .../main/java/org/osoa/sca/annotations/Scope.java | 49 + .../java/org/osoa/sca/annotations/Service.java | 48 + .../sca-java-0.91/modules/wsdl2java/DISCLAIMER | 8 + .../sca-java-0.91/modules/wsdl2java/LICENSE | 205 +++ .../sca-java-0.91/modules/wsdl2java/NOTICE | 6 + .../sca-java-0.91/modules/wsdl2java/pom.xml | 198 +++ .../wsdl2java/generate/JavaInterfaceEmitter.java | 224 ++++ .../wsdl2java/generate/JavaInterfaceGenerator.java | 235 ++++ .../generate/RemotableInterfaceWritter.java | 53 + .../generate/SDODataBindingCodegenExtension.java | 62 + .../generate/SDODataBindingTypeMappingEntry.java | 51 + .../wsdl2java/generate/WSDL2JavaGenerator.java | 349 +++++ .../tuscany/tools/wsdl2java/util/XMLNameUtil.java | 143 +++ .../src/main/resources/META-INF/LICENSE.txt | 202 +++ .../src/main/resources/META-INF/README.txt | 35 + .../main/resources/RemotableInterfaceTemplate.xsl | 116 ++ .../generate/WSDL2JavaGeneratorTestCase.java | 44 + .../java/org/soapinterop/CreditScoreDocLit.java | 25 + .../src/test/resources/AccountService.wsdl | 242 ++++ .../src/test/resources/CreditScoreDocLit.wsdl | 76 ++ .../wsdl2java/src/test/resources/helloworld.wsdl | 121 ++ .../wsdl2java/src/test/resources/interopdoc.wsdl | 180 +++ .../wsdl2java/src/test/resources/sequences.xsd | 100 ++ 1643 files changed, 138092 insertions(+) create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly-java-dsl/DISCLAIMER create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly-java-dsl/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly-java-dsl/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly-java-dsl/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly-java-dsl/src/main/java/org/apache/tuscany/sca/assembly/dsl/AssemblyBuilder.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly-java-dsl/src/main/java/org/apache/tuscany/sca/assembly/dsl/ComponentBuilder.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly-java-dsl/src/main/java/org/apache/tuscany/sca/assembly/dsl/ComponentPropertyBuilder.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly-java-dsl/src/main/java/org/apache/tuscany/sca/assembly/dsl/ComponentReferenceBuilder.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly-java-dsl/src/main/java/org/apache/tuscany/sca/assembly/dsl/ComponentServiceBuilder.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly-java-dsl/src/main/java/org/apache/tuscany/sca/assembly/dsl/CompositeBuilder.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly-java-dsl/src/main/java/org/apache/tuscany/sca/assembly/dsl/impl/AssemblyBuilderImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly-java-dsl/src/main/java/org/apache/tuscany/sca/assembly/dsl/impl/ComponentBuilderImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly-java-dsl/src/main/java/org/apache/tuscany/sca/assembly/dsl/impl/ComponentPropertyBuilderImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly-java-dsl/src/main/java/org/apache/tuscany/sca/assembly/dsl/impl/ComponentReferenceBuilderImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly-java-dsl/src/main/java/org/apache/tuscany/sca/assembly/dsl/impl/ComponentServiceBuilderImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly-java-dsl/src/main/java/org/apache/tuscany/sca/assembly/dsl/impl/CompositeBuilderImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly-java-dsl/src/test/java/org/apache/tuscany/sca/assembly/dsl/AccountDataService.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly-java-dsl/src/test/java/org/apache/tuscany/sca/assembly/dsl/AccountDataServiceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly-java-dsl/src/test/java/org/apache/tuscany/sca/assembly/dsl/AccountService.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly-java-dsl/src/test/java/org/apache/tuscany/sca/assembly/dsl/AccountServiceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly-java-dsl/src/test/java/org/apache/tuscany/sca/assembly/dsl/BigBankBuilder.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly-java-dsl/src/test/java/org/apache/tuscany/sca/assembly/dsl/BigBankBuilderTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly-java-dsl/src/test/java/org/apache/tuscany/sca/assembly/dsl/StockQuoteService.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/.checkstyle create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/.pmd create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/.ruleset create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/DISCLAIMER create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/BaseArtifactProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ComponentTypeDocumentProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ComponentTypeProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeDocumentProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/Constants.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConstrainingTypeDocumentProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConstrainingTypeProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/XAttr.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadAllTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadDocumentTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ResolveTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/StAXPerfTest.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestModelResolver.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/WireTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/WriteAllTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/Calculator.composite create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/CalculatorComponent.constrainingType create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/CalculatorImpl.componentType create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/TestAllCalculator.composite create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/TestAllDivide.composite create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly/.checkstyle create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly/.pmd create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly/.ruleset create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly/DISCLAIMER create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/AbstractContract.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/AbstractProperty.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/AbstractReference.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/AbstractService.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/AssemblyFactory.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Base.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Binding.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Callback.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Component.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ComponentProperty.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ComponentReference.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ComponentService.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ComponentType.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Composite.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/CompositeReference.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/CompositeService.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ConstrainingType.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Contract.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/DefaultAssemblyFactory.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/DefaultSCABindingFactory.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Implementation.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Multiplicity.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Property.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Reference.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/SCABinding.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/SCABindingFactory.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Service.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Visitable.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Visitor.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Wire.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/ComponentPreProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/CompositeBuilder.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/CompositeBuilderException.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/CompositeBuilderMonitor.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/Problem.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBuilderImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ProblemImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/PropertyUtil.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ReferenceUtil.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/AbstractPropertyImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/AbstractReferenceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/AbstractServiceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/AssemblyFactoryImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/BaseImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/CallbackImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentPropertyImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentReferenceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentServiceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentTypeImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/CompositeImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/CompositeReferenceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/CompositeServiceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ConstrainingTypeImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ContractImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/PropertyImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ReferenceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/SCABindingFactoryImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/SCABindingImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ServiceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/WireImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/util/PrintUtil.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/AssemblyFactoryTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestBinding.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestImplementation.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestInterface.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestInterfaceContract.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestOperation.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBuilderTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ajax/DISCLAIMER create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ajax/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ajax/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ajax/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ajax/src/main/java/org/apache/tuscany/sca/binding/ajax/AjaxBinding.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ajax/src/main/java/org/apache/tuscany/sca/binding/ajax/AjaxBindingActivator.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ajax/src/main/java/org/apache/tuscany/sca/binding/ajax/AjaxInvoker.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ajax/src/main/java/org/apache/tuscany/sca/binding/ajax/AjaxInvokerFactory.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ajax/src/main/java/org/apache/tuscany/sca/binding/ajax/AjaxService.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ajax/src/main/java/org/apache/tuscany/sca/binding/ajax/AjaxServlet.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ajax/src/main/resources/META-INF/services/org.apache.tuscany.sca.spi.BindingActivator create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/DISCLAIMER create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/EJBBinding.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/EJBBindingActivator.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/EJBTargetInvoker.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/AttributeMode.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/AttributeType.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/ClassType.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/ConstantType.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/ContainerType.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/ExceptionType.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/IDLType.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/IDLUtil.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/IDLViolationException.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/InterfaceType.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/Java2IDL.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/Java2IDLUtil.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/OperationType.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/ParameterType.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/PrimitiveType.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/ValueMemberType.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/ValueType.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/util/EJBHandler.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/util/EJBLocator.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/util/EJBObjectFactory.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/util/EJBStubHelper.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/util/InterfaceInfo.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/util/JavaReflectionAdapter.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/util/MethodInfo.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/util/NamingEndpoint.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/resources/META-INF/services/org.apache.tuscany.sca.spi.BindingActivator create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/test/java/account/BankManagerFacade.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/test/java/account/Customer.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/test/java/account/CustomerImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/test/java/org/apache/geronimo/samples/bank/ejb/BankManagerFacade.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/test/java/org/apache/geronimo/samples/bank/ejb/BankManagerFacadeHome.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/test/java/org/apache/tuscany/sca/binding/ejb/tests/EJBReferenceTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/test/java/org/apache/tuscany/sca/binding/ejb/tests/MockServer.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/test/java/org/apache/tuscany/sca/binding/ejb/tests/SocketTracer.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/test/resources/account/account.composite create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/DISCLAIMER create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/DefaultFeedBindingFactory.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/Feed.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/FeedBinding.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/FeedBindingFactory.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/impl/FeedBindingImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/module/FeedModuleActivator.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/FeedBindingInvoker.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/FeedBindingListener.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/FeedBindingProviderFactory.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/FeedReferenceBindingProvider.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/FeedServiceBindingProvider.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/xml/AtomBindingProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/xml/RssBindingProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-jsonrpc/DISCLAIMER create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-jsonrpc/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-jsonrpc/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-jsonrpc/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCBinding.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCBindingActivator.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCService.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCServiceServlet.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/JavaToSmd.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/ScaDomainScriptServlet.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-jsonrpc/src/main/resources/META-INF/services/org.apache.tuscany.sca.spi.BindingActivator create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-jsonrpc/src/main/resources/org/apache/tuscany/sca/binding/jsonrpc/jsonrpc.js create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-jsonrpc/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/Echo.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-jsonrpc/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/EchoComponentImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-jsonrpc/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCServiceTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-jsonrpc/src/test/resources/JSONRPCBinding.composite create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-rmi/.ruleset create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-rmi/DISCLAIMER create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-rmi/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-rmi/NOTICE create mode 100755 sca-java-1.x/branches/sca-java-0.91/modules/binding-rmi/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/RMIBinding.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/RMIBindingActivator.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/RMIReferenceInvoker.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/RMIReferenceInvokerFactory.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/RMIService.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-rmi/src/main/resources/META-INF/services/org.apache.tuscany.sca.spi.BindingActivator create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-rmi/src/test/java/helloworld/HelloWorldImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-rmi/src/test/java/helloworld/HelloWorldRmiImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-rmi/src/test/java/helloworld/HelloWorldRmiService.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-rmi/src/test/java/helloworld/HelloWorldService.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-rmi/src/test/java/org/apache/tuscany/sca/binding/rmi/BindingTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-rmi/src/test/resources/HelloWorldImpl.componentType create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-rmi/src/test/resources/HelloWorldRmiImpl.componentType create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-rmi/src/test/resources/RMIBindingTest.composite create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/DISCLAIMER create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/NOTICE create mode 100755 sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/main/assembly/axis2.xml create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/Axis2AsyncBindingInvoker.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/Axis2BindingInvoker.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/Axis2BindingProviderFactory.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/Axis2CallbackInvocationHandler.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/Axis2ModuleActivator.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/Axis2OneWayBindingInvoker.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/Axis2ReferenceBindingProvider.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/Axis2ReferenceCallback.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/Axis2ReferenceCallbackTargetInvoker.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/Axis2ServiceBindingProvider.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/Axis2ServiceCallbackTargetInvoker.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/Axis2ServiceInMessageReceiver.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/Axis2ServiceInOutAsyncMessageReceiver.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/Axis2ServiceInOutSyncMessageReceiver.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/Axis2ServiceServlet.java create mode 100755 sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/TuscanyAxisConfigurator.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/TuscanyDispatcher.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/TuscanyListingAgent.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator create mode 100755 sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/main/resources/org/apache/tuscany/sca/binding/axis2/engine/config/axis2.xml create mode 100755 sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/axis2/Axis2ReferenceTestCase.java create mode 100755 sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/axis2/Axis2ServiceTestCase.java create mode 100755 sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/axis2/Greeter.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/axis2/GreetingCallback.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/axis2/itests/HelloWorld.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/axis2/itests/HelloWorldComponent.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/axis2/itests/HelloWorldMultiService.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/axis2/itests/HelloWorldOM.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/axis2/itests/HelloWorldOM2.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/axis2/itests/HelloWorldOMComponent.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/axis2/itests/HelloWorldOMService.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/axis2/itests/HelloWorldOMTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/axis2/itests/HelloWorldService.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/axis2/itests/HelloWorldTestCaseFIXME.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/axis2/itests/QuestionMarkWSDLTestCaseFIXME.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/axis2/itests/endpoints/AbstractHelloWorldOMTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/axis2/itests/endpoints/DefaultMultiServiceTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/axis2/itests/endpoints/DefaultSingleServiceTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/axis2/itests/endpoints/WSDLExplicitURITestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/axis2/itests/endpoints/WSDLRelativeURITestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/axis2/itests/HelloWorld.composite create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/axis2/itests/endpoints/DefaultMultiService.composite create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/axis2/itests/endpoints/DefaultSingleService.composite create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/axis2/itests/endpoints/WSDLExplicitURI.composite create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/axis2/itests/endpoints/WSDLRelativeURI.composite create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/axis2/itests/endpoints/helloworld-om-relative-uri.wsdl create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/axis2/itests/helloworld-om-uri.wsdl create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/axis2/itests/helloworld-om.composite create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/axis2/itests/helloworld-om.wsdl create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/axis2/itests/helloworld.wsdl create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/axis2/itests/questionmark-wsdl.composite create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-xml/.checkstyle create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-xml/.pmd create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-xml/.ruleset create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-xml/DISCLAIMER create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-xml/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-xml/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-xml/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-xml/src/main/java/org/apache/tuscany/sca/binding/ws/xml/WebServiceBindingProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-xml/src/main/java/org/apache/tuscany/sca/binding/ws/xml/WebServiceConstants.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-xml/src/test/java/org/apache/tuscany/sca/binding/ws/xml/ReadTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-xml/src/test/java/org/apache/tuscany/sca/binding/ws/xml/WriteTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/Calculator.composite create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/CalculatorImpl.componentType create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/example.wsdl create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/invalid-stockquote.wsdl create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/ipo.xsd create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/stockquote.wsdl create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/test1.wsdl create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/test1.xsd create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/test2.wsdl create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/unwrapped-stockquote.wsdl create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ws/.checkstyle create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ws/.pmd create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ws/.ruleset create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ws/DISCLAIMER create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ws/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ws/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ws/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/DefaultWebServiceBindingFactory.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/WebServiceBinding.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/WebServiceBindingFactory.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/impl/WebServiceBindingFactoryImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/impl/WebServiceBindingImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/commonj-api/DISCLAIMER create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/commonj-api/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/commonj-api/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/commonj-api/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/commonj-api/src/main/java/commonj/timers/CancelTimerListener.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/commonj-api/src/main/java/commonj/timers/StopTimerListener.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/commonj-api/src/main/java/commonj/timers/Timer.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/commonj-api/src/main/java/commonj/timers/TimerListener.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/commonj-api/src/main/java/commonj/timers/TimerManager.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/commonj-api/src/main/java/commonj/work/RemoteWorkItem.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/commonj-api/src/main/java/commonj/work/Work.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/commonj-api/src/main/java/commonj/work/WorkCompletedException.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/commonj-api/src/main/java/commonj/work/WorkEvent.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/commonj-api/src/main/java/commonj/work/WorkException.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/commonj-api/src/main/java/commonj/work/WorkItem.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/commonj-api/src/main/java/commonj/work/WorkListener.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/commonj-api/src/main/java/commonj/work/WorkManager.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/commonj-api/src/main/java/commonj/work/WorkRejectedException.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/.checkstyle create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/.pmd create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/.ruleset create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/DISCLAIMER create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/impl/ArtifactImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/impl/ContributionExportImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/impl/ContributionFactoryImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/impl/ContributionImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/impl/ContributionImportImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/impl/DeployedArtifactImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/FolderContributionProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/InvalidFolderContributionException.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/InvalidFolderContributionURIException.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/JarContributionProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/resolver/impl/ModelResolverImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/ArtifactTypeDescriberImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/ContributionMetadataLoaderImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/ContributionRepositoryImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/ContributionServiceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/InvalidContributionMetadataException.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/InvalidContributionURIException.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/InvalidValueException.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/PackageTypeDescriberImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/util/FileHelper.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/util/IOHelper.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/processor/FolderContributionPackageProcessorTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/processor/JarContributionPackageProcessorTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/resolver/ArtifactResolverTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/services/ContentTypeDescriberImplTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/services/ContributionMetadataLoaderTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/services/ContributionRepositoryTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/services/PackageTypeDescriberImplTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/test/resources/deployables/sample-calculator.jar create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/test/resources/repository/sample-calculator.jar create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/test/resources/test.composite create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/test/resources/test.ext create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/contribution/.checkstyle create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/contribution/.pmd create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/contribution/.ruleset create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/contribution/DISCLAIMER create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/contribution/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/contribution/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/contribution/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/Artifact.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/ContentType.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/Contribution.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/ContributionExport.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/ContributionFactory.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/ContributionImport.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/DeployedArtifact.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ArtifactProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ArtifactProcessorExtensionPoint.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ContributionPostProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ContributionPostProcessorExtensionPoint.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultArtifactProcessorExtensionPoint.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultPackageProcessorExtensionPoint.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultStAXArtifactProcessorExtensionPoint.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultURLArtifactProcessorExtensionPoint.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensiblePackageProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleStAXArtifactProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleURLArtifactProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/PackageProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/PackageProcessorExtensionPoint.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/StAXArtifactProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/StAXArtifactProcessorExtensionPoint.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/URLArtifactProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/URLArtifactProcessorExtensionPoint.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/ClassReference.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/ModelResolver.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/AbstractContributionException.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionException.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionMetadataLoader.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionMetadataLoaderException.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionReadException.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionRepository.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionResolveException.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionRuntimeException.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionService.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionWireException.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionWriteException.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/InvalidConfigurationException.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/TypeDescriber.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/UnrecognizedElementException.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/UnsupportedContentTypeException.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-databinding/.checkstyle create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-databinding/.pmd create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-databinding/.ruleset create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-databinding/DISCLAIMER create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-databinding/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-databinding/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-databinding/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-databinding/src/main/java/org/apache/tuscany/core/databinding/module/DataBindingModuleActivator.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-databinding/src/main/java/org/apache/tuscany/core/databinding/processor/DataBindingJavaInterfaceProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-databinding/src/main/java/org/apache/tuscany/core/databinding/transformers/Exception2ExceptionTransformer.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-databinding/src/main/java/org/apache/tuscany/core/databinding/transformers/Input2InputTransformer.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-databinding/src/main/java/org/apache/tuscany/core/databinding/transformers/Output2OutputTransformer.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-databinding/src/main/java/org/apache/tuscany/core/databinding/wire/DataBindingRuntimeWireProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-databinding/src/main/java/org/apache/tuscany/core/databinding/wire/DataTransformationInteceptor.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-databinding/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-databinding/src/test/java/org/apache/tuscany/core/databinding/processor/DataBindingJavaInterfaceProcessorTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-databinding/src/test/java/org/apache/tuscany/core/databinding/transformers/IDLTransformerTestCase.java.fixme create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-spi/.checkstyle create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-spi/.pmd create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-spi/.ruleset create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-spi/DISCLAIMER create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-spi/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-spi/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-spi/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/doc/Context Model.emx create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/core/DefaultExtensionPointRegistry.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/core/DefaultModelFactoryExtensionPoint.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/core/ExtensionPointRegistry.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/core/ModelFactoryExtensionPoint.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/core/ModuleActivator.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/event/Event.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/event/EventFilter.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/event/EventPublisher.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/event/RuntimeEventListener.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/event/TrueFilter.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/Interceptor.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/InvocationChain.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/Invoker.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/Message.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/MessageFactory.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/management/ManagementService.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/BindingProviderFactory.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/DefaultProviderFactoryExtensionPoint.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ImplementationProvider.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ImplementationProviderFactory.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ProviderFactory.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ProviderFactoryExtensionPoint.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ReferenceBindingProvider.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ServiceBindingProvider.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/DefaultWireProcessorExtensionPoint.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/EndpointReference.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponent.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponentReference.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponentService.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeWire.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeWireProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeWireProcessorExtensionPoint.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/DuplicateRecordException.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/RecoveryListener.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/Store.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/StoreException.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/StoreExpirationEvent.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/StoreMonitor.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/StoreReadException.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/StoreWriteException.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/work/NotificationListener.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/work/WorkScheduler.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/work/WorkSchedulerException.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/test/resources/org/apache/tuscany/spi/util/stax/test.composite create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-spring/DISCLAIMER create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-spring/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-spring/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-spring/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/assembly/impl/BeanAssemblyFactory.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/assembly/impl/BeanComponentImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/assembly/impl/BeanReferenceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/context/ModelResolverImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/context/SCADomainContext.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/implementation/java/impl/BeanBaseJavaImplementationImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/implementation/java/impl/BeanJavaImplementationFactory.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/implementation/java/impl/BeanJavaImplementationImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/implementation/java/impl/BeanJavaInterfaceContractImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/implementation/java/impl/BeanJavaInterfaceFactory.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/implementation/java/impl/BeanJavaInterfaceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/test/java/calculator/AddService.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/test/java/calculator/AddServiceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/test/java/calculator/CalculatorClient.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/test/java/calculator/CalculatorService.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/test/java/calculator/CalculatorServiceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/test/java/calculator/DivideService.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/test/java/calculator/DivideServiceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/test/java/calculator/MultiplyService.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/test/java/calculator/MultiplyServiceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/test/java/calculator/NestedCalculatorClient.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/test/java/calculator/SubtractService.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/test/java/calculator/SubtractServiceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/test/java/org/apache/tuscany/sca/core/spring/CalculatorTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/test/java/org/apache/tuscany/sca/core/spring/NestedCalculatorTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/test/resources/org/apache/tuscany/sca/core/spring/Calculator.composite create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/test/resources/org/apache/tuscany/sca/core/spring/InnerCalculator.composite create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/test/resources/org/apache/tuscany/sca/core/spring/InnerOperations.composite create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/test/resources/org/apache/tuscany/sca/core/spring/OuterCalculator.composite create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/.checkstyle create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/.pmd create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/.ruleset create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/DISCLAIMER create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/component/CallableReferenceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/component/CallbackReferenceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/component/ComponentContextImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/component/ComponentContextProvider.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/component/RequestContextImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/component/ServiceReferenceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/event/BaseEventPublisher.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/event/ComponentStart.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/event/ComponentStop.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/event/ConversationEnd.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/event/ConversationStart.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/event/HttpSessionEnd.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/event/HttpSessionStart.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/event/RequestEnd.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/event/RequestStart.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/AbstractInvocationHandler.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallbackInterfaceInterceptor.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallbackWireObjectFactory.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ExtensibleWireProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/InvocationChainImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/JDKCallbackInvocationHandler.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/JDKInvocationHandler.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/JDKProxyService.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/MessageFactoryImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/MessageImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/NoMethodForOperationException.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/NonBlockingInterceptor.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ProxyCreationException.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ProxyFactory.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ThreadMessageContext.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/WireObjectFactory.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/ActivationException.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/CompositeActivator.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/CompositeActivatorImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/EndpointReferenceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/RuntimeAssemblyFactory.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/RuntimeComponentImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/RuntimeComponentReferenceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/RuntimeComponentServiceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/RuntimeSCABindingProvider.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/RuntimeSCABindingProviderFactory.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/RuntimeWireImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/AbstractScopeContainer.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/CompositeScopeContainer.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/CompositeScopeContainerFactory.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ConversationalScopeContainer.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ConversationalScopeContainerFactory.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/HttpSessionScopeContainer.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/HttpSessionScopeContainerFactory.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/RequestScopeContainer.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/RequestScopeContainerFactory.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ScopeRegistryImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/StatelessScopeContainer.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/StatelessScopeContainerFactory.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/store/MemoryStore.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/util/IOHelper.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/work/Jsr237Work.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/work/Jsr237WorkScheduler.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/work/ThreadPoolWorkManager.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/work/WorkEventImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/work/WorkItemImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/factory/ObjectCreationException.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/factory/ObjectFactory.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/factory/SingletonObjectFactory.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/scope/AbstractLifecycle.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/scope/CoreRuntimeException.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/scope/InstanceWrapper.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/scope/Lifecycle.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/scope/PersistenceException.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/scope/Scope.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/scope/ScopeContainer.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/scope/ScopeContainerFactory.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/scope/ScopeIdentifier.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/scope/ScopeNotFoundException.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/scope/ScopeRegistry.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/scope/ScopedImplementationProvider.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/scope/ScopedRuntimeComponent.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/scope/TargetDestructionException.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/scope/TargetInitializationException.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/scope/TargetInvocationException.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/scope/TargetInvokerCreationException.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/scope/TargetNotFoundException.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/scope/TargetResolutionException.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/DefaultExtensionPointRegistryTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/event/BaseEventPublisherTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/event/EventTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/AsyncTarget.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/BadContextPojo.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/BadNamePojo.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/BasicInterface.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/BasicInterfaceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/CompositeScopeComponent.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/CompositeScopeComponentImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/CompositeScopeDestroyOnlyComponent.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/CompositeScopeInitDestroyComponent.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/CompositeScopeInitOnlyComponent.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/ConversationalScopeComponent.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/ConversationalScopeComponentImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/ConversationalScopeDestroyOnlyComponent.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/ConversationalScopeInitDestroyComponent.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/ConversationalScopeInitOnlyComponent.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/OrderException.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/OrderedDependentPojo.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/OrderedDependentPojoImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/OrderedEagerInitPojo.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/OrderedInitPojo.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/OrderedInitPojoImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/OtherTarget.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/OtherTargetImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/RequestScopeComponent.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/RequestScopeDestroyOnlyComponent.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/RequestScopeInitDestroyComponent.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/RequestScopeInitOnlyComponent.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/SessionScopeComponent.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/SessionScopeComponentImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/SessionScopeInitDestroyComponent.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/SessionScopeInitOnlyComponent.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/SimpleTarget.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/SimpleTargetImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/Source.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/SourceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/StatelessComponent.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/StatelessComponentImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/Target.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/TargetImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/scope/AbstractScopeContainerTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/store/MemoryStoreTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/wire/CallbackInterfaceInterceptorTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/wire/InvocationChainImplTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/wire/NonBlockingInterceptorTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/factory/AssertionTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/factory/SingletonObjectFactoryTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/scope/ScopeTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/.ruleset create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/DISCLAIMER create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/NOTICE create mode 100755 sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/AxiomDataBinding.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/AxiomExceptionHandler.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/AxiomHelper.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/OMElement2Object.java create mode 100755 sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/OMElement2String.java create mode 100755 sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/OMElement2XMLStreamReader.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/OMElementWrapperHandler.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/Object2OMElement.java create mode 100755 sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/String2OMElement.java create mode 100755 sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/XMLStreamReader2OMElement.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/module/AxiomDataBindingModuleActivator.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/test/java/org/apache/tuscany/sca/databinding/axiom/AxiomExceptionHandlerTestCase.java create mode 100755 sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/test/java/org/apache/tuscany/sca/databinding/axiom/OMElementTestCase.java create mode 100755 sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/test/resources/ipo.xml create mode 100755 sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/test/resources/ipo.xsd create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/test/resources/order.wsdl create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding-jaxb/.ruleset create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding-jaxb/DISCLAIMER create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding-jaxb/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding-jaxb/NOTICE create mode 100755 sca-java-1.x/branches/sca-java-0.91/modules/databinding-jaxb/pom.xml create mode 100755 sca-java-1.x/branches/sca-java-0.91/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXB2Node.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextHelper.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBDataBinding.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBExceptionHandler.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBWrapperHandler.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXWSJavaInterfaceProcessor.java create mode 100755 sca-java-1.x/branches/sca-java-0.91/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/Node2JAXB.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/Reader2JAXB.java create mode 100755 sca-java-1.x/branches/sca-java-0.91/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/XMLStreamReader2JAXB.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/module/JAXBDataBindingModuleActivator.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding-jaxb/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBDataBindingTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBExceptionHandlerTestCase.java create mode 100755 sca-java-1.x/branches/sca-java-0.91/modules/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBWrapperHandlerTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/fault/InvalidSymbolFault.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/fault/InvalidSymbolFault_Exception.java create mode 100755 sca-java-1.x/branches/sca-java-0.91/modules/databinding-jaxb/src/test/resources/ipo.xsd create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo-axiom/.checkstyle create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo-axiom/.ruleset create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo-axiom/DISCLAIMER create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo-axiom/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo-axiom/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo-axiom/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo-axiom/src/main/java/org/apache/tuscany/sca/databinding/sdo2om/DataObject2OMElement.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo-axiom/src/main/java/org/apache/tuscany/sca/databinding/sdo2om/DataObjectSerializer.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo-axiom/src/main/java/org/apache/tuscany/sca/databinding/sdo2om/SDODataSource.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo-axiom/src/main/java/org/apache/tuscany/sca/databinding/sdo2om/XMLDocument2OMElement.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo-axiom/src/main/java/org/apache/tuscany/sca/databinding/sdo2om/module/SDOAxiomModuleActivator.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo-axiom/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo-axiom/src/test/java/org/apache/tuscany/sca/databinding/sdo2om/DataObject2OMElementTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo-axiom/src/test/java/org/apache/tuscany/sca/databinding/sdo2om/SDOTransformerTestCaseBase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo-axiom/src/test/java/org/apache/tuscany/sca/databinding/sdo2om/XMLDocument2OMElementTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo-axiom/src/test/resources/ipo.xsd create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo-axiom/src/test/resources/stock.xsd create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/.checkstyle create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/.ruleset create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/DISCLAIMER create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/NOTICE create mode 100755 sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/pom.xml create mode 100755 sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/DataObject2String.java create mode 100755 sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/DataObject2XMLStreamReader.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/DuplicateHelperContextException.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/HelperContextProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/HelperContextRegistry.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/HelperContextRegistryImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/ImportSDO.java create mode 100755 sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/ImportSDOProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOContextHelper.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDODataBinding.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOExceptionHandler.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOSimpleTypeMapper.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOWrapperHandler.java create mode 100755 sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/String2DataObject.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/XMLDocument2String.java create mode 100755 sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/XMLDocument2XMLStreamReader.java create mode 100755 sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/XMLStreamReader2DataObject.java create mode 100755 sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/XMLStreamReader2XMLDocument.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/api/HelperContext.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/module/SDODataBindingModuleActivator.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/test/java/com/example/stock/sdo/fault/InvalidSymbolFault_Exception.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/DataObject2StringTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/DataObject2XMLStreamReaderTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/HelperContextProcessorTestCase.java create mode 100755 sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/ImportSDOProcessorTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDODataBindingTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDOExceptionHandlerTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDOTransformerTestCaseBase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDOWrapperHandlerTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/TestModelResolver.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/XMLDocument2XMLStreamReaderTestCase.java create mode 100755 sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/test/resources/ipo.xsd create mode 100755 sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/test/resources/model/sca-core.xsd create mode 100755 sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/test/resources/model/sca-implementation-mock.xsd create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/test/resources/stock.xsd create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/test/resources/wrapper.xml create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/test/resources/wrapper.xsd create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding/.checkstyle create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding/.pmd create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding/.ruleset create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding/DISCLAIMER create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DataBinding.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DataBindingExtensionPoint.java create mode 100755 sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DataPipe.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DefaultDataBindingExtensionPoint.java create mode 100755 sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DefaultTransformerExtensionPoint.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/ExceptionHandler.java create mode 100755 sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/Mediator.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/PullTransformer.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/PushTransformer.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/SimpleTypeMapper.java create mode 100755 sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/TransformationContext.java create mode 100755 sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/TransformationException.java create mode 100755 sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/Transformer.java create mode 100755 sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/TransformerExtensionPoint.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/WrapperHandler.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/annotation/DataBinding.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/BaseDataBinding.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/BaseTransformer.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/DOMHelper.java create mode 100755 sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/DirectedGraph.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/Group2GroupTransformer.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/GroupDataBinding.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/Java2SimpleTypeTransformer.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/MediatorImpl.java create mode 100755 sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/PipedTransformer.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/SimpleType2JavaTransformer.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/SimpleTypeMapperImpl.java create mode 100755 sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/TransformationContextImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/XSDDataTypeConverter.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/DOMNode2JavaBeanTransformer.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/Java2XMLMapperException.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/JavaBean2DOMNodeTransformer.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/JavaBean2XMLStreamReader.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/JavaBean2XMLTransformer.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/JavaBeansDataBinding.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/XML2JavaBeanTransformer.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/XML2JavaMapperException.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/BeanUtil.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/DOMDataBinding.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/DOMWrapperHandler.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/DOMXMLStreamReader.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/DelegatingNamespaceContext.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/InputSource2Node.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/InputSource2SAX.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/InputStream2Node.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/InputStream2SAX.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/NameValueArrayStreamReader.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/NameValuePairStreamReader.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/NamedProperty.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/NilElementStreamReader.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Node2OutputStream.java create mode 100755 sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Node2String.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Node2Writer.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Node2XMLStreamReader.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Reader2Node.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Reader2SAX.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/SAX2DOM.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/SAX2DOMPipe.java create mode 100755 sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Source2ResultTransformer.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/StAX2SAXAdapter.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/StAXDataBinding.java create mode 100755 sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/StAXHelper.java create mode 100755 sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/StreamDataPipe.java create mode 100755 sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/String2Node.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/String2SAX.java create mode 100755 sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/String2XMLStreamReader.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/WrappingXMLStreamReader.java create mode 100755 sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Writer2ReaderDataPipe.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XMLDocumentStreamReader.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XMLFragmentStreamReader.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XMLFragmentStreamReaderImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XMLGroupDataBinding.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XMLStreamReader2Node.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XMLStreamReader2SAX.java create mode 100755 sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XMLStreamReader2String.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XMLStreamSerializer.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XMLStreamable.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XMLStringDataBinding.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/extension/DOMHelperTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/extension/DataBindingExtensionTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/extension/SimpleTypeMapperExtensionTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/extension/TransformerExtensionTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/extension/XSDDataTypeConverterTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/impl/DataBindingRegistryImplTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/impl/DataBindingTestCase.java create mode 100755 sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/impl/DirectedGraphTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/impl/MediatorImplTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/impl/TransformerRegistryImplTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/DOM2StAXTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/DataPipeTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/JavaBean2XMLStreamReaderTestCase.java create mode 100755 sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/Node2StringTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/PushTransformationTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/StAXHelperTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/TraxTransformerTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/test/resources/org/apache/tuscany/sca/databinding/impl/ipo.xsd create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/test/resources/org/apache/tuscany/sca/databinding/impl/order.wsdl create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/test/resources/org/apache/tuscany/sca/databinding/xml/foo.xml create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/extension-helper/DISCLAIMER create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/extension-helper/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/extension-helper/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/extension-helper/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/extension-helper/src/main/java/org/apache/tuscany/sca/spi/BindingActivator.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/extension-helper/src/main/java/org/apache/tuscany/sca/spi/ComponentLifecycle.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/extension-helper/src/main/java/org/apache/tuscany/sca/spi/ImplementationActivator.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/extension-helper/src/main/java/org/apache/tuscany/sca/spi/InvokerFactory.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/extension-helper/src/main/java/org/apache/tuscany/sca/spi/impl/BindingSCDLProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/extension-helper/src/main/java/org/apache/tuscany/sca/spi/impl/BindingsActivator.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/extension-helper/src/main/java/org/apache/tuscany/sca/spi/impl/DiscoveryUtils.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/extension-helper/src/main/java/org/apache/tuscany/sca/spi/impl/ImplementationImplementationProvider.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/extension-helper/src/main/java/org/apache/tuscany/sca/spi/impl/ImplementationsActivator.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/extension-helper/src/main/java/org/apache/tuscany/sca/spi/impl/PojoBinding.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/extension-helper/src/main/java/org/apache/tuscany/sca/spi/impl/PojoImplementation.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/extension-helper/src/main/java/org/apache/tuscany/sca/spi/impl/SCDLProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/extension-helper/src/main/java/org/apache/tuscany/sca/spi/utils/AbstractBinding.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/extension-helper/src/main/java/org/apache/tuscany/sca/spi/utils/AbstractImplementation.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/extension-helper/src/main/java/org/apache/tuscany/sca/spi/utils/AbstractStAXArtifactProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/extension-helper/src/main/java/org/apache/tuscany/sca/spi/utils/DefaultPropertyValueObjectFactory.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/extension-helper/src/main/java/org/apache/tuscany/sca/spi/utils/DynamicImplementation.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/extension-helper/src/main/java/org/apache/tuscany/sca/spi/utils/PropertyValueObjectFactory.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/extension-helper/src/main/java/org/apache/tuscany/sca/spi/utils/ResourceHelper.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/extension-helper/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/host-embedded/.checkstyle create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/host-embedded/.pmd create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/host-embedded/.ruleset create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/host-embedded/DISCLAIMER create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/host-embedded/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/host-embedded/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/host-embedded/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/SCADomain.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/SCADomainBean.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/SCATestCaseRunner.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/DefaultSCADomain.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/EmbeddedSCADomain.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/ReallySmallRuntime.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/ReallySmallRuntimeBuilder.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/host-embedded/src/test/java/crud/CRUD.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/host-embedded/src/test/java/crud/CRUDImplementation.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/host-embedded/src/test/java/crud/CRUDImplementationFactory.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/host-embedded/src/test/java/crud/DefaultCRUDImplementationFactory.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/host-embedded/src/test/java/crud/backend/ResourceManager.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/host-embedded/src/test/java/crud/impl/CRUDImplementationImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/host-embedded/src/test/java/crud/impl/CRUDImplementationProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/host-embedded/src/test/java/crud/module/CRUDModuleActivator.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/host-embedded/src/test/java/crud/provider/CRUDImplementationProvider.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/host-embedded/src/test/java/crud/provider/CRUDImplementationProviderFactory.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/host-embedded/src/test/java/crud/provider/CRUDInvoker.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/SCADomainBeanTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/SCADomainTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/impl/DefaultSCADomainTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/impl/EmbeddedSCADomainTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/impl/TestModelResolver.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/host-embedded/src/test/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/host-embedded/src/test/resources/crud.composite create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/host-embedded/src/test/resources/test.txt create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/host-http/DISCLAIMER create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/host-http/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/host-http/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/host-http/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/host-http/src/main/java/org/apache/tuscany/sca/http/DefaultResourceServlet.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/host-http/src/main/java/org/apache/tuscany/sca/http/DefaultServletHostExtensionPoint.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/host-http/src/main/java/org/apache/tuscany/sca/http/ExtensibleServletHost.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/host-http/src/main/java/org/apache/tuscany/sca/http/ServletHost.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/host-http/src/main/java/org/apache/tuscany/sca/http/ServletHostExtensionPoint.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/host-http/src/main/java/org/apache/tuscany/sca/http/ServletMappingException.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/host-http/src/main/java/org/apache/tuscany/sca/http/module/HTTPRuntimeModuleActivator.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/host-http/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/host-rmi/DISCLAIMER create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/host-rmi/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/host-rmi/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/host-rmi/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/host-rmi/src/main/java/org/apache/tuscany/sca/rmi/DefaultRMIHost.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/host-rmi/src/main/java/org/apache/tuscany/sca/rmi/RMIHost.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/host-rmi/src/main/java/org/apache/tuscany/sca/rmi/RMIHostException.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/host-rmi/src/main/java/org/apache/tuscany/sca/rmi/RMIHostRuntimeException.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/host-rmi/src/main/java/org/apache/tuscany/sca/rmi/module/RMIRuntimeModuleActivator.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/host-rmi/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/host-rmi/src/test/java/org/apache/tuscany/sca/rmi/RMIHostImplTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/host-webapp/DISCLAIMER create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/host-webapp/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/host-webapp/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/host-webapp/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/host-webapp/src/main/java/org/apache/tuscany/sca/webapp/SCADomainHelper.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/host-webapp/src/main/java/org/apache/tuscany/sca/webapp/TuscanyContextListener.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/host-webapp/src/main/java/org/apache/tuscany/sca/webapp/TuscanyServlet.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/host-webapp/src/main/java/org/apache/tuscany/sca/webapp/WebAppModuleActivator.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/host-webapp/src/main/java/org/apache/tuscany/sca/webapp/WebAppServletHost.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/host-webapp/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/http-jetty/.ruleset create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/http-jetty/DISCLAIMER create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/http-jetty/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/http-jetty/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/http-jetty/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/http-jetty/src/main/java/org/apache/tuscany/sca/http/jetty/JettyDefaultServlet.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/http-jetty/src/main/java/org/apache/tuscany/sca/http/jetty/JettyLogger.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/http-jetty/src/main/java/org/apache/tuscany/sca/http/jetty/JettyServer.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/http-jetty/src/main/java/org/apache/tuscany/sca/http/jetty/module/JettyRuntimeModuleActivator.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/http-jetty/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/http-jetty/src/test/java/org/apache/tuscany/sca/http/jetty/JettyServerTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/http-jetty/src/test/resources/content/test.html create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/http-tomcat/.ruleset create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/http-tomcat/DISCLAIMER create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/http-tomcat/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/http-tomcat/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/http-tomcat/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/http-tomcat/src/main/java/org/apache/tuscany/sca/http/tomcat/ServletWrapper.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/http-tomcat/src/main/java/org/apache/tuscany/sca/http/tomcat/TomcatDefaultServlet.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/http-tomcat/src/main/java/org/apache/tuscany/sca/http/tomcat/TomcatServer.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/http-tomcat/src/main/java/org/apache/tuscany/sca/http/tomcat/module/TomcatRuntimeModuleActivator.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/http-tomcat/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/http-tomcat/src/test/java/org/apache/tuscany/sca/http/tomcat/TomcatServerTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/http-tomcat/src/test/resources/content/test.html create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/.checkstyle create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/.pmd create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/.ruleset create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/DISCLAIMER create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/context/InstanceFactory.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/context/InstanceFactoryProvider.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/context/JavaPropertyValueObjectFactory.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/context/ReflectiveInstanceFactory.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/context/ReflectiveInstanceWrapper.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/context/TargetMethodNotFoundException.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/ArrayMultiplicityObjectFactory.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/ContextInjector.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/ConversationIDObjectFactory.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/EventInvoker.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/FieldInjector.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/InjectionRuntimeException.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/Injector.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/InvalidAccessorException.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/InvalidResourceTypeException.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/JNDIObjectFactory.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/ListMultiplicityObjectFactory.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/MethodEventInvoker.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/MethodInjector.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/NoAccessorException.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/NoMultiplicityTypeException.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/ObjectCallbackException.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/PojoObjectFactory.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/RequestContextObjectFactory.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/ResourceHost.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/ResourceNotFoundException.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/ResourceObjectFactory.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/ResourceResolutionException.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/SingletonObjectFactory.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/InvalidConversationSequenceException.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaComponentInfo.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaImplementationProvider.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaImplementationProviderFactory.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaTargetInvoker.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/NoConversationalContractException.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/PassByValueInvoker.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/PojoComponentContextFactory.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/PojoConfiguration.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/TargetInvoker.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/TargetInvokerInvoker.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/module/JavaRuntimeModuleActivator.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/monitor/ExceptionFormatter.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/monitor/ExceptionFormatterImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/monitor/FormatterRegistry.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/monitor/InvalidLevelException.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/monitor/JavaLoggingMonitorFactory.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/monitor/MonitorFactory.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/monitor/MonitorFactoryUtil.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/monitor/NullMonitorFactory.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/monitor/ProxyMonitorFactory.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/context/ModelHelper.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/context/MultiplicityTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/context/ReflectiveInstanceWrapperTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/injection/CallbackWireObjectFactoryTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/injection/FieldInjectorTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/injection/JNDIObjectFactoryTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/injection/MethodEventInvokerTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/injection/MethodInjectorTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/injection/PojoObjectFactoryTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/injection/RequestContextObjectFactoryTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/injection/ResourceObjectFactoryTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/injection/SingletonObjectFactoryTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/integration/AbstractConversationTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/integration/ConversationIdleExpireTestCase.java.FIXME create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/integration/ConversationMaxAgeExpireTestCase.java.FIXME create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/integration/ConversationStartStopEndTestCase.java.FIXME create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/integration/ReferenceInjectionTestCase.java.FIXME create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/mock/AsyncTarget.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/mock/BadContextPojo.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/mock/BadNamePojo.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/mock/BasicInterface.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/mock/BasicInterfaceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/mock/CompositeScopeComponent.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/mock/CompositeScopeComponentImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/mock/CompositeScopeDestroyOnlyComponent.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/mock/CompositeScopeInitDestroyComponent.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/mock/CompositeScopeInitOnlyComponent.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/mock/ConversationalScopeComponent.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/mock/ConversationalScopeComponentImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/mock/ConversationalScopeDestroyOnlyComponent.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/mock/ConversationalScopeInitDestroyComponent.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/mock/ConversationalScopeInitOnlyComponent.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/mock/MockFactory.java.FIXME create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/mock/MockStaticInvoker.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/mock/MockSyncInterceptor.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/mock/OrderException.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/mock/OrderedDependentPojo.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/mock/OrderedDependentPojoImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/mock/OrderedEagerInitPojo.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/mock/OrderedInitPojo.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/mock/OrderedInitPojoImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/mock/OtherTarget.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/mock/OtherTargetImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/mock/RequestScopeComponent.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/mock/RequestScopeDestroyOnlyComponent.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/mock/RequestScopeInitDestroyComponent.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/mock/RequestScopeInitOnlyComponent.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/mock/SessionScopeComponent.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/mock/SessionScopeComponentImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/mock/SessionScopeInitDestroyComponent.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/mock/SessionScopeInitOnlyComponent.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/mock/SimpleTarget.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/mock/SimpleTargetImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/mock/Source.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/mock/SourceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/mock/StatelessComponent.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/mock/StatelessComponentImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/mock/Target.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/mock/TargetImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/monitor/ExceptionFormatterTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/monitor/JavaLoggingTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/util/Bean1.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/util/Bean2.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/util/JavaIntrospectionHelperTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/util/SuperBean.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-xml/.checkstyle create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-xml/.pmd create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-xml/.ruleset create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-xml/DISCLAIMER create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-xml/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-xml/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-xml/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-xml/src/main/java/org/apache/tuscany/api/annotation/LogLevel.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-xml/src/main/java/org/apache/tuscany/api/annotation/Monitor.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-xml/src/main/java/org/apache/tuscany/api/annotation/Resource.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-xml/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/DefaultJavaClassIntrospectorExtensionPoint.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-xml/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/DuplicatePropertyException.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-xml/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/ExtensibleJavaClassIntrospector.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-xml/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/IllegalPropertyException.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-xml/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/IntrospectionException.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-xml/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/JavaClassIntrospector.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-xml/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/JavaClassIntrospectorExtensionPoint.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-xml/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/JavaClassVisitor.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-xml/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/AbstractPropertyProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-xml/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/AllowsPassByReferenceProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-xml/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/AmbiguousConstructorException.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-xml/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/BaseJavaClassVisitor.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-xml/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConstructorProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-xml/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ContextProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-xml/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConversationProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-xml/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/DestroyProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-xml/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/DuplicateConstructorException.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-xml/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/DuplicateDestructorException.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-xml/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/DuplicateInitException.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-xml/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/DuplicateReferenceException.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-xml/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/DuplicateResourceException.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-xml/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/EagerInitProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-xml/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/HeuristicPojoProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-xml/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/IllegalCallbackReferenceException.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-xml/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/IllegalContextException.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-xml/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/IllegalDestructorException.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-xml/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/IllegalInitException.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-xml/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/IllegalReferenceException.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-xml/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/IllegalResourceException.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-xml/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/IllegalServiceDefinitionException.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-xml/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/InitProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-xml/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/InvalidConstructorException.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-xml/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/InvalidConversationalImplementation.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-xml/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/InvalidPropertyException.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-xml/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/InvalidReferenceException.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-xml/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/InvalidResourceException.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-xml/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/InvalidServiceType.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-xml/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/JavaIntrospectionHelper.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-xml/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/NoConstructorException.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-xml/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/PolicyProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-xml/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/PropertyProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-xml/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ReferenceProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-xml/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ResourceProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-xml/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ScopeProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-xml/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ServiceProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-xml/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ServiceTypeNotFoundException.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-xml/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/UnknownContextTypeException.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-xml/src/main/java/org/apache/tuscany/sca/implementation/java/xml/JavaImplementationConstants.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-xml/src/main/java/org/apache/tuscany/sca/implementation/java/xml/JavaImplementationProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-xml/src/test/java/calculator/AddService.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-xml/src/test/java/calculator/AddServiceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-xml/src/test/java/calculator/CalculatorService.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-xml/src/test/java/calculator/CalculatorServiceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-xml/src/test/java/calculator/DivideService.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-xml/src/test/java/calculator/DivideServiceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-xml/src/test/java/calculator/MultiplyService.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-xml/src/test/java/calculator/MultiplyServiceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-xml/src/test/java/calculator/SubtractService.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-xml/src/test/java/calculator/SubtractServiceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/DefaultJavaClassIntrospectorTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/AbstractProcessorTest.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/AbstractPropertyProcessorTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/AllowsPassByReferenceProcessorTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConstructorProcessorTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConstructorPropertyTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConstructorReferenceTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConstructorResourceTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ContextProcessorTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConversationProcessorTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConvertTimeMillisTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/DestroyProcessorTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/EagerInitProcessorTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/HeuristicAndPropertyTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/HeuristicConstructorTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/HeuristicPojoProcessorTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/HeutisticExtensibleConstructorTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/InitProcessorTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ModelHelper.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/PolicyProcessorTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/PropertyProcessorTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ReferenceProcessorTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ResourceProcessorTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ScopeProcessorTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ServiceCallbackTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ServiceProcessorTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/xml/ReadTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/xml/TestModelResolver.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/xml/WriteTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java-xml/src/test/resources/org/apache/tuscany/sca/implementation/java/xml/Calculator.composite create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java/.checkstyle create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java/.pmd create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java/.ruleset create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java/DISCLAIMER create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/BaseJavaImplementation.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/DefaultJavaImplementationFactory.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/JavaImplementation.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/JavaImplementationFactory.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/impl/BaseJavaImplementationImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/impl/JavaConstructorImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/impl/JavaElementImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/impl/JavaImplementationFactoryImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/impl/JavaImplementationImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/impl/JavaParameterImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/impl/JavaResourceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/impl/JavaScopeImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-resource/DISCLAIMER create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-resource/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-resource/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-resource/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-resource/src/main/java/org/apache/tuscany/sca/binding/resource/DefaultHTTPResourceBindingFactory.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-resource/src/main/java/org/apache/tuscany/sca/binding/resource/HTTPResourceBinding.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-resource/src/main/java/org/apache/tuscany/sca/binding/resource/HTTPResourceBindingFactory.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-resource/src/main/java/org/apache/tuscany/sca/binding/resource/impl/HTTPResourceBindingImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-resource/src/main/java/org/apache/tuscany/sca/binding/resource/impl/HTTPResourceBindingProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-resource/src/main/java/org/apache/tuscany/sca/binding/resource/provider/HTTPResourceBindingProviderFactory.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-resource/src/main/java/org/apache/tuscany/sca/binding/resource/provider/HTTPResourceServiceBindingProvider.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-resource/src/main/java/org/apache/tuscany/sca/implementation/resource/DefaultResourceImplementationFactory.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-resource/src/main/java/org/apache/tuscany/sca/implementation/resource/Resource.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-resource/src/main/java/org/apache/tuscany/sca/implementation/resource/ResourceImplementation.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-resource/src/main/java/org/apache/tuscany/sca/implementation/resource/ResourceImplementationFactory.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-resource/src/main/java/org/apache/tuscany/sca/implementation/resource/impl/ResourceImplementationImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-resource/src/main/java/org/apache/tuscany/sca/implementation/resource/impl/ResourceImplementationProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-resource/src/main/java/org/apache/tuscany/sca/implementation/resource/module/ResourceImplementationModuleActivator.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-resource/src/main/java/org/apache/tuscany/sca/implementation/resource/provider/ResourceImplementationProvider.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-resource/src/main/java/org/apache/tuscany/sca/implementation/resource/provider/ResourceImplementationProviderFactory.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-resource/src/main/java/org/apache/tuscany/sca/implementation/resource/provider/ResourceInvoker.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-resource/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-resource/src/test/java/org/apache/tuscany/sca/implementation/resource/ResourceImplementationTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-resource/src/test/resources/content/test.html create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-resource/src/test/resources/resource.composite create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-script/DISCLAIMER create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-script/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-script/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-script/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-script/src/main/java/org/apache/tuscany/sca/implementation/script/ScriptImplementation.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-script/src/main/java/org/apache/tuscany/sca/implementation/script/ScriptImplementationActivator.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-script/src/main/java/org/apache/tuscany/sca/implementation/script/ScriptInvoker.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-script/src/main/java/org/apache/tuscany/sca/implementation/script/ScriptInvokerFactory.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-script/src/main/java/org/apache/tuscany/sca/implementation/script/engines/TuscanyJRubyScriptEngine.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-script/src/main/resources/META-INF/services/org.apache.tuscany.sca.spi.ImplementationActivator create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-script/src/test/java/org/apache/tuscany/sca/implementation/script/itests/AbstractSCATestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-script/src/test/java/org/apache/tuscany/sca/implementation/script/itests/dynamic/AbstractHelloWorldTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-script/src/test/java/org/apache/tuscany/sca/implementation/script/itests/dynamic/HelloWorld.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-script/src/test/java/org/apache/tuscany/sca/implementation/script/itests/dynamic/JavaScriptDynamicRefTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-script/src/test/java/org/apache/tuscany/sca/implementation/script/itests/dynamic/JavaScriptHelloWorldTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-script/src/test/java/org/apache/tuscany/sca/implementation/script/itests/helloworld/AbstractHelloWorldTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-script/src/test/java/org/apache/tuscany/sca/implementation/script/itests/helloworld/GroovyHelloWorldTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-script/src/test/java/org/apache/tuscany/sca/implementation/script/itests/helloworld/HelloWorld.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-script/src/test/java/org/apache/tuscany/sca/implementation/script/itests/helloworld/HelloWorldProxy.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-script/src/test/java/org/apache/tuscany/sca/implementation/script/itests/helloworld/JRubyHelloWorldTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-script/src/test/java/org/apache/tuscany/sca/implementation/script/itests/helloworld/JavaScripInlineHelloWorldTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-script/src/test/java/org/apache/tuscany/sca/implementation/script/itests/helloworld/JavaScriptHelloWorldTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-script/src/test/java/org/apache/tuscany/sca/implementation/script/itests/helloworld/JythonHelloWorldTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-script/src/test/java/org/apache/tuscany/sca/implementation/script/itests/properties/AbstractHelloWorldTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-script/src/test/java/org/apache/tuscany/sca/implementation/script/itests/properties/GroovyHelloWorldTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-script/src/test/java/org/apache/tuscany/sca/implementation/script/itests/properties/HelloWorld.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-script/src/test/java/org/apache/tuscany/sca/implementation/script/itests/properties/HelloWorldProxy.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-script/src/test/java/org/apache/tuscany/sca/implementation/script/itests/properties/JRubyHelloWorldTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-script/src/test/java/org/apache/tuscany/sca/implementation/script/itests/properties/JavaScriptHelloWorldTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-script/src/test/java/org/apache/tuscany/sca/implementation/script/itests/properties/JythonHelloWorldTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-script/src/test/java/org/apache/tuscany/sca/implementation/script/itests/references/GroovyReferenceTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-script/src/test/java/org/apache/tuscany/sca/implementation/script/itests/references/HelloWorldTarget.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-script/src/test/java/org/apache/tuscany/sca/implementation/script/itests/references/JRubyReferenceTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-script/src/test/java/org/apache/tuscany/sca/implementation/script/itests/references/JavaScriptReferenceTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-script/src/test/java/org/apache/tuscany/sca/implementation/script/itests/references/JythonReferenceTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/dynamic/JavaScriptDynamicRef.composite create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/dynamic/JavaScriptHelloWorld.composite create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/dynamic/helloworld.js create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/dynamic/helloworldProxy.js create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/helloworld/GroovyHelloWorld.composite create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/helloworld/JRubyHelloWorld.composite create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/helloworld/JavaScripInlineHelloWorld.composite create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/helloworld/JavaScriptHelloWorld.composite create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/helloworld/JythonHelloWorld.composite create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/helloworld/helloworld.componentType create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/helloworld/helloworld.groovy create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/helloworld/helloworld.js create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/helloworld/helloworld.py create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/helloworld/helloworld.rb create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/properties/GroovyHelloWorld.composite create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/properties/JRubyHelloWorld.composite create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/properties/JavaScriptHelloWorld.composite create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/properties/JythonHelloWorld.composite create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/properties/helloworld.componentType create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/properties/helloworld.groovy create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/properties/helloworld.js create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/properties/helloworld.py create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/properties/helloworld.rb create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/references/GroovyReference.composite create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/references/JRubyReference.composite create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/references/JavaScriptReference.composite create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/references/JythonReference.composite create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/references/reference.componentType create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/references/reference.groovy create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/references/reference.js create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/references/reference.py create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-script/src/test/resources/org/apache/tuscany/sca/implementation/script/itests/references/reference.rb create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-spring/.ruleset create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-spring/DISCLAIMER create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-spring/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-spring/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-spring/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-spring/src/main/java/org/apache/tuscany/implementation/spring/SCAApplicationContext.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-spring/src/main/java/org/apache/tuscany/implementation/spring/SCANamespaceHandlerResolver.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-spring/src/main/java/org/apache/tuscany/implementation/spring/SCAParentApplicationContext.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-spring/src/main/java/org/apache/tuscany/implementation/spring/ScaNamespaceHandler.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-spring/src/main/java/org/apache/tuscany/implementation/spring/ScaPropertyBeanDefinitionParser.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-spring/src/main/java/org/apache/tuscany/implementation/spring/ScaReferenceBeanDefinitionParser.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-spring/src/main/java/org/apache/tuscany/implementation/spring/ScaServiceBeanDefinitionParser.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-spring/src/main/java/org/apache/tuscany/implementation/spring/SpringArtifactProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-spring/src/main/java/org/apache/tuscany/implementation/spring/SpringBeanNotFoundException.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-spring/src/main/java/org/apache/tuscany/implementation/spring/SpringImplementation.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-spring/src/main/java/org/apache/tuscany/implementation/spring/SpringImplementationProvider.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-spring/src/main/java/org/apache/tuscany/implementation/spring/SpringImplementationProviderFactory.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-spring/src/main/java/org/apache/tuscany/implementation/spring/SpringInvocationException.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-spring/src/main/java/org/apache/tuscany/implementation/spring/SpringInvoker.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-spring/src/main/java/org/apache/tuscany/implementation/spring/SpringModuleActivator.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-spring/src/main/java/org/apache/tuscany/implementation/spring/SpringOperationNotFoundException.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-spring/src/main/java/org/apache/tuscany/implementation/spring/SpringPropertyValueObjectFactory.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-spring/src/main/java/org/apache/tuscany/implementation/spring/xml/SpringBeanElement.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-spring/src/main/java/org/apache/tuscany/implementation/spring/xml/SpringBeanIntrospector.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-spring/src/main/java/org/apache/tuscany/implementation/spring/xml/SpringPropertyElement.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-spring/src/main/java/org/apache/tuscany/implementation/spring/xml/SpringSCAPropertyElement.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-spring/src/main/java/org/apache/tuscany/implementation/spring/xml/SpringSCAReferenceElement.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-spring/src/main/java/org/apache/tuscany/implementation/spring/xml/SpringSCAServiceElement.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-spring/src/main/java/org/apache/tuscany/implementation/spring/xml/SpringXMLComponentTypeLoader.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-spring/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-spring/src/main/resources/META-INF/spring.handlers create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-spring/src/main/resources/META-INF/spring.schemas create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-spring/src/main/resources/org/springframework/sca/xml/spring-sca.xsd create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-spring/src/test/java/org/apache/tuscany/implementation/spring/itests/AbstractSCATestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-spring/src/test/java/org/apache/tuscany/implementation/spring/itests/helloworld/AbstractHelloWorldTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-spring/src/test/java/org/apache/tuscany/implementation/spring/itests/helloworld/HelloWorld.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-spring/src/test/java/org/apache/tuscany/implementation/spring/itests/helloworld/HelloWorldImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-spring/src/test/java/org/apache/tuscany/implementation/spring/itests/helloworld/HelloWorldProxy.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-spring/src/test/java/org/apache/tuscany/implementation/spring/itests/helloworld/SpringExplicitHelloWorldTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-spring/src/test/java/org/apache/tuscany/implementation/spring/itests/helloworld/SpringExplicitReferenceTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-spring/src/test/java/org/apache/tuscany/implementation/spring/itests/helloworld/SpringHelloWorldTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-spring/src/test/java/org/apache/tuscany/implementation/spring/itests/helloworld/SpringImplicitReferenceTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-spring/src/test/java/org/apache/tuscany/implementation/spring/itests/helloworld/SpringSCAPropertyTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-spring/src/test/java/org/apache/tuscany/implementation/spring/itests/mock/TestBean.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-spring/src/test/java/org/apache/tuscany/implementation/spring/itests/mock/TestBeanImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-spring/src/test/java/org/apache/tuscany/implementation/spring/itests/mock/TestHelloWorldBean.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-spring/src/test/java/org/apache/tuscany/implementation/spring/itests/mock/TestReference.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-spring/src/test/java/org/apache/tuscany/implementation/spring/itests/mock/TestReferenceBean.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-spring/src/test/java/org/apache/tuscany/implementation/spring/itests/mock/TestSCAPropertyBean.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-spring/src/test/resources/META-INF/sca/SpringExplicitHelloWorld-context.xml create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-spring/src/test/resources/META-INF/sca/SpringExplicitReference-context.xml create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-spring/src/test/resources/META-INF/sca/SpringHelloWorld-context.xml create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-spring/src/test/resources/META-INF/sca/SpringImplicitReference-context.xml create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-spring/src/test/resources/META-INF/sca/SpringSCAProperty-context.xml create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-spring/src/test/resources/META-INF/sca/testReferenceContext.xml create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-spring/src/test/resources/META-INF/sca/testServiceContext.xml create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-spring/src/test/resources/org/apache/tuscany/implementation/spring/itests/helloworld/SpringExplicitHelloWorld.composite create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-spring/src/test/resources/org/apache/tuscany/implementation/spring/itests/helloworld/SpringExplicitReference.composite create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-spring/src/test/resources/org/apache/tuscany/implementation/spring/itests/helloworld/SpringHelloWorld.composite create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-spring/src/test/resources/org/apache/tuscany/implementation/spring/itests/helloworld/SpringImplicitReference.composite create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-spring/src/test/resources/org/apache/tuscany/implementation/spring/itests/helloworld/SpringSCAProperty.composite create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/implementation-spring/src/test/resources/test.xml create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface-java-runtime/DISCLAIMER create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface-java-runtime/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface-java-runtime/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface-java-runtime/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface-java-runtime/src/main/java/org/apache/tuscany/sca/interfacedef/java/module/JavaInterfaceRuntimeModuleActivator.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface-java-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface-java-xml/.checkstyle create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface-java-xml/.pmd create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface-java-xml/.ruleset create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface-java-xml/DISCLAIMER create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface-java-xml/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface-java-xml/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface-java-xml/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface-java-xml/src/main/java/org/apache/tuscany/sca/interfacedef/java/introspect/DefaultJavaInterfaceIntrospectorExtensionPoint.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface-java-xml/src/main/java/org/apache/tuscany/sca/interfacedef/java/introspect/ExtensibleJavaInterfaceIntrospector.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface-java-xml/src/main/java/org/apache/tuscany/sca/interfacedef/java/introspect/JavaInterfaceIntrospector.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface-java-xml/src/main/java/org/apache/tuscany/sca/interfacedef/java/introspect/JavaInterfaceIntrospectorExtensionPoint.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface-java-xml/src/main/java/org/apache/tuscany/sca/interfacedef/java/introspect/JavaInterfaceVisitor.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface-java-xml/src/main/java/org/apache/tuscany/sca/interfacedef/java/xml/JavaConstants.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface-java-xml/src/main/java/org/apache/tuscany/sca/interfacedef/java/xml/JavaInterfaceProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface-java-xml/src/test/java/org/apache/tuscany/sca/interfacedef/java/introspection/impl/ConversationalIntrospectionTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface-java-xml/src/test/java/org/apache/tuscany/sca/interfacedef/java/introspection/impl/JavaInterfaceProcessorRegistryImplTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface-java-xml/src/test/java/org/apache/tuscany/sca/interfacedef/java/xml/ReadTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface-java-xml/src/test/java/org/apache/tuscany/sca/interfacedef/java/xml/WriteTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface-java-xml/src/test/resources/org/apache/tuscany/sca/interfacedef/java/xml/Calculator.composite create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface-java-xml/src/test/resources/org/apache/tuscany/sca/interfacedef/java/xml/CalculatorComponent.constrainingType create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface-java-xml/src/test/resources/org/apache/tuscany/sca/interfacedef/java/xml/CalculatorImpl.componentType create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface-java/.checkstyle create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface-java/.pmd create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface-java/.ruleset create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface-java/DISCLAIMER create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface-java/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface-java/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface-java/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/DefaultJavaInterfaceFactory.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/JavaInterface.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/JavaInterfaceContract.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/JavaInterfaceFactory.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceContractImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceFactoryImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceUtil.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface-java/src/test/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceUtilTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface-wsdl-runtime/DISCLAIMER create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface-wsdl-runtime/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface-wsdl-runtime/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface-wsdl-runtime/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface-wsdl-runtime/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/module/WSDLInterfaceRuntimeModuleActivator.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface-wsdl-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface-wsdl-xml/.checkstyle create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface-wsdl-xml/.pmd create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface-wsdl-xml/.ruleset create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface-wsdl-xml/DISCLAIMER create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface-wsdl-xml/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface-wsdl-xml/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface-wsdl-xml/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface-wsdl-xml/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/introspect/DefaultWSDLInterfaceIntrospector.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface-wsdl-xml/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/introspect/InvalidWSDLException.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface-wsdl-xml/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/introspect/WSDLInterfaceIntrospector.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface-wsdl-xml/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/introspect/WSDLOperation.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface-wsdl-xml/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLConstants.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface-wsdl-xml/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLDocumentProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface-wsdl-xml/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLInterfaceProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface-wsdl-xml/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/XSDDocumentProcessor.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface-wsdl-xml/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/introspect/DefaultWSDLInterfaceIntrospectorTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface-wsdl-xml/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/introspect/TestModelResolver.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface-wsdl-xml/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/introspect/WSDLOperationTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface-wsdl-xml/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/introspect/WrapperStyleOperationTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface-wsdl-xml/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/ReadTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface-wsdl-xml/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WSDLTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface-wsdl-xml/src/test/java/org/apache/tuscany/sca/interfacedef/wsdl/xml/WriteTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface-wsdl-xml/src/test/resources/org/apache/tuscany/sca/interfacedef/wsdl/xml/Calculator.composite create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface-wsdl-xml/src/test/resources/org/apache/tuscany/sca/interfacedef/wsdl/xml/CalculatorComponent.constrainingType create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface-wsdl-xml/src/test/resources/org/apache/tuscany/sca/interfacedef/wsdl/xml/CalculatorImpl.componentType create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface-wsdl-xml/src/test/resources/org/apache/tuscany/sca/interfacedef/wsdl/xml/example.wsdl create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface-wsdl-xml/src/test/resources/org/apache/tuscany/sca/interfacedef/wsdl/xml/invalid-stockquote.wsdl create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface-wsdl-xml/src/test/resources/org/apache/tuscany/sca/interfacedef/wsdl/xml/ipo.xsd create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface-wsdl-xml/src/test/resources/org/apache/tuscany/sca/interfacedef/wsdl/xml/stockquote.wsdl create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface-wsdl-xml/src/test/resources/org/apache/tuscany/sca/interfacedef/wsdl/xml/test1.wsdl create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface-wsdl-xml/src/test/resources/org/apache/tuscany/sca/interfacedef/wsdl/xml/test1.xsd create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface-wsdl-xml/src/test/resources/org/apache/tuscany/sca/interfacedef/wsdl/xml/test2.wsdl create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface-wsdl-xml/src/test/resources/org/apache/tuscany/sca/interfacedef/wsdl/xml/unwrapped-stockquote.wsdl create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface-wsdl/.checkstyle create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface-wsdl/.pmd create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface-wsdl/.ruleset create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface-wsdl/DISCLAIMER create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface-wsdl/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface-wsdl/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface-wsdl/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/DefaultWSDLFactory.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/WSDLDefinition.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/WSDLFactory.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/WSDLInterface.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/WSDLInterfaceContract.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/XSDefinition.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/impl/WSDLDefinitionImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/impl/WSDLFactoryImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/impl/WSDLInterfaceContractImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/impl/WSDLInterfaceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface-wsdl/src/main/java/org/apache/tuscany/sca/interfacedef/wsdl/impl/XSDefinitionImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface/.checkstyle create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface/.pmd create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface/.ruleset create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface/DISCLAIMER create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/ConversationSequence.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/DataType.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/IncompatibleInterfaceContractException.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/Interface.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/InterfaceContract.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/InterfaceContractMapper.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/InvalidCallbackException.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/InvalidInterfaceException.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/InvalidOperationException.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/Operation.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/OverloadedOperationException.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/impl/DataTypeImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/impl/InterfaceContractImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/impl/InterfaceContractMapperImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/impl/InterfaceImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/impl/OperationImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/util/ElementInfo.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/util/FaultException.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/util/JavaXMLMapper.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/util/TypeInfo.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/util/WrapperInfo.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/util/XMLType.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/interface/src/test/java/org/apache/tuscany/sca/interfacedef/impl/ContractCompatibilityTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/java2wsdl/DISCLAIMER create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/java2wsdl/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/java2wsdl/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/java2wsdl/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/java2wsdl/src/main/java/org/apache/tuscany/tools/java2wsdl/generate/GenerationParameters.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/java2wsdl/src/main/java/org/apache/tuscany/tools/java2wsdl/generate/Java2WSDL.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/java2wsdl/src/main/java/org/apache/tuscany/tools/java2wsdl/generate/Java2WSDLGenerator.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/java2wsdl/src/main/java/org/apache/tuscany/tools/java2wsdl/generate/Java2WSDLGeneratorFactory.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/java2wsdl/src/main/java/org/apache/tuscany/tools/java2wsdl/generate/Java2WSDLGeneratorImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/java2wsdl/src/main/java/org/apache/tuscany/tools/java2wsdl/generate/SchemaBuilder.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/java2wsdl/src/main/java/org/apache/tuscany/tools/java2wsdl/generate/TuscanyJava2OMBuilder.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/java2wsdl/src/main/java/org/apache/tuscany/tools/java2wsdl/generate/TuscanyJava2WSDLBuilder.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/java2wsdl/src/main/java/org/apache/tuscany/tools/java2wsdl/generate/TuscanyJava2WSDLConstants.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/java2wsdl/src/main/java/org/apache/tuscany/tools/java2wsdl/generate/TuscanyJava2WSDLOptionsValidator.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/java2wsdl/src/main/java/org/apache/tuscany/tools/java2wsdl/generate/TuscanySchemaGenerator.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/java2wsdl/src/main/java/org/apache/tuscany/tools/java2wsdl/generate/TuscanyTypeTable.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/java2wsdl/src/main/java/org/apache/tuscany/tools/java2wsdl/generate/TuscanyWSDLTypesGenerator.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/java2wsdl/src/main/java/org/apache/tuscany/tools/java2wsdl/generate/WSDLGenEvent.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/java2wsdl/src/main/java/org/apache/tuscany/tools/java2wsdl/generate/WSDLGenListener.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/java2wsdl/src/main/java/org/apache/tuscany/tools/java2wsdl/util/XMLNameUtil.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/java2wsdl/src/main/resources/META-INF/LICENSE.txt create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/java2wsdl/src/main/resources/META-INF/README.txt create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/java2wsdl/src/main/resources/RemotableInterfaceTemplate.xsl create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/java2wsdl/src/test/java/org/apache/tuscany/tools/java2wsdl/generate/CustomerValue.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/java2wsdl/src/test/java/org/apache/tuscany/tools/java2wsdl/generate/CustomerWithAccount.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/java2wsdl/src/test/java/org/apache/tuscany/tools/java2wsdl/generate/TuscanyJava2WSDLTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/java2wsdl/src/test/java/org/apache/tuscany/tools/java2wsdl/generate/account/Account.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/java2wsdl/src/test/java/org/apache/tuscany/tools/java2wsdl/generate/customer/Customer.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/java2wsdl/src/test/java/org/apache/tuscany/tools/java2wsdl/generate/extra/GoldCustomer.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/java2wsdl/src/test/java/org/soapinterop/CreditScoreDocLit.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/java2wsdl/src/test/resources/AccountService.wsdl create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/java2wsdl/src/test/resources/CreditScoreDocLit.wsdl create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/java2wsdl/src/test/resources/helloworld.wsdl create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/java2wsdl/src/test/resources/interopdoc.wsdl create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/java2wsdl/src/test/resources/sequences.xsd create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/maven-java2wsdl/DISCLAIMER create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/maven-java2wsdl/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/maven-java2wsdl/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/maven-java2wsdl/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/maven-java2wsdl/src/main/java/org/apache/tuscany/tools/java2wsdl/plugin/Java2WSDLGeneratorMojo.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/maven-wsdl2java/DISCLAIMER create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/maven-wsdl2java/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/maven-wsdl2java/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/maven-wsdl2java/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/maven-wsdl2java/src/main/java/org/apache/tuscany/tools/wsdl2java/plugin/WSDL2JavaGeneratorMojo.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/maven-wsdl2java/src/main/java/org/apache/tuscany/tools/wsdl2java/plugin/WSDLFileOption.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/policy/DISCLAIMER create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/policy/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/policy/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/policy/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/policy/src/main/java/org/apache/tuscany/sca/policy/DefaultPolicyFactory.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/policy/src/main/java/org/apache/tuscany/sca/policy/Intent.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/policy/src/main/java/org/apache/tuscany/sca/policy/IntentAttachPoint.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/policy/src/main/java/org/apache/tuscany/sca/policy/IntentMap.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/policy/src/main/java/org/apache/tuscany/sca/policy/PolicyFactory.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/policy/src/main/java/org/apache/tuscany/sca/policy/PolicySet.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/policy/src/main/java/org/apache/tuscany/sca/policy/PolicySetAttachPoint.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/IntentImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/IntentMapImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/PolicyFactoryImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/PolicySetImpl.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/policy/src/test/java/org/apache/tuscany/sca/policy/PolicyFactoryTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/sca-api/DISCLAIMER create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/sca-api/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/sca-api/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/sca-api/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/sca-api/src/main/java/org/osoa/sca/CallableReference.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/sca-api/src/main/java/org/osoa/sca/ComponentContext.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/sca-api/src/main/java/org/osoa/sca/Constants.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/sca-api/src/main/java/org/osoa/sca/Conversation.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/sca-api/src/main/java/org/osoa/sca/ConversationEndedException.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/sca-api/src/main/java/org/osoa/sca/NoRegisteredCallbackException.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/sca-api/src/main/java/org/osoa/sca/RequestContext.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/sca-api/src/main/java/org/osoa/sca/ServiceReference.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/sca-api/src/main/java/org/osoa/sca/ServiceRuntimeException.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/sca-api/src/main/java/org/osoa/sca/ServiceUnavailableException.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/sca-api/src/main/java/org/osoa/sca/annotations/AllowsPassByReference.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/sca-api/src/main/java/org/osoa/sca/annotations/Authentication.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/sca-api/src/main/java/org/osoa/sca/annotations/Callback.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/sca-api/src/main/java/org/osoa/sca/annotations/ComponentName.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/sca-api/src/main/java/org/osoa/sca/annotations/Confidentiality.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/sca-api/src/main/java/org/osoa/sca/annotations/Constructor.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/sca-api/src/main/java/org/osoa/sca/annotations/Context.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/sca-api/src/main/java/org/osoa/sca/annotations/ConversationAttributes.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/sca-api/src/main/java/org/osoa/sca/annotations/ConversationID.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/sca-api/src/main/java/org/osoa/sca/annotations/Conversational.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/sca-api/src/main/java/org/osoa/sca/annotations/Destroy.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/sca-api/src/main/java/org/osoa/sca/annotations/EagerInit.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/sca-api/src/main/java/org/osoa/sca/annotations/EndsConversation.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/sca-api/src/main/java/org/osoa/sca/annotations/Init.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/sca-api/src/main/java/org/osoa/sca/annotations/Integrity.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/sca-api/src/main/java/org/osoa/sca/annotations/Intent.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/sca-api/src/main/java/org/osoa/sca/annotations/OneWay.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/sca-api/src/main/java/org/osoa/sca/annotations/PolicySets.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/sca-api/src/main/java/org/osoa/sca/annotations/Property.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/sca-api/src/main/java/org/osoa/sca/annotations/Qualifier.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/sca-api/src/main/java/org/osoa/sca/annotations/Reference.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/sca-api/src/main/java/org/osoa/sca/annotations/Remotable.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/sca-api/src/main/java/org/osoa/sca/annotations/Requires.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/sca-api/src/main/java/org/osoa/sca/annotations/Scope.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/sca-api/src/main/java/org/osoa/sca/annotations/Service.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/wsdl2java/DISCLAIMER create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/wsdl2java/LICENSE create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/wsdl2java/NOTICE create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/wsdl2java/pom.xml create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/wsdl2java/src/main/java/org/apache/tuscany/tools/wsdl2java/generate/JavaInterfaceEmitter.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/wsdl2java/src/main/java/org/apache/tuscany/tools/wsdl2java/generate/JavaInterfaceGenerator.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/wsdl2java/src/main/java/org/apache/tuscany/tools/wsdl2java/generate/RemotableInterfaceWritter.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/wsdl2java/src/main/java/org/apache/tuscany/tools/wsdl2java/generate/SDODataBindingCodegenExtension.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/wsdl2java/src/main/java/org/apache/tuscany/tools/wsdl2java/generate/SDODataBindingTypeMappingEntry.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/wsdl2java/src/main/java/org/apache/tuscany/tools/wsdl2java/generate/WSDL2JavaGenerator.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/wsdl2java/src/main/java/org/apache/tuscany/tools/wsdl2java/util/XMLNameUtil.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/wsdl2java/src/main/resources/META-INF/LICENSE.txt create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/wsdl2java/src/main/resources/META-INF/README.txt create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/wsdl2java/src/main/resources/RemotableInterfaceTemplate.xsl create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/wsdl2java/src/test/java/org/apache/tuscany/tools/wsdl2java/generate/WSDL2JavaGeneratorTestCase.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/wsdl2java/src/test/java/org/soapinterop/CreditScoreDocLit.java create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/wsdl2java/src/test/resources/AccountService.wsdl create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/wsdl2java/src/test/resources/CreditScoreDocLit.wsdl create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/wsdl2java/src/test/resources/helloworld.wsdl create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/wsdl2java/src/test/resources/interopdoc.wsdl create mode 100644 sca-java-1.x/branches/sca-java-0.91/modules/wsdl2java/src/test/resources/sequences.xsd (limited to 'sca-java-1.x/branches/sca-java-0.91/modules') diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly-java-dsl/DISCLAIMER b/sca-java-1.x/branches/sca-java-0.91/modules/assembly-java-dsl/DISCLAIMER new file mode 100644 index 0000000000..d68a410903 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly-java-dsl/DISCLAIMER @@ -0,0 +1,8 @@ +Apache Tuscany is an effort undergoing incubation at The Apache Software +Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is +required of all newly accepted projects until a further review indicates that +the infrastructure, communications, and decision making process have stabilized +in a manner consistent with other successful ASF projects. While incubation +status is not necessarily a reflection of the completeness or stability of the +code, it does indicate that the project has yet to be fully endorsed by the ASF. + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly-java-dsl/LICENSE b/sca-java-1.x/branches/sca-java-0.91/modules/assembly-java-dsl/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/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/sca-java-1.x/branches/sca-java-0.91/modules/assembly-java-dsl/NOTICE b/sca-java-1.x/branches/sca-java-0.91/modules/assembly-java-dsl/NOTICE new file mode 100644 index 0000000000..94481d6cfa --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly-java-dsl/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2007 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly-java-dsl/pom.xml b/sca-java-1.x/branches/sca-java-0.91/modules/assembly-java-dsl/pom.xml new file mode 100644 index 0000000000..16e7260ce2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly-java-dsl/pom.xml @@ -0,0 +1,38 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 0.91-incubating-SNAPSHOT + ../pom.xml + + tuscany-assembly-java-dsl + Apache Tuscany SCA Assembly Java DSL + + + + org.apache.tuscany.sca + tuscany-assembly + 0.91-incubating-SNAPSHOT + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly-java-dsl/src/main/java/org/apache/tuscany/sca/assembly/dsl/AssemblyBuilder.java b/sca-java-1.x/branches/sca-java-0.91/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/sca-java-1.x/branches/sca-java-0.91/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/sca-java-1.x/branches/sca-java-0.91/modules/assembly-java-dsl/src/main/java/org/apache/tuscany/sca/assembly/dsl/ComponentBuilder.java b/sca-java-1.x/branches/sca-java-0.91/modules/assembly-java-dsl/src/main/java/org/apache/tuscany/sca/assembly/dsl/ComponentBuilder.java new file mode 100644 index 0000000000..98f247e5cc --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly-java-dsl/src/main/java/org/apache/tuscany/sca/assembly/dsl/ComponentBuilder.java @@ -0,0 +1,34 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.assembly.dsl; + +public interface ComponentBuilder { + + ComponentBuilder implementedBy(Class clazz); + + ComponentBuilder implementedBy(CompositeBuilder composite); + + public ComponentBuilder uses(ComponentReferenceBuilder... componentReferences); + + public ComponentBuilder provides(ComponentServiceBuilder... componentServices); + + public ComponentBuilder declares(ComponentPropertyBuilder...componentProperties); + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly-java-dsl/src/main/java/org/apache/tuscany/sca/assembly/dsl/ComponentPropertyBuilder.java b/sca-java-1.x/branches/sca-java-0.91/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/sca-java-1.x/branches/sca-java-0.91/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/sca-java-1.x/branches/sca-java-0.91/modules/assembly-java-dsl/src/main/java/org/apache/tuscany/sca/assembly/dsl/ComponentReferenceBuilder.java b/sca-java-1.x/branches/sca-java-0.91/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/sca-java-1.x/branches/sca-java-0.91/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/sca-java-1.x/branches/sca-java-0.91/modules/assembly-java-dsl/src/main/java/org/apache/tuscany/sca/assembly/dsl/ComponentServiceBuilder.java b/sca-java-1.x/branches/sca-java-0.91/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/sca-java-1.x/branches/sca-java-0.91/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/sca-java-1.x/branches/sca-java-0.91/modules/assembly-java-dsl/src/main/java/org/apache/tuscany/sca/assembly/dsl/CompositeBuilder.java b/sca-java-1.x/branches/sca-java-0.91/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/sca-java-1.x/branches/sca-java-0.91/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/sca-java-1.x/branches/sca-java-0.91/modules/assembly-java-dsl/src/main/java/org/apache/tuscany/sca/assembly/dsl/impl/AssemblyBuilderImpl.java b/sca-java-1.x/branches/sca-java-0.91/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/sca-java-1.x/branches/sca-java-0.91/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/sca-java-1.x/branches/sca-java-0.91/modules/assembly-java-dsl/src/main/java/org/apache/tuscany/sca/assembly/dsl/impl/ComponentBuilderImpl.java b/sca-java-1.x/branches/sca-java-0.91/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/sca-java-1.x/branches/sca-java-0.91/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/sca-java-1.x/branches/sca-java-0.91/modules/assembly-java-dsl/src/main/java/org/apache/tuscany/sca/assembly/dsl/impl/ComponentPropertyBuilderImpl.java b/sca-java-1.x/branches/sca-java-0.91/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/sca-java-1.x/branches/sca-java-0.91/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/sca-java-1.x/branches/sca-java-0.91/modules/assembly-java-dsl/src/main/java/org/apache/tuscany/sca/assembly/dsl/impl/ComponentReferenceBuilderImpl.java b/sca-java-1.x/branches/sca-java-0.91/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/sca-java-1.x/branches/sca-java-0.91/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/sca-java-1.x/branches/sca-java-0.91/modules/assembly-java-dsl/src/main/java/org/apache/tuscany/sca/assembly/dsl/impl/ComponentServiceBuilderImpl.java b/sca-java-1.x/branches/sca-java-0.91/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/sca-java-1.x/branches/sca-java-0.91/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/sca-java-1.x/branches/sca-java-0.91/modules/assembly-java-dsl/src/main/java/org/apache/tuscany/sca/assembly/dsl/impl/CompositeBuilderImpl.java b/sca-java-1.x/branches/sca-java-0.91/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/sca-java-1.x/branches/sca-java-0.91/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/sca-java-1.x/branches/sca-java-0.91/modules/assembly-java-dsl/src/test/java/org/apache/tuscany/sca/assembly/dsl/AccountDataService.java b/sca-java-1.x/branches/sca-java-0.91/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/sca-java-1.x/branches/sca-java-0.91/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/sca-java-1.x/branches/sca-java-0.91/modules/assembly-java-dsl/src/test/java/org/apache/tuscany/sca/assembly/dsl/AccountDataServiceImpl.java b/sca-java-1.x/branches/sca-java-0.91/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/sca-java-1.x/branches/sca-java-0.91/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/sca-java-1.x/branches/sca-java-0.91/modules/assembly-java-dsl/src/test/java/org/apache/tuscany/sca/assembly/dsl/AccountService.java b/sca-java-1.x/branches/sca-java-0.91/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/sca-java-1.x/branches/sca-java-0.91/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/sca-java-1.x/branches/sca-java-0.91/modules/assembly-java-dsl/src/test/java/org/apache/tuscany/sca/assembly/dsl/AccountServiceImpl.java b/sca-java-1.x/branches/sca-java-0.91/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/sca-java-1.x/branches/sca-java-0.91/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/sca-java-1.x/branches/sca-java-0.91/modules/assembly-java-dsl/src/test/java/org/apache/tuscany/sca/assembly/dsl/BigBankBuilder.java b/sca-java-1.x/branches/sca-java-0.91/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/sca-java-1.x/branches/sca-java-0.91/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/sca-java-1.x/branches/sca-java-0.91/modules/assembly-java-dsl/src/test/java/org/apache/tuscany/sca/assembly/dsl/BigBankBuilderTestCase.java b/sca-java-1.x/branches/sca-java-0.91/modules/assembly-java-dsl/src/test/java/org/apache/tuscany/sca/assembly/dsl/BigBankBuilderTestCase.java new file mode 100644 index 0000000000..90a4292546 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly-java-dsl/src/test/java/org/apache/tuscany/sca/assembly/dsl/BigBankBuilderTestCase.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.assembly.dsl; + +import junit.framework.TestCase; + +public class BigBankBuilderTestCase extends TestCase { + + public void testBuild() throws Exception { + + BigBankBuilder builder = new BigBankBuilder(); + CompositeBuilder domain = builder.build(); + assertNotNull(domain); + + //System.out.println(); + //new PrintUtil(System.out).print(domain); + //System.out.println(); + + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly-java-dsl/src/test/java/org/apache/tuscany/sca/assembly/dsl/StockQuoteService.java b/sca-java-1.x/branches/sca-java-0.91/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/sca-java-1.x/branches/sca-java-0.91/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/sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/.checkstyle b/sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/.checkstyle new file mode 100644 index 0000000000..3e57539570 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/.checkstyle @@ -0,0 +1,24 @@ + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/.pmd b/sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/.pmd new file mode 100644 index 0000000000..2db10d6a6a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/.pmd @@ -0,0 +1,20 @@ + + +truefalse \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/.ruleset b/sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/.ruleset new file mode 100644 index 0000000000..830b4cfee4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/.ruleset @@ -0,0 +1,190 @@ + + + + PMD Plugin preferences rule set + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/DISCLAIMER b/sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/DISCLAIMER new file mode 100644 index 0000000000..d68a410903 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/DISCLAIMER @@ -0,0 +1,8 @@ +Apache Tuscany is an effort undergoing incubation at The Apache Software +Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is +required of all newly accepted projects until a further review indicates that +the infrastructure, communications, and decision making process have stabilized +in a manner consistent with other successful ASF projects. While incubation +status is not necessarily a reflection of the completeness or stability of the +code, it does indicate that the project has yet to be fully endorsed by the ASF. + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/LICENSE b/sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/NOTICE b/sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/NOTICE new file mode 100644 index 0000000000..94481d6cfa --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2007 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/pom.xml b/sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/pom.xml new file mode 100644 index 0000000000..e217368d96 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/pom.xml @@ -0,0 +1,58 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 0.91-incubating-SNAPSHOT + ../pom.xml + + tuscany-assembly-xml + Apache Tuscany SCA XML Assembly Support + + + + org.apache.tuscany.sca + tuscany-assembly + 0.91-incubating-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-contribution + 0.91-incubating-SNAPSHOT + + + + stax + stax-api + 1.0.1 + + + + org.codehaus.woodstox + wstx-asl + 3.2.0 + runtime + + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/BaseArtifactProcessor.java b/sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/BaseArtifactProcessor.java new file mode 100644 index 0000000000..9223fa8947 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/BaseArtifactProcessor.java @@ -0,0 +1,686 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.assembly.xml; + +import static javax.xml.XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI; +import static javax.xml.XMLConstants.XMLNS_ATTRIBUTE_NS_URI; +import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; +import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.StringTokenizer; + +import javax.xml.XMLConstants; +import javax.xml.namespace.QName; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.stream.XMLStreamConstants; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.assembly.AbstractContract; +import org.apache.tuscany.sca.assembly.AbstractProperty; +import org.apache.tuscany.sca.assembly.AbstractReference; +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.ComponentService; +import org.apache.tuscany.sca.assembly.ComponentType; +import org.apache.tuscany.sca.assembly.ConstrainingType; +import org.apache.tuscany.sca.assembly.Contract; +import org.apache.tuscany.sca.assembly.Implementation; +import org.apache.tuscany.sca.assembly.Multiplicity; +import org.apache.tuscany.sca.assembly.Property; +import org.apache.tuscany.sca.assembly.Reference; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.contribution.service.ContributionResolveException; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.policy.Intent; +import org.apache.tuscany.sca.policy.IntentAttachPoint; +import org.apache.tuscany.sca.policy.PolicyFactory; +import org.apache.tuscany.sca.policy.PolicySet; +import org.apache.tuscany.sca.policy.PolicySetAttachPoint; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NamedNodeMap; +import org.w3c.dom.Node; + +/** + * A base class with utility methods for the other artifact processors in this module. + * + * @version $Rev$ $Date$ + */ +abstract class BaseArtifactProcessor implements Constants { + + protected AssemblyFactory assemblyFactory; + protected PolicyFactory policyFactory; + protected StAXArtifactProcessor extensionProcessor; + + private static final DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance(); + static { + domFactory.setNamespaceAware(true); + } + + /** + * Construcst a new BaseArtifactProcessor. + * @param factory + * @param policyFactory + */ + @SuppressWarnings("unchecked") + public BaseArtifactProcessor(AssemblyFactory factory, PolicyFactory policyFactory, StAXArtifactProcessor extensionProcessor) { + this.assemblyFactory = factory; + this.policyFactory = policyFactory; + this.extensionProcessor = (StAXArtifactProcessor)extensionProcessor; + } + + /** + * Returns the string value of an attribute. + * @param reader + * @param name + * @return + */ + protected String getString(XMLStreamReader reader, String name) { + return reader.getAttributeValue(null, name); + } + + /** + * Returns the qname value of an attribute. + * @param reader + * @param name + * @return + */ + protected QName getQName(XMLStreamReader reader, String name) { + String qname = reader.getAttributeValue(null, name); + return getQNameValue(reader, qname); + } + + /** + * Returns the value of xsi:type attribute + * @param reader The XML stream reader + * @return The QName of the type, if the attribute is not present, null is + * returned. + */ + protected QName getXSIType(XMLStreamReader reader) { + String qname = reader.getAttributeValue(XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI, "type"); + return getQNameValue(reader, qname); + } + + /** + * Returns a qname from a string. + * @param reader + * @param value + * @return + */ + protected QName getQNameValue(XMLStreamReader reader, String value) { + if (value != null) { + int index = value.indexOf(':'); + String prefix = index == -1 ? "" : value.substring(0, index); + String localName = index == -1 ? value : value.substring(index + 1); + String ns = reader.getNamespaceContext().getNamespaceURI(prefix); + if (ns == null) { + ns = ""; + } + return new QName(ns, localName, prefix); + } else { + return null; + } + } + + /** + * Returns the boolean value of an attribute. + * @param reader + * @param name + * @return + */ + protected boolean getBoolean(XMLStreamReader reader, String name) { + String value = reader.getAttributeValue(null, name); + if (value == null) { + value = Boolean.toString(false); + } + return Boolean.valueOf(value); + } + + /** + * Returns the value of an attribute as a list of qnames. + * @param reader + * @param name + * @return + */ + protected List getQNames(XMLStreamReader reader, String name) { + String value = reader.getAttributeValue(null, name); + if (value != null) { + List qnames = new ArrayList(); + for (StringTokenizer tokens = new StringTokenizer(value); tokens.hasMoreTokens();) { + qnames.add(getQName(reader, tokens.nextToken())); + } + return qnames; + } else { + return Collections.emptyList(); + } + } + + /** + * Read policy intents. + * @param attachPoint + * @param reader + */ + protected void readIntents(IntentAttachPoint attachPoint, XMLStreamReader reader) { + readIntents(attachPoint, null, reader); + } + + /** + * Read policy intents associated with an operation. + * @param attachPoint + * @param operation + * @param reader + */ + protected void readIntents(IntentAttachPoint attachPoint, Operation operation, XMLStreamReader reader) { + String value = reader.getAttributeValue(null, Constants.REQUIRES); + if (value != null) { + List requiredIntents = attachPoint.getRequiredIntents(); + for (StringTokenizer tokens = new StringTokenizer(value); tokens.hasMoreTokens();) { + QName qname = getQNameValue(reader, tokens.nextToken()); + Intent intent = policyFactory.createIntent(); + intent.setName(qname); + if (operation != null) { + intent.getOperations().add(operation); + } + requiredIntents.add(intent); + } + } + } + + /** + * Reads policy intents and policy sets. + * @param attachPoint + * @param reader + */ + protected void readPolicies(PolicySetAttachPoint attachPoint, XMLStreamReader reader) { + readPolicies(attachPoint, null, reader); + } + + /** + * Reads policy intents and policy sets associated with an operation. + * @param attachPoint + * @param operation + * @param reader + */ + protected void readPolicies(PolicySetAttachPoint attachPoint, Operation operation, XMLStreamReader reader) { + readIntents(attachPoint, operation, reader); + + String value = reader.getAttributeValue(null, Constants.POLICY_SETS); + if (value != null) { + List policySets = attachPoint.getPolicySets(); + for (StringTokenizer tokens = new StringTokenizer(value); tokens.hasMoreTokens();) { + QName qname = getQNameValue(reader, tokens.nextToken()); + PolicySet policySet = policyFactory.createPolicySet(); + policySet.setName(qname); + if (operation != null) { + policySet.getOperations().add(operation); + } + policySets.add(policySet); + } + } + } + + /** + * Read list of reference targets + * @param reference + * @param reader + */ + protected void readTargets(Reference reference, XMLStreamReader reader) { + String value = reader.getAttributeValue(null, Constants.TARGET); + ComponentService target = null; + if (value != null) { + for (StringTokenizer tokens = new StringTokenizer(value); tokens.hasMoreTokens();) { + target = assemblyFactory.createComponentService(); + target.setUnresolved(true); + target.setName(tokens.nextToken()); + reference.getTargets().add(target); + } + } + } + + /** + * Read a multiplicity attribute. + * @param reference + * @param reader + */ + protected void readMultiplicity(AbstractReference reference, XMLStreamReader reader) { + String value = reader.getAttributeValue(null, MULTIPLICITY); + if (ZERO_ONE.equals(value)) { + reference.setMultiplicity(Multiplicity.ZERO_ONE); + } else if (ONE_N.equals(value)) { + reference.setMultiplicity(Multiplicity.ONE_N); + } else if (ZERO_N.equals(value)) { + reference.setMultiplicity(Multiplicity.ZERO_N); + } + } + + /** + * Returns the value of a constrainingType attribute. + * @param reader + * @return + */ + protected ConstrainingType getConstrainingType(XMLStreamReader reader) { + QName constrainingTypeName = getQName(reader, "constrainingType"); + if (constrainingTypeName != null) { + ConstrainingType constrainingType = assemblyFactory.createConstrainingType(); + constrainingType.setName(constrainingTypeName); + constrainingType.setUnresolved(true); + return constrainingType; + } else { + return null; + } + } + + /** + * Reads an abstract property element. + * @param prop + * @param reader + * @throws XMLStreamException + * @throws ContributionReadException + */ + protected void readAbstractProperty(AbstractProperty prop, XMLStreamReader reader) + throws XMLStreamException, ContributionReadException { + prop.setName(getString(reader, "name")); + prop.setMany(getBoolean(reader, "many")); + prop.setMustSupply(getBoolean(reader, "mustSupply")); + prop.setXSDElement(getQName(reader, "element")); + prop.setXSDType(getQName(reader, "type")); + try { + Document value = readPropertyValue(reader, prop.getXSDType()); + prop.setValue(value); + } catch (ParserConfigurationException e) { + throw new ContributionReadException(e); + } + } + + /** + * Reads a property element. + * @param prop + * @param reader + * @throws XMLStreamException + * @throws ContributionReadException + */ + protected void readProperty(Property prop, XMLStreamReader reader) + throws XMLStreamException, ContributionReadException { + readAbstractProperty(prop, reader); + } + + /** + * Parse the next child element. + * @param reader + * @return + * @throws XMLStreamException + */ + protected boolean nextChildElement(XMLStreamReader reader) throws XMLStreamException { + while (reader.hasNext()) { + int event = reader.next(); + if (event == END_ELEMENT) { + return false; + } + if (event == START_ELEMENT) { + return true; + } + } + return false; + } + + /** + * Advance the stream to the next END_ELEMENT event skipping any nested + * content. + * @param reader the reader to advance + * @throws XMLStreamException if there was a problem reading the stream + */ + protected void skipToEndElement(XMLStreamReader reader) throws XMLStreamException { + int depth = 0; + while (reader.hasNext()) { + int event = reader.next(); + if (event == XMLStreamConstants.START_ELEMENT) { + depth++; + } else if (event == XMLStreamConstants.END_ELEMENT) { + if (depth == 0) { + return; + } + depth--; + } + } + } + + /** + * Resolve an implementation. + * @param implementation + * @param resolver + * @return + * @throws ContributionResolveException + */ + protected Implementation resolveImplementation(Implementation implementation, ModelResolver resolver) throws ContributionResolveException { + if (implementation != null) { + if (implementation.isUnresolved()) { + implementation = resolver.resolveModel(Implementation.class, implementation); + + // Lazily resolve implementations + if (implementation.isUnresolved()) { + extensionProcessor.resolve(implementation, resolver); + if (!implementation.isUnresolved()) { + resolver.addModel(implementation); + } + } + } + } + return implementation; + } + + /** + * Resolve interface, callback interface and bindings on a list of contracts. + * @param contracts the list of contracts + * @param resolver the resolver to use to resolve models + */ + protected void resolveContracts(List contracts, ModelResolver resolver) throws ContributionResolveException { + for (Contract contract: contracts) { + + // Resolve the interface contract + InterfaceContract interfaceContract = contract.getInterfaceContract(); + if (interfaceContract != null) { + extensionProcessor.resolve(interfaceContract, resolver); + } + + // Resolve bindings + for (int i = 0, n = contract.getBindings().size(); i < n; i++) { + Binding binding = contract.getBindings().get(i); + extensionProcessor.resolve(binding, resolver); + } + } + } + + /** + * Resolve interface and callback interface on a list of abstract contracts. + * @param contracts the list of contracts + * @param resolver the resolver to use to resolve models + */ + protected void resolveAbstractContracts(List contracts, ModelResolver resolver) throws ContributionResolveException { + for (AbstractContract contract: contracts) { + + // Resolve the interface contract + InterfaceContract interfaceContract = contract.getInterfaceContract(); + if (interfaceContract != null) { + extensionProcessor.resolve(interfaceContract, resolver); + } + } + } + + /** + * Start an element. + * @param uri + * @param name + * @param attrs + * @throws XMLStreamException + */ + protected void writeStart(XMLStreamWriter writer, String uri, String name, XAttr... attrs) throws XMLStreamException { + writer.writeStartElement(uri, name); + writeAttributes(writer, attrs); + } + + /** + * Start an element. + * @param writer + * @param name + * @param attrs + * @throws XMLStreamException + */ + protected void writeStart(XMLStreamWriter writer, String name, XAttr... attrs) throws XMLStreamException { + writer.writeStartElement(SCA10_NS, name); + writeAttributes(writer, attrs); + } + + /** + * End an element. + * @param writer + * @throws XMLStreamException + */ + protected void writeEnd(XMLStreamWriter writer) throws XMLStreamException { + writer.writeEndElement(); + } + + /** + * Start a document. + * @param writer + * @throws XMLStreamException + */ + protected void writeStartDocument(XMLStreamWriter writer, String name, XAttr... attrs) throws XMLStreamException { + writer.writeStartDocument(); + writer.setDefaultNamespace(SCA10_NS); + writeStart(writer, name, attrs); + writer.writeDefaultNamespace(SCA10_NS); + } + + /** + * End a document. + * @param writer + * @throws XMLStreamException + */ + protected void writeEndDocument(XMLStreamWriter writer) throws XMLStreamException { + writer.writeEndDocument(); + } + + /** + * Write attributes to the current element. + * @param writer + * @param attrs + * @throws XMLStreamException + */ + protected void writeAttributes(XMLStreamWriter writer, XAttr... attrs) throws XMLStreamException { + for (XAttr attr : attrs) { + if (attr != null) + attr.write(writer); + } + } + + /** + * Write an SCA abstract property declaration. + * @param writer + * @param prop + */ + protected void writeAbstractProperty(XMLStreamWriter writer, AbstractProperty prop) throws XMLStreamException { + } + + /** + * Write an SCA property declaration. + * @param writer + * @param prop + */ + protected void writeProperty(XMLStreamWriter writer, Property prop) throws XMLStreamException { + writeAbstractProperty(writer, prop); + } + + /** + * Returns a constrainingType attribute. + * @param componentType + * @return + */ + protected QName getConstrainingTypeAttr(ComponentType componentType) { + ConstrainingType constrainingType = componentType.getConstrainingType(); + if (constrainingType != null) + return constrainingType.getName(); + else + return null; + } + + /** + * Read a property value into a DOM document. + * @param reader + * @param type + * @return + * @throws XMLStreamException + * @throws ContributionReadException + * @throws ParserConfigurationException + */ + protected Document readPropertyValue(XMLStreamReader reader, QName type) + throws XMLStreamException, ParserConfigurationException { + + Document doc = createDocument(); + + // root element has no namespace and local name "value" + Element root = doc.createElementNS(null, "value"); + if (type != null) { + org.w3c.dom.Attr xsi = doc.createAttributeNS(XMLNS_ATTRIBUTE_NS_URI, "xmlns:xsi"); + xsi.setValue(W3C_XML_SCHEMA_INSTANCE_NS_URI); + root.setAttributeNodeNS(xsi); + + String prefix = type.getPrefix(); + if (prefix == null || prefix.length() == 0) { + prefix = "ns"; + } + + declareNamespace(root, prefix, type.getNamespaceURI()); + + org.w3c.dom.Attr xsiType = doc.createAttributeNS(W3C_XML_SCHEMA_INSTANCE_NS_URI, "xsi:type"); + xsiType.setValue(prefix + ":" + type.getLocalPart()); + root.setAttributeNodeNS(xsiType); + } + doc.appendChild(root); + + loadElement(reader, root); + return doc; + } + + /** + * Create a new DOM document. + * @return + * @throws ContributionReadException + */ + private Document createDocument() throws ParserConfigurationException { + return domFactory.newDocumentBuilder().newDocument(); + } + + /** + * Create a DOM element + * @param document + * @param name + * @return + */ + private Element createElement(Document document, QName name) { + String prefix = name.getPrefix(); + String qname = (prefix != null && prefix.length() > 0) ? prefix + ":" + name.getLocalPart() : name + .getLocalPart(); + return document.createElementNS(name.getNamespaceURI(), qname); + } + + /** + * Declare a namespace. + * @param element + * @param prefix + * @param ns + */ + private void declareNamespace(Element element, String prefix, String ns) { + String qname = null; + if ("".equals(prefix)) { + qname = "xmlns"; + } else { + qname = "xmlns:" + prefix; + } + Node node = element; + boolean declared = false; + while (node != null && node.getNodeType() == Node.ELEMENT_NODE) { + NamedNodeMap attrs = node.getAttributes(); + if (attrs == null) { + break; + } + Node attr = attrs.getNamedItem(qname); + if (attr != null) { + declared = ns.equals(attr.getNodeValue()); + break; + } + node = node.getParentNode(); + } + if (!declared) { + org.w3c.dom.Attr attr = element.getOwnerDocument().createAttributeNS(XMLNS_ATTRIBUTE_NS_URI, qname); + attr.setValue(ns); + element.setAttributeNodeNS(attr); + } + } + + /** + * Load a property value specification from an StAX stream into a DOM + * Document. Only elements, text and attributes are processed; all comments + * and other whitespace are ignored. + * + * @param reader the stream to read from + * @param root the DOM node to load + * @throws javax.xml.stream.XMLStreamException + */ + private void loadElement(XMLStreamReader reader, Element root) throws XMLStreamException { + Document document = root.getOwnerDocument(); + Node current = root; + while (true) { + switch (reader.next()) { + case XMLStreamConstants.START_ELEMENT: + QName name = reader.getName(); + Element child = createElement(document, name); + + // push the new element and make it the current one + current.appendChild(child); + current = child; + + declareNamespace(child, name.getPrefix(), name.getNamespaceURI()); + + int count = reader.getNamespaceCount(); + for (int i = 0; i < count; i++) { + String prefix = reader.getNamespacePrefix(i); + String ns = reader.getNamespaceURI(i); + declareNamespace(child, prefix, ns); + } + + // add the attributes for this element + count = reader.getAttributeCount(); + for (int i = 0; i < count; i++) { + String ns = reader.getAttributeNamespace(i); + String prefix = reader.getAttributePrefix(i); + String localPart = reader.getAttributeLocalName(i); + String value = reader.getAttributeValue(i); + child.setAttributeNS(ns, localPart, value); + declareNamespace(child, prefix, ns); + } + + break; + case XMLStreamConstants.CDATA: + current.appendChild(document.createCDATASection(reader.getText())); + break; + case XMLStreamConstants.CHARACTERS: + current.appendChild(document.createTextNode(reader.getText())); + break; + case XMLStreamConstants.END_ELEMENT: + // if we are back at the root then we are done + if (current == root) { + return; + } + + // pop the element off the stack + current = current.getParentNode(); + } + } + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ComponentTypeDocumentProcessor.java b/sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ComponentTypeDocumentProcessor.java new file mode 100644 index 0000000000..32655689b2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ComponentTypeDocumentProcessor.java @@ -0,0 +1,94 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.assembly.xml; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.net.URL; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.sca.assembly.ComponentType; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.contribution.service.ContributionResolveException; + +/** + * A componentType processor. + * + * @version $Rev$ $Date$ + */ +public class ComponentTypeDocumentProcessor extends BaseArtifactProcessor implements URLArtifactProcessor { + private XMLInputFactory inputFactory; + + /** + * Constructs a new componentType processor. + * @param factory + * @param policyFactory + * @param registry + */ + public ComponentTypeDocumentProcessor(StAXArtifactProcessor staxProcessor, XMLInputFactory inputFactory) { + super(null, null, staxProcessor); + this.inputFactory = inputFactory; + } + + public ComponentType read(URL contributionURL, URI uri, URL url) throws ContributionReadException { + InputStream urlStream = null; + try { + urlStream = url.openStream(); + XMLStreamReader reader = inputFactory.createXMLStreamReader(urlStream); + reader.nextTag(); + ComponentType componentType = (ComponentType)extensionProcessor.read(reader); + componentType.setURI(url.toString()); + return componentType; + + } catch (XMLStreamException e) { + throw new ContributionReadException(e); + } catch (IOException e) { + throw new ContributionReadException(e); + } finally { + try { + if (urlStream != null) { + urlStream.close(); + urlStream = null; + } + } catch (IOException ioe) { + //ignore + } + } + } + + public void resolve(ComponentType componentType, ModelResolver resolver) throws ContributionResolveException { + extensionProcessor.resolve(componentType, resolver); + } + + public String getArtifactType() { + return ".componentType"; + } + + public Class getModelType() { + return ComponentType.class; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ComponentTypeProcessor.java b/sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ComponentTypeProcessor.java new file mode 100644 index 0000000000..386842e8d6 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ComponentTypeProcessor.java @@ -0,0 +1,271 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.assembly.xml; + +import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; +import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; + +import java.util.ArrayList; +import java.util.List; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.Base; +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.Callback; +import org.apache.tuscany.sca.assembly.ComponentType; +import org.apache.tuscany.sca.assembly.Contract; +import org.apache.tuscany.sca.assembly.Property; +import org.apache.tuscany.sca.assembly.Reference; +import org.apache.tuscany.sca.assembly.Service; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.contribution.service.ContributionResolveException; +import org.apache.tuscany.sca.contribution.service.ContributionWriteException; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.policy.PolicyFactory; + +/** + * A componentType processor. + * + * @version $Rev$ $Date$ + */ +public class ComponentTypeProcessor extends BaseArtifactProcessor implements StAXArtifactProcessor { + + /** + * Constructs a new componentType processor. + * @param factory + * @param policyFactory + * @param registry + */ + public ComponentTypeProcessor(AssemblyFactory factory, PolicyFactory policyFactory, StAXArtifactProcessor extensionProcessor) { + super(factory, policyFactory, extensionProcessor); + } + + public ComponentType read(XMLStreamReader reader) throws ContributionReadException { + ComponentType componentType = null; + Service service = null; + Reference reference = null; + Contract contract = null; + Property property = null; + Callback callback = null; + QName name = null; + + try { + + // Read the componentType document + while (reader.hasNext()) { + int event = reader.getEventType(); + switch (event) { + case START_ELEMENT: + name = reader.getName(); + + if (Constants.COMPONENT_TYPE_QNAME.equals(name)) { + + // Read a + componentType = assemblyFactory.createComponentType(); + componentType.setConstrainingType(getConstrainingType(reader)); + readPolicies(componentType, reader); + + } else if (Constants.SERVICE_QNAME.equals(name)) { + + // Read a + service = assemblyFactory.createService(); + contract = service; + service.setName(getString(reader, Constants.NAME)); + componentType.getServices().add(service); + readPolicies(service, reader); + + } else if (Constants.REFERENCE_QNAME.equals(name)) { + // Read a + reference = assemblyFactory.createReference(); + contract = reference; + reference.setName(getString(reader, Constants.NAME)); + reference.setWiredByImpl(getBoolean(reader, Constants.WIRED_BY_IMPL)); + readMultiplicity(reference, reader); + readTargets(reference, reader); + componentType.getReferences().add(reference); + readPolicies(reference, reader); + + } else if (Constants.PROPERTY_QNAME.equals(name)) { + + // Read a + property = assemblyFactory.createProperty(); + readPolicies(property, reader); + readProperty(property, reader); + componentType.getProperties().add(property); + + } else if (Constants.CALLBACK_QNAME.equals(name)) { + + // Read a + callback = assemblyFactory.createCallback(); + contract.setCallback(callback); + readPolicies(callback, reader); + + } else if (OPERATION.equals(name)) { + + // Read an + Operation operation = assemblyFactory.createOperation(); + operation.setName(getString(reader, NAME)); + operation.setUnresolved(true); + if (callback != null) { + readPolicies(callback, operation, reader); + } else { + readPolicies(contract, operation, reader); + } + } else { + + // Read an extension element + Object extension = extensionProcessor.read(reader); + if (extension != null) { + if (extension instanceof InterfaceContract) { + + // and + contract.setInterfaceContract((InterfaceContract)extension); + + } else if (extension instanceof Binding) { + + // and + contract.getBindings().add((Binding)extension); + } + } + } + break; + + case END_ELEMENT: + name = reader.getName(); + + // Clear current state when reading reaching end element + if (SERVICE_QNAME.equals(name)) { + service = null; + contract = null; + } else if (REFERENCE_QNAME.equals(name)) { + reference = null; + contract = null; + } else if (PROPERTY_QNAME.equals(name)) { + property = null; + } else if (CALLBACK_QNAME.equals(name)) { + callback = null; + } + break; + } + + // Read the next element + if (reader.hasNext()) { + reader.next(); + } + } + + } catch (XMLStreamException e) { + throw new ContributionReadException(e); + } + return componentType; + } + + public void validate(ComponentType componentType, List problems) { + if (problems == null) { + problems = new ArrayList(); + } + validatePropertyDefinitions(componentType.getProperties(), problems); + } + + public void validatePropertyDefinitions(List properties, List problems) { + for(Property aProperty : properties) { + if (aProperty.isMustSupply() && aProperty.getValue() != null) { + problems.add(aProperty); + } + } + } + + public void write(ComponentType componentType, XMLStreamWriter writer) throws ContributionWriteException { + + try { + writeStartDocument(writer, COMPONENT_TYPE, + new XAttr(CONSTRAINING_TYPE, getConstrainingTypeAttr(componentType))); + + for (Service service : componentType.getServices()) { + writeStart(writer, SERVICE, new XAttr(NAME, service.getName())); + + extensionProcessor.write(service.getInterfaceContract(), writer); + + for (Binding binding: service.getBindings()) { + extensionProcessor.write(binding, writer); + } + + if (service.getCallback() != null) { + writeStart(writer, CALLBACK); + writeEnd(writer); + } + writeEnd(writer); + } + + for (Reference reference : componentType.getReferences()) { + // TODO handle multivalued target attribute + String target = reference.getTargets().isEmpty() ? null : reference.getTargets().get(0).getName(); + writeStart(writer, REFERENCE, + new XAttr(NAME, reference.getName()), + new XAttr(TARGET, target)); + + extensionProcessor.write(reference.getInterfaceContract(), writer); + + for (Binding binding: reference.getBindings()) { + extensionProcessor.write(binding, writer); + } + + if (reference.getCallback() != null) { + writeStart(writer, CALLBACK); + writeEnd(writer); + } + writeEnd(writer); + } + + for (Property property : componentType.getProperties()) { + writeStart(writer, PROPERTY, new XAttr(NAME, property.getName())); + writeEnd(writer); + } + + writeEndDocument(writer); + + } catch (XMLStreamException e) { + throw new ContributionWriteException(e); + } + } + + public void resolve(ComponentType componentType, ModelResolver resolver) throws ContributionResolveException { + + // Resolve component type services and references + resolveContracts(componentType.getServices(), resolver); + resolveContracts(componentType.getReferences(), resolver); + } + + public QName getArtifactType() { + return COMPONENT_TYPE_QNAME; + } + + public Class getModelType() { + return ComponentType.class; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeDocumentProcessor.java b/sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeDocumentProcessor.java new file mode 100644 index 0000000000..feafb73c05 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeDocumentProcessor.java @@ -0,0 +1,93 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.assembly.xml; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.net.URL; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.contribution.service.ContributionResolveException; + +/** + * A composite processor. + * + * @version $Rev$ $Date$ + */ +public class CompositeDocumentProcessor extends BaseArtifactProcessor implements URLArtifactProcessor { + private XMLInputFactory inputFactory; + + /** + * Construct a new composite processor + * @param assemblyFactory + * @param policyFactory + * @param staxProcessor + */ + public CompositeDocumentProcessor(StAXArtifactProcessor staxProcessor, XMLInputFactory inputFactory) { + super(null, null, staxProcessor); + this.inputFactory = inputFactory; + } + + public Composite read(URL contributionURL, URI uri, URL url) throws ContributionReadException { + InputStream urlStream = null; + try { + urlStream = url.openStream(); + XMLStreamReader reader = inputFactory.createXMLStreamReader(urlStream); + reader.nextTag(); + Composite composite = (Composite)extensionProcessor.read(reader); + return composite; + + } catch (XMLStreamException e) { + throw new ContributionReadException(e); + } catch (IOException e) { + throw new ContributionReadException(e); + } finally { + try { + if (urlStream != null) { + urlStream.close(); + urlStream = null; + } + } catch (IOException ioe) { + //ignore + } + } + } + + public void resolve(Composite composite, ModelResolver resolver) throws ContributionResolveException { + extensionProcessor.resolve(composite, resolver); + } + + public String getArtifactType() { + return ".composite"; + } + + public Class getModelType() { + return Composite.class; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeProcessor.java b/sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeProcessor.java new file mode 100644 index 0000000000..962aeb67dd --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeProcessor.java @@ -0,0 +1,498 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.assembly.xml; + +import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; +import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; + +import java.util.StringTokenizer; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamConstants; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.Callback; +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.ComponentProperty; +import org.apache.tuscany.sca.assembly.ComponentReference; +import org.apache.tuscany.sca.assembly.ComponentService; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.CompositeReference; +import org.apache.tuscany.sca.assembly.CompositeService; +import org.apache.tuscany.sca.assembly.ConstrainingType; +import org.apache.tuscany.sca.assembly.Contract; +import org.apache.tuscany.sca.assembly.Implementation; +import org.apache.tuscany.sca.assembly.Property; +import org.apache.tuscany.sca.assembly.Reference; +import org.apache.tuscany.sca.assembly.Service; +import org.apache.tuscany.sca.assembly.Wire; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.contribution.service.ContributionResolveException; +import org.apache.tuscany.sca.contribution.service.ContributionWriteException; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.policy.PolicyFactory; + +/** + * A composite processor. + * + * @version $Rev$ $Date$ + */ +public class CompositeProcessor extends BaseArtifactProcessor implements StAXArtifactProcessor { + + /** + * Construct a new composite processor + * @param assemblyFactory + * @param policyFactory + * @param extensionProcessor + */ + public CompositeProcessor(AssemblyFactory factory, PolicyFactory policyFactory, + InterfaceContractMapper interfaceContractMapper, + StAXArtifactProcessor extensionProcessor) { + super(factory, policyFactory, extensionProcessor); + } + + public Composite read(XMLStreamReader reader) throws ContributionReadException { + Composite composite = null; + Composite include = null; + Component component = null; + Property property = null; + ComponentService componentService = null; + ComponentReference componentReference = null; + ComponentProperty componentProperty = null; + CompositeService compositeService = null; + CompositeReference compositeReference = null; + Contract contract = null; + Wire wire = null; + Callback callback = null; + QName name = null; + + try { + + // Read the composite document + while (reader.hasNext()) { + int event = reader.getEventType(); + switch (event) { + case START_ELEMENT: + name = reader.getName(); + + if (COMPOSITE_QNAME.equals(name)) { + + // Read a + composite = assemblyFactory.createComposite(); + composite.setName(new QName(getString(reader, TARGET_NAMESPACE), getString(reader, NAME))); + composite.setAutowire(getBoolean(reader, AUTOWIRE)); + composite.setLocal(getBoolean(reader, LOCAL)); + composite.setConstrainingType(getConstrainingType(reader)); + readPolicies(composite, reader); + + } else if (INCLUDE_QNAME.equals(name)) { + + // Read an + include = assemblyFactory.createComposite(); + include.setName(getQName(reader, "name")); + include.setUnresolved(true); + composite.getIncludes().add(include); + + } else if (SERVICE_QNAME.equals(name)) { + if (component != null) { + + // Read a + componentService = assemblyFactory.createComponentService(); + contract = componentService; + componentService.setName(getString(reader, NAME)); + component.getServices().add(componentService); + readPolicies(contract, reader); + } else { + + // Read a + compositeService = assemblyFactory.createCompositeService(); + contract = compositeService; + compositeService.setName(getString(reader, NAME)); + + ComponentService promoted = assemblyFactory.createComponentService(); + promoted.setUnresolved(true); + promoted.setName(getString(reader, PROMOTE)); + compositeService.setPromotedService(promoted); + + composite.getServices().add(compositeService); + readPolicies(contract, reader); + } + + } else if (REFERENCE_QNAME.equals(name)) { + if (component != null) { + // Read a + componentReference = assemblyFactory.createComponentReference(); + contract = componentReference; + componentReference.setName(getString(reader, NAME)); + readMultiplicity(componentReference, reader); + componentReference.setAutowire(getBoolean(reader, AUTOWIRE)); + readTargets(componentReference, reader); + componentReference.setWiredByImpl(getBoolean(reader, WIRED_BY_IMPL)); + component.getReferences().add(componentReference); + readPolicies(contract, reader); + } else { + // Read a + compositeReference = assemblyFactory.createCompositeReference(); + contract = compositeReference; + compositeReference.setName(getString(reader, NAME)); + readMultiplicity(compositeReference, reader); + readTargets(compositeReference, reader); + readPromotes(compositeReference, reader); + compositeReference.setWiredByImpl(getBoolean(reader, WIRED_BY_IMPL)); + composite.getReferences().add(compositeReference); + readPolicies(contract, reader); + } + + } else if (PROPERTY_QNAME.equals(name)) { + if (component != null) { + // Read a + componentProperty = assemblyFactory.createComponentProperty(); + property = componentProperty; + componentProperty.setSource(getString(reader, SOURCE)); + componentProperty.setFile(getString(reader, FILE)); + readPolicies(property, reader); + readProperty(componentProperty, reader); + component.getProperties().add(componentProperty); + } else { + + // Read a + property = assemblyFactory.createProperty(); + readPolicies(property, reader); + readProperty(property, reader); + composite.getProperties().add(property); + } + + } else if (COMPONENT_QNAME.equals(name)) { + + // Read a + component = assemblyFactory.createComponent(); + component.setName(getString(reader, NAME)); + component.setConstrainingType(getConstrainingType(reader)); + composite.getComponents().add(component); + readPolicies(component, reader); + + } else if (WIRE_QNAME.equals(name)) { + + // Read a + wire = assemblyFactory.createWire(); + ComponentReference source = assemblyFactory.createComponentReference(); + source.setUnresolved(true); + source.setName(getString(reader, SOURCE)); + wire.setSource(source); + + ComponentService target = assemblyFactory.createComponentService(); + target.setUnresolved(true); + target.setName(getString(reader, TARGET)); + wire.setTarget(target); + + composite.getWires().add(wire); + readPolicies(wire, reader); + + } else if (CALLBACK_QNAME.equals(name)) { + + // Read a + callback = assemblyFactory.createCallback(); + contract.setCallback(callback); + readPolicies(callback, reader); + + } else if (OPERATION_QNAME.equals(name)) { + + // Read an + Operation operation = assemblyFactory.createOperation(); + operation.setName(getString(reader, NAME)); + operation.setUnresolved(true); + if (callback != null) { + readPolicies(callback, operation, reader); + } else { + readPolicies(contract, operation, reader); + } + } else if (IMPLEMENTATION_COMPOSITE_QNAME.equals(name)) { + + // Read an implementation.composite + Composite implementation = assemblyFactory.createComposite(); + implementation.setName(getQName(reader, NAME)); + implementation.setUnresolved(true); + component.setImplementation(implementation); + + } else { + + // Read an extension element + Object extension = extensionProcessor.read(reader); + if (extension != null) { + if (extension instanceof InterfaceContract) { + + // and + // + contract.setInterfaceContract((InterfaceContract)extension); + + } else if (extension instanceof Binding) { + // and + contract.getBindings().add((Binding)extension); + + } else if (extension instanceof Implementation) { + + // + component.setImplementation((Implementation)extension); + } else { + + // FIXME: We need to decide where to host the extensions + composite.getExtensions().add(extension); + } + } + } + break; + + case XMLStreamConstants.CHARACTERS: + break; + + case END_ELEMENT: + name = reader.getName(); + + // Clear current state when reading reaching end element + if (SERVICE_QNAME.equals(name)) { + componentService = null; + compositeService = null; + contract = null; + } else if (INCLUDE_QNAME.equals(name)) { + include = null; + } else if (REFERENCE_QNAME.equals(name)) { + componentReference = null; + compositeReference = null; + contract = null; + } else if (PROPERTY_QNAME.equals(name)) { + componentProperty = null; + property = null; + } else if (COMPONENT_QNAME.equals(name)) { + component = null; + } else if (WIRE_QNAME.equals(name)) { + wire = null; + } else if (CALLBACK_QNAME.equals(name)) { + callback = null; + } + break; + } + + // Read the next element + if (reader.hasNext()) { + reader.next(); + } + } + return composite; + + } catch (XMLStreamException e) { + throw new ContributionReadException(e); + } + } + + public void write(Composite composite, XMLStreamWriter writer) throws ContributionWriteException { + + try { + writeStartDocument(writer, COMPOSITE, + new XAttr(CONSTRAINING_TYPE, getConstrainingTypeAttr(composite)), + new XAttr(TARGET_NAMESPACE, composite.getName().getNamespaceURI()), + new XAttr(NAME, composite.getName().getLocalPart())); + + for (Service service : composite.getServices()) { + CompositeService compositeService = (CompositeService)service; + ComponentService promotedService = compositeService.getPromotedService(); + String promote = promotedService != null ? promotedService.getName() : null; + writeStart(writer, SERVICE, new XAttr(NAME, service.getName()), new XAttr(PROMOTE, promote)); + + extensionProcessor.write(service.getInterfaceContract(), writer); + + for (Binding binding: service.getBindings()) { + extensionProcessor.write(binding, writer); + } + + if (service.getCallback() != null) { + writeStart(writer, CALLBACK); + writeEnd(writer); + } + writeEnd(writer); + } + + for (Component component : composite.getComponents()) { + writeStart(writer, COMPONENT, new XAttr(NAME, component.getName())); + + for (ComponentService service : component.getServices()) { + writeStart(writer, SERVICE, new XAttr(NAME, service.getName())); + + extensionProcessor.write(service.getInterfaceContract(), writer); + + for (Binding binding: service.getBindings()) { + extensionProcessor.write(binding, writer); + } + + if (service.getCallback() != null) { + writeStart(writer, CALLBACK); + writeEnd(writer); + } + writeEnd(writer); + } + + for (ComponentReference reference : component.getReferences()) { + // TODO handle multivalued target attribute + String target = reference.getTargets().isEmpty() ? null : reference.getTargets().get(0).getName(); + writeStart(writer, REFERENCE, + new XAttr(NAME, reference.getName()), + new XAttr(TARGET,target)); + + extensionProcessor.write(reference.getInterfaceContract(), writer); + + for (Binding binding: reference.getBindings()) { + extensionProcessor.write(binding, writer); + } + + if (reference.getCallback() != null) { + writeStart(writer, CALLBACK); + writeEnd(writer); + } + writeEnd(writer); + } + + for (ComponentProperty property : component.getProperties()) { + writeStart(writer, PROPERTY, new XAttr(NAME, property.getName())); + writeEnd(writer); + } + + // Write the component implementation + Implementation implementation = component.getImplementation(); + if (implementation instanceof Composite) { + writeStart(writer, IMPLEMENTATION_COMPOSITE, + new XAttr(NAME, composite.getName())); + writeEnd(writer); + } else { + extensionProcessor.write(component.getImplementation(), writer); + } + + writeEnd(writer); + } + + for (Reference reference : composite.getReferences()) { + // TODO handle multivalued promote attribute + CompositeReference compositeReference = (CompositeReference)reference; + String promote; + if (!compositeReference.getPromotedReferences().isEmpty()) + promote = compositeReference.getPromotedReferences().get(0).getName(); + else + promote = null; + writeStart(writer, REFERENCE, + new XAttr(NAME, reference.getName()), + new XAttr(PROMOTE, promote)); + + extensionProcessor.write(reference.getInterfaceContract(), writer); + + for (Binding binding: reference.getBindings()) { + extensionProcessor.write(binding, writer); + } + + if (reference.getCallback() != null) { + writeStart(writer, CALLBACK); + writeEnd(writer); + } + writeEnd(writer); + } + + for (Property property : composite.getProperties()) { + writeStart(writer, PROPERTY, new XAttr(NAME, property.getName())); + writeEnd(writer); + } + + writeEndDocument(writer); + + } catch (XMLStreamException e) { + throw new ContributionWriteException(e); + } + } + + public void resolve(Composite composite, ModelResolver resolver) throws ContributionResolveException { + + // Resolve constraining type + ConstrainingType constrainingType = composite.getConstrainingType(); + constrainingType = resolver.resolveModel(ConstrainingType.class, constrainingType); + composite.setConstrainingType(constrainingType); + + // Resolve includes in the composite + for (int i = 0, n = composite.getIncludes().size(); i < n; i++) { + Composite include = composite.getIncludes().get(i); + include = resolver.resolveModel(Composite.class, include); + composite.getIncludes().set(i, include); + } + + // resolve and extensions to the standard SCDL that appear in the + // SCDL. + for (int i = 0, n = composite.getExtensions().size(); i < n; i++) { + Object model = composite.getExtensions().get(i); + extensionProcessor.resolve(model, resolver); + } + + // Resolve component implementations, services and references + for (Component component: composite.getComponents()) { + constrainingType = component.getConstrainingType(); + constrainingType = resolver.resolveModel(ConstrainingType.class, constrainingType); + component.setConstrainingType(constrainingType); + + Implementation implementation = component.getImplementation(); + implementation = resolveImplementation(implementation, resolver); + component.setImplementation(implementation); + + resolveContracts(component.getServices(), resolver); + resolveContracts(component.getReferences(), resolver); + } + + // Resolve composite services and references + resolveContracts(composite.getServices(), resolver); + resolveContracts(composite.getReferences(), resolver); + } + + public QName getArtifactType() { + return COMPOSITE_QNAME; + } + + public Class getModelType() { + return Composite.class; + } + + /** + * Read list of refence targets + * @param reference + * @param reader + */ + protected void readPromotes(CompositeReference reference, XMLStreamReader reader) { + String value = reader.getAttributeValue(null, Constants.PROMOTE); + ComponentReference promoted = null; + if (value != null) { + for (StringTokenizer tokens = new StringTokenizer(value); tokens.hasMoreTokens();) { + promoted = assemblyFactory.createComponentReference(); + promoted.setUnresolved(true); + promoted.setName(tokens.nextToken()); + reference.getPromotedReferences().add(promoted); + } + } + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/Constants.java b/sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/Constants.java new file mode 100644 index 0000000000..cd98685203 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/Constants.java @@ -0,0 +1,74 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.assembly.xml; + +import javax.xml.namespace.QName; + +/** + * Constants used in SCA assembly XML files. + */ +public interface Constants { + String SCA10_NS = "http://www.osoa.org/xmlns/sca/1.0"; + String COMPONENT_TYPE = "componentType"; + QName COMPONENT_TYPE_QNAME = new QName(SCA10_NS, COMPONENT_TYPE); + String SERVICE = "service"; + QName SERVICE_QNAME = new QName(SCA10_NS, SERVICE); + String REFERENCE = "reference"; + QName REFERENCE_QNAME = new QName(SCA10_NS, REFERENCE); + String PROPERTY = "property"; + QName PROPERTY_QNAME = new QName(SCA10_NS, PROPERTY); + String CONSTRAINING_TYPE = "constrainingType"; + QName CONSTRAINING_TYPE_QNAME = new QName(SCA10_NS, CONSTRAINING_TYPE); + String COMPOSITE = "composite"; + QName COMPOSITE_QNAME = new QName(SCA10_NS, COMPOSITE); + String INCLUDE = "include"; + QName INCLUDE_QNAME = new QName(SCA10_NS, INCLUDE); + String COMPONENT = "component"; + QName COMPONENT_QNAME = new QName(SCA10_NS, COMPONENT); + String WIRE = "wire"; + QName WIRE_QNAME = new QName(SCA10_NS, WIRE); + String NAME = "name"; + String TARGET_NAMESPACE = "targetNamespace"; + String LOCAL = "local"; + String AUTOWIRE = "autowire"; + String REQUIRES = "requires"; + String POLICY_SETS = "policySets"; + String OPERATION = "operation"; + QName OPERATION_QNAME = new QName(SCA10_NS, OPERATION); + String CALLBACK = "callback"; + QName CALLBACK_QNAME = new QName(SCA10_NS, CALLBACK); + String PROMOTE = "promote"; + String TARGET = "target"; + String WIRED_BY_IMPL = "wiredByImpl"; + String MULTIPLICITY = "multiplicity"; + String TYPE = "type"; + String ELEMENT = "element"; + String MANY = "many"; + String MUST_SUPPLY = "mustSupply"; + String SOURCE = "source"; + String FILE = "file"; + String URI = "uri"; + String ZERO_ONE = "0..1"; + String ZERO_N = "0..n"; + String ONE_ONE = "1..1"; + String ONE_N = "1..n"; + String IMPLEMENTATION_COMPOSITE = "implementation.composite"; + QName IMPLEMENTATION_COMPOSITE_QNAME = new QName(SCA10_NS, IMPLEMENTATION_COMPOSITE); +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConstrainingTypeDocumentProcessor.java b/sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConstrainingTypeDocumentProcessor.java new file mode 100644 index 0000000000..fa22602356 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConstrainingTypeDocumentProcessor.java @@ -0,0 +1,93 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.assembly.xml; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.net.URL; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.sca.assembly.ConstrainingType; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.contribution.service.ContributionResolveException; + +/** + * A contrainingType content handler. + * + * @version $Rev$ $Date$ + */ +public class ConstrainingTypeDocumentProcessor extends BaseArtifactProcessor implements URLArtifactProcessor { + private XMLInputFactory inputFactory; + + /** + * Construct a new constrainingType processor. + * @param factory + * @param policyFactory + * @param staxProcessor + */ + public ConstrainingTypeDocumentProcessor(StAXArtifactProcessor staxProcessor, XMLInputFactory inputFactory) { + super(null, null, staxProcessor); + this.inputFactory = inputFactory; + } + + public ConstrainingType read(URL contributionURL, URI uri, URL url) throws ContributionReadException { + InputStream urlStream = null; + try { + urlStream = url.openStream(); + XMLStreamReader reader = inputFactory.createXMLStreamReader(urlStream); + reader.nextTag(); + ConstrainingType constrainingType = (ConstrainingType)extensionProcessor.read(reader); + return constrainingType; + + } catch (XMLStreamException e) { + throw new ContributionReadException(e); + } catch (IOException e) { + throw new ContributionReadException(e); + } finally { + try { + if (urlStream != null) { + urlStream.close(); + urlStream = null; + } + } catch (IOException ioe) { + //ignore + } + } + } + + public void resolve(ConstrainingType constrainingType, ModelResolver resolver) throws ContributionResolveException { + extensionProcessor.resolve(constrainingType, resolver); + } + + public String getArtifactType() { + return ".constrainingType"; + } + + public Class getModelType() { + return ConstrainingType.class; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConstrainingTypeProcessor.java b/sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConstrainingTypeProcessor.java new file mode 100644 index 0000000000..74a9fc430e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConstrainingTypeProcessor.java @@ -0,0 +1,205 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.assembly.xml; + +import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; +import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.assembly.AbstractContract; +import org.apache.tuscany.sca.assembly.AbstractProperty; +import org.apache.tuscany.sca.assembly.AbstractReference; +import org.apache.tuscany.sca.assembly.AbstractService; +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.ConstrainingType; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.contribution.service.ContributionResolveException; +import org.apache.tuscany.sca.contribution.service.ContributionWriteException; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.policy.PolicyFactory; + +/** + * A contrainingType content handler. + * + * @version $Rev$ $Date$ + */ +public class ConstrainingTypeProcessor extends BaseArtifactProcessor implements StAXArtifactProcessor { + + /** + * Construct a new constrainingType processor. + * @param factory + * @param policyFactory + * @param extensionProcessor + */ + public ConstrainingTypeProcessor(AssemblyFactory factory, PolicyFactory policyFactory, StAXArtifactProcessor extensionProcessor) { + super(factory, policyFactory, extensionProcessor); + } + + public ConstrainingType read(XMLStreamReader reader) throws ContributionReadException { + ConstrainingType constrainingType = null; + AbstractService abstractService = null; + AbstractReference abstractReference = null; + AbstractProperty abstractProperty = null; + AbstractContract abstractContract = null; + QName name = null; + + try { + + // Read the constrainingType document + while (reader.hasNext()) { + int event = reader.getEventType(); + switch (event) { + + case START_ELEMENT: + name = reader.getName(); + + // Read a + if (Constants.CONSTRAINING_TYPE_QNAME.equals(name)) { + constrainingType = assemblyFactory.createConstrainingType(); + constrainingType.setName(new QName(getString(reader, TARGET_NAMESPACE), getString(reader, NAME))); + readIntents(constrainingType, reader); + + } else if (Constants.SERVICE_QNAME.equals(name)) { + + // Read a + abstractService = assemblyFactory.createAbstractService(); + abstractContract = abstractService; + abstractService.setName(getString(reader, Constants.NAME)); + constrainingType.getServices().add(abstractService); + readIntents(abstractService, reader); + + } else if (Constants.REFERENCE_QNAME.equals(name)) { + + // Read a + abstractReference = assemblyFactory.createAbstractReference(); + abstractContract = abstractReference; + abstractReference.setName(getString(reader, Constants.NAME)); + readMultiplicity(abstractReference, reader); + constrainingType.getReferences().add(abstractReference); + readIntents(abstractReference, reader); + + } else if (Constants.PROPERTY_QNAME.equals(name)) { + + // Read a + abstractProperty = assemblyFactory.createAbstractProperty(); + readAbstractProperty(abstractProperty, reader); + constrainingType.getProperties().add(abstractProperty); + readIntents(abstractProperty, reader); + + } else if (OPERATION.equals(name)) { + + // Read an + Operation operation = assemblyFactory.createOperation(); + operation.setName(getString(reader, NAME)); + operation.setUnresolved(true); + readIntents(abstractContract, operation, reader); + + } else { + + // Read an extension element + Object extension = extensionProcessor.read(reader); + if (extension instanceof InterfaceContract) { + + // and + abstractContract.setInterfaceContract((InterfaceContract)extension); + } + } + break; + + case END_ELEMENT: + name = reader.getName(); + + // Clear current state when reading reaching end element + if (SERVICE_QNAME.equals(name)) { + abstractService = null; + abstractContract = null; + } else if (REFERENCE_QNAME.equals(name)) { + abstractReference = null; + abstractContract = null; + } else if (PROPERTY_QNAME.equals(name)) { + abstractProperty = null; + } + break; + } + if (reader.hasNext()) { + reader.next(); + } + } + return constrainingType; + + } catch (XMLStreamException e) { + throw new ContributionReadException(e); + } + } + + public void write(ConstrainingType constrainingType, XMLStreamWriter writer) throws ContributionWriteException { + + try { + writeStartDocument(writer, CONSTRAINING_TYPE, + new XAttr(TARGET_NAMESPACE, constrainingType.getName().getNamespaceURI()), + new XAttr(NAME, constrainingType.getName().getLocalPart())); + + for (AbstractService service : constrainingType.getServices()) { + writeStart(writer, SERVICE, new XAttr(NAME, service.getName())); + extensionProcessor.write(service.getInterfaceContract(), writer); + writeEnd(writer); + } + + for (AbstractReference reference : constrainingType.getReferences()) { + writeStart(writer, REFERENCE, + new XAttr(NAME, reference.getName())); + extensionProcessor.write(reference.getInterfaceContract(), writer); + writeEnd(writer); + } + + for (AbstractProperty property : constrainingType.getProperties()) { + writeStart(writer, PROPERTY, new XAttr(NAME, property.getName())); + writeEnd(writer); + } + + writeEndDocument(writer); + + } catch (XMLStreamException e) { + throw new ContributionWriteException(e); + } + } + + public void resolve(ConstrainingType constrainingType, ModelResolver resolver) throws ContributionResolveException { + + // Resolve component type services and references + resolveAbstractContracts(constrainingType.getServices(), resolver); + resolveAbstractContracts(constrainingType.getReferences(), resolver); + } + + public QName getArtifactType() { + return CONSTRAINING_TYPE_QNAME; + } + + public Class getModelType() { + return ConstrainingType.class; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/XAttr.java b/sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/XAttr.java new file mode 100644 index 0000000000..3c991798de --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/XAttr.java @@ -0,0 +1,122 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.assembly.xml; + +import javax.xml.namespace.NamespaceContext; +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamWriter; + + +/** + * Represents an XML attribute that needs to be written to a document. + * + * @version $Rev$ $Date$ + */ +class XAttr { + + String uri = Constants.SCA10_NS; + String name; + Object value; + + public XAttr(String uri, String name, String value) { + this.uri = uri; + this.name = name; + this.value = value; + } + + public XAttr(String name, String value) { + this.name = name; + this.value = value; + } + + public XAttr(String uri, String name, boolean value) { + this.uri = uri; + this.name = name; + this.value = value; + } + + public XAttr(String name, boolean value) { + this.name = name; + this.value = value; + } + + public XAttr(String uri, String name, QName value) { + this.uri = uri; + this.name = name; + this.value = value; + } + + public XAttr(String name, QName value) { + this.name = name; + this.value = value; + } + + /** + * Writes a string from a qname and registers a prefix for its namespace. + * @param reader + * @param value + * @return + */ + protected String writeQNameValue(XMLStreamWriter writer, QName qname) throws XMLStreamException { + if (qname != null) { + String prefix = qname.getPrefix(); + String uri = qname.getNamespaceURI(); + prefix = writer.getPrefix(uri); + if (prefix != null) { + + // Use the prefix already bound to the given uri + return prefix + ":" + qname.getLocalPart(); + } else { + + // Find an available prefix and bind it to the given uri + NamespaceContext nsc = writer.getNamespaceContext(); + for (int i=1; ; i++) { + prefix = "ns" + i; + if (nsc.getNamespaceURI(prefix) == null) { + break; + } + } + writer.setPrefix(prefix, uri); + writer.writeNamespace(prefix, uri); + return prefix + ":" + qname.getLocalPart(); + } + } else { + return null; + } + } + + void write(XMLStreamWriter writer) throws XMLStreamException { + if (value != null) { + String str; + if (value instanceof QName) { + str = writeQNameValue(writer, (QName)value); + } else { + str = String.valueOf(value); + } + if (uri != null && !uri.equals(Constants.SCA10_NS)) { + writer.writeAttribute(uri, name, str); + } else { + writer.writeAttribute(name,str); + } + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadAllTestCase.java b/sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadAllTestCase.java new file mode 100644 index 0000000000..110e155bb0 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadAllTestCase.java @@ -0,0 +1,159 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.assembly.xml; + +import java.io.InputStream; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLOutputFactory; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.Callback; +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.ComponentReference; +import org.apache.tuscany.sca.assembly.ComponentService; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.CompositeReference; +import org.apache.tuscany.sca.assembly.CompositeService; +import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory; +import org.apache.tuscany.sca.assembly.Property; +import org.apache.tuscany.sca.contribution.processor.DefaultStAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; +import org.apache.tuscany.sca.interfacedef.impl.InterfaceContractMapperImpl; +import org.apache.tuscany.sca.policy.DefaultPolicyFactory; +import org.apache.tuscany.sca.policy.PolicyFactory; +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +/** + * Test reading SCA XML assemblies. + * + * @version $Rev$ $Date$ + */ +public class ReadAllTestCase extends TestCase { + private ExtensibleStAXArtifactProcessor staxProcessor; + + public void setUp() throws Exception { + AssemblyFactory factory = new DefaultAssemblyFactory(); + PolicyFactory policyFactory = new DefaultPolicyFactory(); + InterfaceContractMapper mapper = new InterfaceContractMapperImpl(); + + StAXArtifactProcessorExtensionPoint staxProcessors = new DefaultStAXArtifactProcessorExtensionPoint(); + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, XMLInputFactory.newInstance(), XMLOutputFactory.newInstance()); + + staxProcessors.addArtifactProcessor(new CompositeProcessor(factory, policyFactory, mapper, staxProcessor)); + staxProcessors.addArtifactProcessor(new ComponentTypeProcessor(factory, policyFactory, staxProcessor)); + staxProcessors.addArtifactProcessor(new ConstrainingTypeProcessor(factory, policyFactory, staxProcessor)); + } + + public void tearDown() throws Exception { + staxProcessor = null; + } + + public void testReadComposite() throws Exception { + InputStream is = getClass().getResourceAsStream("TestAllCalculator.composite"); + Composite composite = (Composite)staxProcessor.read(is, Composite.class); + assertNotNull(composite); + assertEquals(composite.getName(), new QName("http://calc", "TestAllCalculator")); + assertEquals(composite.getConstrainingType().getName(), new QName("http://calc", "CalculatorComponent")); + assertTrue(composite.isLocal()); + assertFalse(composite.isAutowire()); + assertEquals(composite.getRequiredIntents().get(0).getName(), new QName("http://test/confidentiality", + "confidentiality")); + assertEquals(composite.getPolicySets().get(0).getName(), new QName("http://test/secure", "secure")); + + Composite include = composite.getIncludes().get(0); + assertEquals(include.getName(), new QName("http://calc", "TestAllDivide")); + + CompositeService calcCompositeService = (CompositeService)composite.getServices().get(0); + assertEquals(calcCompositeService.getName(), "CalculatorService"); + assertTrue(calcCompositeService.getPromotedService().isUnresolved()); + assertEquals(calcCompositeService.getPromotedService().getName(), + "CalculatorServiceComponent/CalculatorService"); + assertEquals(calcCompositeService.getRequiredIntents().get(0).getName(), + new QName("http://test/confidentiality", "confidentiality")); + assertEquals(calcCompositeService.getPolicySets().get(0).getName(), new QName("http://test/secure", "secure")); + // TODO test operations + Callback calcServiceCallback = calcCompositeService.getCallback(); + assertNotNull(calcServiceCallback); + assertEquals(calcServiceCallback.getRequiredIntents().get(0).getName(), + new QName("http://test/confidentiality", "confidentiality")); + assertEquals(calcServiceCallback.getPolicySets().get(0).getName(), new QName("http://test/secure", "secure")); + // TODO test operations + + Component calcComponent = composite.getComponents().get(0); + assertEquals(calcComponent.getName(), "CalculatorServiceComponent"); + assertEquals(calcComponent.isAutowire(), false); + assertEquals(calcComponent.getConstrainingType().getName(), new QName("http://calc", + "CalculatorComponent")); + assertEquals(calcComponent.getRequiredIntents().get(0).getName(), new QName("http://test/confidentiality", + "confidentiality")); + assertEquals(calcComponent.getPolicySets().get(0).getName(), new QName("http://test/secure", "secure")); + + ComponentService calcComponentService = calcComponent.getServices().get(0); + assertEquals(calcComponentService.getName(), "CalculatorService"); + assertEquals(calcComponentService.getRequiredIntents().get(0).getName(), + new QName("http://test/confidentiality", "confidentiality")); + assertEquals(calcComponentService.getPolicySets().get(0).getName(), new QName("http://test/secure", "secure")); + // TODO test operations + + ComponentReference calcComponentReference = calcComponent.getReferences().get(0); + assertEquals(calcComponentReference.getName(), "addService"); + assertEquals(calcComponentReference.isAutowire(), false); + assertEquals(calcComponentReference.isWiredByImpl(), false); + assertEquals(calcComponentReference.getRequiredIntents().get(0).getName(), + new QName("http://test/confidentiality", "confidentiality")); + assertEquals(calcComponentReference.getPolicySets().get(0).getName(), new QName("http://test/secure", "secure")); + // TODO test operations + + Property property = calcComponent.getProperties().get(0); + assertEquals(property.getName(), "round"); + Document doc = (Document) property.getValue(); + Element element = doc.getDocumentElement(); + String value = element.getTextContent(); + assertEquals(value, "true"); + assertEquals(property.getXSDType(), new QName("http://www.w3.org/2001/XMLSchema", "boolean")); + assertEquals(property.isMany(), false); + + CompositeReference calcCompositeReference = (CompositeReference)composite.getReferences().get(0); + assertEquals(calcCompositeReference.getName(), "MultiplyService"); + assertTrue(calcCompositeReference.getPromotedReferences().get(0).isUnresolved()); + assertEquals(calcCompositeReference.getPromotedReferences().get(0).getName(), + "CalculatorServiceComponent/multiplyService"); + assertEquals(calcCompositeReference.getRequiredIntents().get(0).getName(), + new QName("http://test/confidentiality", "confidentiality")); + assertEquals(calcCompositeReference.getPolicySets().get(0).getName(), new QName("http://test/secure", "secure")); + // TODO test operations + Callback calcCallback = calcCompositeReference.getCallback(); + assertEquals(calcCompositeReference.getRequiredIntents().get(0).getName(), + new QName("http://test/confidentiality", "confidentiality")); + assertEquals(calcCompositeReference.getPolicySets().get(0).getName(), new QName("http://test/secure", "secure")); + assertNotNull(calcCallback); + // TODO test operations + + //new PrintUtil(System.out).print(composite); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadDocumentTestCase.java b/sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadDocumentTestCase.java new file mode 100644 index 0000000000..967256c54a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadDocumentTestCase.java @@ -0,0 +1,113 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.assembly.xml; + +import java.net.URL; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLOutputFactory; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.ConstrainingType; +import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory; +import org.apache.tuscany.sca.contribution.processor.DefaultStAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.DefaultURLArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.ExtensibleURLArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; +import org.apache.tuscany.sca.interfacedef.impl.InterfaceContractMapperImpl; +import org.apache.tuscany.sca.policy.DefaultPolicyFactory; +import org.apache.tuscany.sca.policy.PolicyFactory; + +/** + * Test reading SCA XML assembly documents. + * + * @version $Rev$ $Date$ + */ +public class ReadDocumentTestCase extends TestCase { + + private ExtensibleURLArtifactProcessor documentProcessor; + private TestModelResolver resolver; + + public void setUp() throws Exception { + AssemblyFactory factory = new DefaultAssemblyFactory(); + PolicyFactory policyFactory = new DefaultPolicyFactory(); + InterfaceContractMapper mapper = new InterfaceContractMapperImpl(); + + URLArtifactProcessorExtensionPoint documentProcessors = new DefaultURLArtifactProcessorExtensionPoint(); + documentProcessor = new ExtensibleURLArtifactProcessor(documentProcessors); + + // Create Stax processors + DefaultStAXArtifactProcessorExtensionPoint staxProcessors = new DefaultStAXArtifactProcessorExtensionPoint(); + ExtensibleStAXArtifactProcessor staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, XMLInputFactory.newInstance(), XMLOutputFactory.newInstance()); + staxProcessors.addArtifactProcessor(new CompositeProcessor(factory, policyFactory, mapper, staxProcessor)); + staxProcessors.addArtifactProcessor(new ComponentTypeProcessor(factory, policyFactory, staxProcessor)); + staxProcessors.addArtifactProcessor(new ConstrainingTypeProcessor(factory, policyFactory, staxProcessor)); + + // Create document processors + XMLInputFactory inputFactory = XMLInputFactory.newInstance(); + documentProcessors.addArtifactProcessor(new CompositeDocumentProcessor(staxProcessor, inputFactory)); + documentProcessors.addArtifactProcessor(new ComponentTypeDocumentProcessor(staxProcessor, inputFactory)); + documentProcessors.addArtifactProcessor(new ConstrainingTypeDocumentProcessor(staxProcessor, inputFactory)); + + resolver = new TestModelResolver(getClass().getClassLoader()); + } + + public void tearDown() throws Exception { + documentProcessor = null; + resolver = null; + } + + public void testResolveConstrainingType() throws Exception { + + URL url = getClass().getResource("CalculatorComponent.constrainingType"); + ConstrainingType constrainingType = (ConstrainingType)documentProcessor.read(null, null, url); + assertNotNull(constrainingType); + resolver.addModel(constrainingType); + + url = getClass().getResource("TestAllCalculator.composite"); + Composite composite = (Composite)documentProcessor.read(null, null, url); + assertNotNull(composite); + + documentProcessor.resolve(composite, resolver); + + assertEquals(composite.getConstrainingType(), constrainingType); + assertEquals(composite.getComponents().get(0).getConstrainingType(), constrainingType); + } + + public void testResolveComposite() throws Exception { + URL url = getClass().getResource("Calculator.composite"); + Composite nestedComposite = (Composite)documentProcessor.read(null, null, url); + assertNotNull(nestedComposite); + resolver.addModel(nestedComposite); + + url = getClass().getResource("TestAllCalculator.composite"); + Composite composite = (Composite)documentProcessor.read(null, null, url); + + documentProcessor.resolve(composite, resolver); + + assertEquals(composite.getComponents().get(2).getImplementation(), nestedComposite); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadTestCase.java b/sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadTestCase.java new file mode 100644 index 0000000000..50a429a82c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadTestCase.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.assembly.xml; + +import java.io.InputStream; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLOutputFactory; +import javax.xml.stream.XMLStreamReader; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory; +import org.apache.tuscany.sca.contribution.processor.DefaultStAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; +import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; +import org.apache.tuscany.sca.interfacedef.impl.InterfaceContractMapperImpl; +import org.apache.tuscany.sca.policy.DefaultPolicyFactory; +import org.apache.tuscany.sca.policy.PolicyFactory; + +/** + * Test reading SCA XML assemblies. + * + * @version $Rev$ $Date$ + */ +public class ReadTestCase extends TestCase { + + private XMLInputFactory inputFactory; + private DefaultStAXArtifactProcessorExtensionPoint staxProcessors; + private ExtensibleStAXArtifactProcessor staxProcessor; + private AssemblyFactory factory; + private PolicyFactory policyFactory; + private InterfaceContractMapper mapper; + + public void setUp() throws Exception { + factory = new DefaultAssemblyFactory(); + policyFactory = new DefaultPolicyFactory(); + mapper = new InterfaceContractMapperImpl(); + inputFactory = XMLInputFactory.newInstance(); + staxProcessors = new DefaultStAXArtifactProcessorExtensionPoint(); + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, XMLInputFactory.newInstance(), XMLOutputFactory.newInstance()); + } + + public void tearDown() throws Exception { + inputFactory = null; + staxProcessors = null; + policyFactory = null; + factory = null; + mapper = null; + } + + public void testReadComponentType() throws Exception { + ComponentTypeProcessor componentTypeReader = new ComponentTypeProcessor(factory, policyFactory, staxProcessor); + InputStream is = getClass().getResourceAsStream("CalculatorImpl.componentType"); + XMLStreamReader reader = inputFactory.createXMLStreamReader(is); + assertNotNull(componentTypeReader.read(reader)); + is.close(); + } + + public void testReadConstrainingType() throws Exception { + InputStream is = getClass().getResourceAsStream("CalculatorComponent.constrainingType"); + ConstrainingTypeProcessor constrainingTypeReader = new ConstrainingTypeProcessor(factory, policyFactory, staxProcessor); + XMLStreamReader reader = inputFactory.createXMLStreamReader(is); + assertNotNull(constrainingTypeReader.read(reader)); + is.close(); + + } + + public void testReadComposite() throws Exception { + InputStream is = getClass().getResourceAsStream("Calculator.composite"); + CompositeProcessor compositeReader = new CompositeProcessor(factory, policyFactory, mapper, staxProcessor); + XMLStreamReader reader = inputFactory.createXMLStreamReader(is); + assertNotNull(compositeReader.read(reader)); + is.close(); + + } + + public void testReadCompositeAndWireIt() throws Exception { + InputStream is = getClass().getResourceAsStream("Calculator.composite"); + CompositeProcessor compositeReader = new CompositeProcessor(factory, policyFactory, mapper, staxProcessor); + XMLStreamReader reader = inputFactory.createXMLStreamReader(is); + assertNotNull(compositeReader.read(reader)); + is.close(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ResolveTestCase.java b/sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ResolveTestCase.java new file mode 100644 index 0000000000..407354c2d2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ResolveTestCase.java @@ -0,0 +1,117 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.assembly.xml; + +import java.io.InputStream; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLOutputFactory; +import javax.xml.stream.XMLStreamReader; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.ConstrainingType; +import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory; +import org.apache.tuscany.sca.contribution.processor.DefaultStAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; +import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; +import org.apache.tuscany.sca.interfacedef.impl.InterfaceContractMapperImpl; +import org.apache.tuscany.sca.policy.DefaultPolicyFactory; +import org.apache.tuscany.sca.policy.PolicyFactory; + +/** + * Test resolving SCA XML assemblies. + * + * @version $Rev$ $Date$ + */ +public class ResolveTestCase extends TestCase { + + private XMLInputFactory inputFactory; + private DefaultStAXArtifactProcessorExtensionPoint staxProcessors; + private ExtensibleStAXArtifactProcessor staxProcessor; + private TestModelResolver resolver; + private AssemblyFactory factory; + private PolicyFactory policyFactory; + private InterfaceContractMapper mapper; + + public void setUp() throws Exception { + factory = new DefaultAssemblyFactory(); + policyFactory = new DefaultPolicyFactory(); + mapper = new InterfaceContractMapperImpl(); + inputFactory = XMLInputFactory.newInstance(); + staxProcessors = new DefaultStAXArtifactProcessorExtensionPoint(); + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, XMLInputFactory.newInstance(), XMLOutputFactory.newInstance()); + resolver = new TestModelResolver(getClass().getClassLoader()); + } + + public void tearDown() throws Exception { + inputFactory = null; + staxProcessors = null; + resolver = null; + policyFactory = null; + factory = null; + mapper = null; + } + + public void testResolveConstrainingType() throws Exception { + InputStream is = getClass().getResourceAsStream("CalculatorComponent.constrainingType"); + ConstrainingTypeProcessor constrainingTypeReader = new ConstrainingTypeProcessor(factory, policyFactory, staxProcessor); + XMLStreamReader reader = inputFactory.createXMLStreamReader(is); + ConstrainingType constrainingType = constrainingTypeReader.read(reader); + is.close(); + assertNotNull(constrainingType); + resolver.addModel(constrainingType); + + is = getClass().getResourceAsStream("TestAllCalculator.composite"); + CompositeProcessor compositeReader = new CompositeProcessor(factory, policyFactory, mapper, staxProcessor); + reader = inputFactory.createXMLStreamReader(is); + Composite composite = compositeReader.read(reader); + is.close(); + assertNotNull(composite); + + compositeReader.resolve(composite, resolver); + + assertEquals(composite.getConstrainingType(), constrainingType); + assertEquals(composite.getComponents().get(0).getConstrainingType(), constrainingType); + } + + public void testResolveComposite() throws Exception { + InputStream is = getClass().getResourceAsStream("Calculator.composite"); + CompositeProcessor compositeReader = new CompositeProcessor(factory, policyFactory, mapper, staxProcessor); + XMLStreamReader reader = inputFactory.createXMLStreamReader(is); + Composite nestedComposite = compositeReader.read(reader); + is.close(); + assertNotNull(nestedComposite); + resolver.addModel(nestedComposite); + + is = getClass().getResourceAsStream("TestAllCalculator.composite"); + compositeReader = new CompositeProcessor(factory, policyFactory, mapper, staxProcessor); + reader = inputFactory.createXMLStreamReader(is); + Composite composite = compositeReader.read(reader); + is.close(); + + compositeReader.resolve(composite, resolver); + + assertEquals(composite.getComponents().get(2).getImplementation(), nestedComposite); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/StAXPerfTest.java b/sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/StAXPerfTest.java new file mode 100644 index 0000000000..46ed9ea425 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/StAXPerfTest.java @@ -0,0 +1,105 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.assembly.xml; + +import java.io.InputStream; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLOutputFactory; +import javax.xml.stream.XMLStreamReader; + +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.contribution.processor.DefaultStAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; +import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; +import org.apache.tuscany.sca.interfacedef.impl.InterfaceContractMapperImpl; +import org.apache.tuscany.sca.policy.DefaultPolicyFactory; +import org.apache.tuscany.sca.policy.PolicyFactory; + +/** + * Test the performance of StAX parsing. + * + * @version $Rev$ $Date$ + */ +public class StAXPerfTest { + + private XMLInputFactory inputFactory; + private AssemblyFactory assemblyFactory; + private PolicyFactory policyFactory; + private InterfaceContractMapper interfaceContractMapper; + private ExtensibleStAXArtifactProcessor staxProcessor; + private DefaultStAXArtifactProcessorExtensionPoint staxProcessors; + + public static void main(String[] args) throws Exception { + + StAXPerfTest perfTest = new StAXPerfTest(); + perfTest.setUp(); + + // Warm up + for (long i = 0; i < 500; i++) { + perfTest.testReadComposite(); + } + + long begin = System.currentTimeMillis(); + long iter = 50000; + for (long i = 0; i < iter; i++) { + perfTest.testReadComposite(); + } + long end = System.currentTimeMillis(); + System.out.println("Iterations: " + iter); + double time = ((double)(end - begin)) / ((double)iter); + System.out.println("Time: " + time); + System.out.println("Memory: " + Runtime.getRuntime().totalMemory() / 1024); + + } + + public void setUp() throws Exception { + inputFactory = XMLInputFactory.newInstance(); + assemblyFactory = new DefaultAssemblyFactory(); + policyFactory = new DefaultPolicyFactory(); + interfaceContractMapper = new InterfaceContractMapperImpl(); + staxProcessors = new DefaultStAXArtifactProcessorExtensionPoint(); + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, XMLInputFactory.newInstance(), XMLOutputFactory.newInstance()); + } + + public void tearDown() throws Exception { + assemblyFactory = null; + policyFactory = null; + inputFactory = null; + staxProcessors = null; + } + + public void testReadComposite() throws Exception { + InputStream is = getClass().getResourceAsStream("TestAllCalculator.composite"); + CompositeProcessor loader = new CompositeProcessor(assemblyFactory, + policyFactory, interfaceContractMapper, staxProcessor); + XMLStreamReader reader = inputFactory.createXMLStreamReader(is); + + Composite composite = loader.read(reader); + is.close(); + + if (composite == null) { + throw new IllegalStateException("Null composite"); + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestModelResolver.java b/sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestModelResolver.java new file mode 100644 index 0000000000..7a4077188a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestModelResolver.java @@ -0,0 +1,63 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.assembly.xml; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; + + +/** + * A default implementation of an artifact resolver, based on a map. + * + * @version $Rev$ $Date$ + */ +public class TestModelResolver implements ModelResolver { + private static final long serialVersionUID = -7826976465762296634L; + + private Map map = new HashMap(); + + public TestModelResolver(ClassLoader 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 { + + // Return the unresolved object + return unresolved; + } + } + + public void addModel(Object resolved) { + map.put(resolved, resolved); + } + + public Object removeModel(Object resolved) { + return map.remove(resolved); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/WireTestCase.java b/sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/WireTestCase.java new file mode 100644 index 0000000000..2b95057f23 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/WireTestCase.java @@ -0,0 +1,126 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.assembly.xml; + +import java.io.InputStream; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLOutputFactory; +import javax.xml.stream.XMLStreamReader; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.ConstrainingType; +import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory; +import org.apache.tuscany.sca.assembly.DefaultSCABindingFactory; +import org.apache.tuscany.sca.assembly.SCABindingFactory; +import org.apache.tuscany.sca.assembly.builder.impl.CompositeBuilderImpl; +import org.apache.tuscany.sca.contribution.processor.DefaultStAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; +import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; +import org.apache.tuscany.sca.interfacedef.impl.InterfaceContractMapperImpl; +import org.apache.tuscany.sca.policy.DefaultPolicyFactory; +import org.apache.tuscany.sca.policy.PolicyFactory; + +/** + * Test the wiring of SCA XML assemblies. + * + * @version $Rev$ $Date$ + */ +public class WireTestCase extends TestCase { + + private XMLInputFactory inputFactory; + private DefaultStAXArtifactProcessorExtensionPoint staxProcessors; + private ExtensibleStAXArtifactProcessor staxProcessor; + private TestModelResolver resolver; + private AssemblyFactory assemblyFactory; + private SCABindingFactory scaBindingFactory; + private PolicyFactory policyFactory; + private InterfaceContractMapper mapper; + + public void setUp() throws Exception { + inputFactory = XMLInputFactory.newInstance(); + staxProcessors = new DefaultStAXArtifactProcessorExtensionPoint(); + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, XMLInputFactory.newInstance(), XMLOutputFactory.newInstance()); + resolver = new TestModelResolver(getClass().getClassLoader()); + assemblyFactory = new DefaultAssemblyFactory(); + scaBindingFactory = new DefaultSCABindingFactory(); + policyFactory = new DefaultPolicyFactory(); + mapper = new InterfaceContractMapperImpl(); + } + + public void tearDown() throws Exception { + inputFactory = null; + staxProcessors = null; + resolver = null; + policyFactory = null; + assemblyFactory = null; + mapper = null; + } + + public void testResolveConstrainingType() throws Exception { + InputStream is = getClass().getResourceAsStream("CalculatorComponent.constrainingType"); + ConstrainingTypeProcessor constrainingTypeReader = new ConstrainingTypeProcessor(assemblyFactory, policyFactory, staxProcessor); + XMLStreamReader reader = inputFactory.createXMLStreamReader(is); + ConstrainingType constrainingType = constrainingTypeReader.read(reader); + is.close(); + assertNotNull(constrainingType); + resolver.addModel(constrainingType); + + is = getClass().getResourceAsStream("TestAllCalculator.composite"); + CompositeProcessor compositeReader = new CompositeProcessor(assemblyFactory, policyFactory, mapper, staxProcessor); + reader = inputFactory.createXMLStreamReader(is); + Composite composite = compositeReader.read(reader); + is.close(); + assertNotNull(composite); + + compositeReader.resolve(composite, resolver); + CompositeBuilderImpl compositeUtil = new CompositeBuilderImpl(assemblyFactory, scaBindingFactory, mapper, null); + compositeUtil.build(composite); + + assertEquals(composite.getConstrainingType(), constrainingType); + assertEquals(composite.getComponents().get(0).getConstrainingType(), constrainingType); + } + + public void testResolveComposite() throws Exception { + InputStream is = getClass().getResourceAsStream("Calculator.composite"); + CompositeProcessor compositeReader = new CompositeProcessor(assemblyFactory, policyFactory, mapper, staxProcessor); + XMLStreamReader reader = inputFactory.createXMLStreamReader(is); + Composite nestedComposite = compositeReader.read(reader); + is.close(); + assertNotNull(nestedComposite); + resolver.addModel(nestedComposite); + + is = getClass().getResourceAsStream("TestAllCalculator.composite"); + compositeReader = new CompositeProcessor(assemblyFactory, policyFactory, mapper, staxProcessor); + reader = inputFactory.createXMLStreamReader(is); + Composite composite = compositeReader.read(reader); + is.close(); + + compositeReader.resolve(composite, resolver); + CompositeBuilderImpl compositeUtil = new CompositeBuilderImpl(assemblyFactory, scaBindingFactory, mapper, null); + compositeUtil.build(composite); + + assertEquals(composite.getComponents().get(2).getImplementation(), nestedComposite); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/WriteAllTestCase.java b/sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/WriteAllTestCase.java new file mode 100644 index 0000000000..39b9b04a3e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/WriteAllTestCase.java @@ -0,0 +1,115 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.assembly.xml; + +import java.io.ByteArrayOutputStream; +import java.io.InputStream; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLOutputFactory; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.ComponentType; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.ConstrainingType; +import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory; +import org.apache.tuscany.sca.assembly.DefaultSCABindingFactory; +import org.apache.tuscany.sca.assembly.SCABindingFactory; +import org.apache.tuscany.sca.assembly.builder.impl.CompositeBuilderImpl; +import org.apache.tuscany.sca.contribution.processor.DefaultStAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; +import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; +import org.apache.tuscany.sca.interfacedef.impl.InterfaceContractMapperImpl; +import org.apache.tuscany.sca.policy.DefaultPolicyFactory; +import org.apache.tuscany.sca.policy.PolicyFactory; + +/** + * Test writing SCA XML assemblies. + * + * @version $Rev$ $Date$ + */ +public class WriteAllTestCase extends TestCase { + private DefaultStAXArtifactProcessorExtensionPoint staxProcessors; + private ExtensibleStAXArtifactProcessor staxProcessor; + private TestModelResolver resolver; + private AssemblyFactory assemblyFactory; + private SCABindingFactory scaBindingFactory; + private PolicyFactory policyFactory; + private InterfaceContractMapper mapper; + private CompositeBuilderImpl compositeUtil; + + + public void setUp() throws Exception { + assemblyFactory = new DefaultAssemblyFactory(); + scaBindingFactory = new DefaultSCABindingFactory(); + policyFactory = new DefaultPolicyFactory(); + mapper = new InterfaceContractMapperImpl(); + compositeUtil = new CompositeBuilderImpl(assemblyFactory, scaBindingFactory, mapper, null); + staxProcessors = new DefaultStAXArtifactProcessorExtensionPoint(); + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, XMLInputFactory.newInstance(), XMLOutputFactory.newInstance()); + staxProcessors.addArtifactProcessor(new CompositeProcessor(assemblyFactory, policyFactory, mapper, staxProcessor)); + staxProcessors.addArtifactProcessor(new ComponentTypeProcessor(assemblyFactory, policyFactory, staxProcessor)); + staxProcessors.addArtifactProcessor(new ConstrainingTypeProcessor(assemblyFactory, policyFactory, staxProcessor)); + resolver = new TestModelResolver(getClass().getClassLoader()); + } + + public void tearDown() throws Exception { + staxProcessors = null; + resolver = null; + policyFactory = null; + assemblyFactory = null; + mapper = null; + } + + public void testReadWriteComposite() throws Exception { + InputStream is = getClass().getResourceAsStream("TestAllCalculator.composite"); + Composite composite = staxProcessor.read(is, Composite.class); + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + staxProcessor.write(composite, bos); + } + + public void testReadWireWriteComposite() throws Exception { + InputStream is = getClass().getResourceAsStream("TestAllCalculator.composite"); + Composite composite = staxProcessor.read(is, Composite.class); + staxProcessor.resolve(composite, resolver); + compositeUtil.build(composite); + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + staxProcessor.write(composite, bos); + } + + public void testReadWriteComponentType() throws Exception { + InputStream is = getClass().getResourceAsStream("CalculatorImpl.componentType"); + ComponentType componentType = staxProcessor.read(is, ComponentType.class); + staxProcessor.resolve(componentType, resolver); + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + staxProcessor.write(componentType, bos); + } + + public void testReadWriteConstrainingType() throws Exception { + InputStream is = getClass().getResourceAsStream("CalculatorComponent.constrainingType"); + ConstrainingType constrainingType = staxProcessor.read(is, ConstrainingType.class); + staxProcessor.resolve(constrainingType, resolver); + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + staxProcessor.write(constrainingType, bos); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/Calculator.composite b/sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/Calculator.composite new file mode 100644 index 0000000000..4546fddb2d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/Calculator.composite @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/CalculatorComponent.constrainingType b/sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/CalculatorComponent.constrainingType new file mode 100644 index 0000000000..072fe8fde1 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/CalculatorComponent.constrainingType @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/CalculatorImpl.componentType b/sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/CalculatorImpl.componentType new file mode 100644 index 0000000000..d67ba3ec2b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/CalculatorImpl.componentType @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/TestAllCalculator.composite b/sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/TestAllCalculator.composite new file mode 100644 index 0000000000..6044d973b7 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/TestAllCalculator.composite @@ -0,0 +1,119 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + AValue + InterestingURI + + + BValue + BoringURI + + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/TestAllDivide.composite b/sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/TestAllDivide.composite new file mode 100644 index 0000000000..d59e69209d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/TestAllDivide.composite @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly/.checkstyle b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/.checkstyle new file mode 100644 index 0000000000..e3c216986d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/.checkstyle @@ -0,0 +1,24 @@ + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly/.pmd b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/.pmd new file mode 100644 index 0000000000..aa1ce3e754 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/.pmd @@ -0,0 +1,21 @@ + + + +truefalse \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly/.ruleset b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/.ruleset new file mode 100644 index 0000000000..ba9b5ce886 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/.ruleset @@ -0,0 +1,190 @@ + + + + PMD Plugin preferences rule set + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly/DISCLAIMER b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/DISCLAIMER new file mode 100644 index 0000000000..d68a410903 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/DISCLAIMER @@ -0,0 +1,8 @@ +Apache Tuscany is an effort undergoing incubation at The Apache Software +Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is +required of all newly accepted projects until a further review indicates that +the infrastructure, communications, and decision making process have stabilized +in a manner consistent with other successful ASF projects. While incubation +status is not necessarily a reflection of the completeness or stability of the +code, it does indicate that the project has yet to be fully endorsed by the ASF. + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly/LICENSE b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly/NOTICE b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/NOTICE new file mode 100644 index 0000000000..94481d6cfa --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2007 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly/pom.xml b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/pom.xml new file mode 100644 index 0000000000..8d167daa6a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/pom.xml @@ -0,0 +1,44 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 0.91-incubating-SNAPSHOT + ../pom.xml + + tuscany-assembly + Apache Tuscany Assembly Model + + + + org.apache.tuscany.sca + tuscany-policy + 0.91-incubating-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-interface + 0.91-incubating-SNAPSHOT + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/AbstractContract.java b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/AbstractContract.java new file mode 100644 index 0000000000..8f371defde --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/AbstractContract.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; + +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.policy.IntentAttachPoint; + +/** + * Interface contracts define one or more business functions. These business + * functions are provided by services and are used by references. + * + * @version $Rev$ $Date$ + */ +public interface AbstractContract extends Base, IntentAttachPoint { + + /** + * Returns the name of the contract. + * + * @return the name of the contract + */ + String getName(); + + /** + * Sets the name of the contract. + * + * @param name the name of the contract + */ + void setName(String name); + + /** + * Returns the interface contract defining the interface and callback + * interface for the contract. + * + * @return the interface contract + */ + InterfaceContract getInterfaceContract(); + + + /** + * Returns the interface contract defining the interface and callback + * interface for the contract. + * + * @param interfaceContract the interface contract + */ + void setInterfaceContract(InterfaceContract interfaceContract); +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/AbstractProperty.java b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/AbstractProperty.java new file mode 100644 index 0000000000..35c5da4123 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/AbstractProperty.java @@ -0,0 +1,122 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.assembly; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.policy.IntentAttachPoint; + +/** + * A property allows for the configuration of an implementation with externally + * set data values. An implementation can have zero or more properties. Each + * property has a data type, which may be either simple or complex. An + * implementation may also define a default value for a property. + */ +public interface AbstractProperty extends Base, IntentAttachPoint { + + /** + * Returns the property name. + * + * @return the property name + */ + String getName(); + + /** + * Sets the property name. + * + * @param name the property name + */ + void setName(String name); + + /** + * Returns the default value of the property. + * + * @return the default value of ths property + */ + Object getValue(); + + /** + * Sets the default value of the property. + * + * @param defaultValue the default value of ths property + */ + void setValue(Object defaultValue); + + /** + * Returns true if the property allows multiple values. + * + * @return true if the property allows multiple values + */ + boolean isMany(); + + /** + * Sets whether or not the property allows multiple values. + * + * @param many true if the property should allow multiple values + */ + void setMany(boolean many); + + /** + * Returns true if a value must be supplied for the property. + * + * @return true is a value must be supplied for the property + */ + boolean isMustSupply(); + + /** + * Sets whether a value must be supplied for the property. + * + * @param mustSupply set to true to require that a value be supplied for + * uses of this property + */ + void setMustSupply(boolean mustSupply); + + /** + * Returns the data type of this property. This is the qualified name of an + * XML schema type. + * + * @return the type of this property + */ + QName getXSDType(); + + /** + * Sets the data type of this property. This is the qualified name of an XML + * schema type. + * + * @param type the type of this property + */ + void setXSDType(QName type); + + /** + * Returns the element defining the data type of this property. This is the + * qualified name of an XML schema element. + * + * @return the element defining the type of this property + */ + QName getXSDElement(); + + /** + * Sets the element defining the data type of this property. This is the + * qualified name of an XML schema element. + * + * @param type the element defining the type of this property + */ + void setXSDElement(QName element); + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/AbstractReference.java b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/AbstractReference.java new file mode 100644 index 0000000000..a9ef26bbb9 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/AbstractReference.java @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.assembly; + +/** + * Represents a reference contract. + * + * @version $Rev$ $Date$ + */ +public interface AbstractReference extends AbstractContract { + + /** + * Returns the multiplicity allowed for wires connected to this reference. + * + * @return the multiplicity allowed for wires connected to this reference + */ + Multiplicity getMultiplicity(); + + /** + * Sets the multiplicity allowed for wires connected to this reference. + * + * @param multiplicity the multiplicity allowed for wires connected to this + * reference + */ + void setMultiplicity(Multiplicity multiplicity); + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/AbstractService.java b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/AbstractService.java new file mode 100644 index 0000000000..9ae511c07b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/AbstractService.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.assembly; + +/** + * Represents a service contract. + * + * @version $Rev$ $Date$ + */ +public interface AbstractService extends AbstractContract { + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/AssemblyFactory.java b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/AssemblyFactory.java new file mode 100644 index 0000000000..3937d34f92 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/AssemblyFactory.java @@ -0,0 +1,156 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.assembly; + +import org.apache.tuscany.sca.interfacedef.Operation; + +/** + * A factory for the assembly model + * + * @version $Rev$ $Date$ + */ +public interface AssemblyFactory { + + /** + * Create a new abstract property. + * + * @return a new abstract property + */ + AbstractProperty createAbstractProperty(); + + /** + * Create a new abstract reference. + * + * @return a new abstract reference + */ + AbstractReference createAbstractReference(); + + /** + * Create a new abstract service. + * + * @return a new abstract service + */ + AbstractService createAbstractService(); + + /** + * Create a new callback. + * + * @return + */ + Callback createCallback(); + + /** + * Create a new component. + * + * @return a new component + */ + Component createComponent(); + + /** + * Create a new component property. + * + * @return a new component property + */ + ComponentProperty createComponentProperty(); + + /** + * Create a new component reference. + * + * @return a new component reference + */ + ComponentReference createComponentReference(); + + /** + * Create a new component service. + * + * @return a new component service + */ + ComponentService createComponentService(); + + /** + * Create a new component type + * + * @return a new component type + */ + ComponentType createComponentType(); + + /** + * Create a new composite. + * + * @return a new composite + */ + Composite createComposite(); + + /** + * Create a new composite reference. + * + * @return a new composite reference + */ + CompositeReference createCompositeReference(); + + /** + * Create a new composite service. + * + * @return a new composite service + */ + CompositeService createCompositeService(); + + /** + * Create a new constraining type. + * + * @return a new constraining type + */ + ConstrainingType createConstrainingType(); + + /** + * Create a new property. + * + * @return a new property + */ + Property createProperty(); + + /** + * Create a new reference. + * + * @return a new reference + */ + Reference createReference(); + + /** + * Create a new service. + * + * @return a new service + */ + Service createService(); + + /** + * Create a new wire. + * + * @return a new wire + */ + Wire createWire(); + + /** + * Create a new operation. + * + * @return a new operation + */ + Operation createOperation(); + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Base.java b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Base.java new file mode 100644 index 0000000000..9681ff0c40 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Base.java @@ -0,0 +1,51 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.assembly; + +import java.util.List; + +/** + * Base interface for all assembly model objects. + * + * @version $Rev$ $Date$ + */ +public interface Base { + + /** + * Returns a list of extension objects contained in this model object. + * + * @return a list of extension objects container in this model object + */ + List getExtensions(); + + /** + * Returns true if the model element is unresolved. + * + * @return true if the model element is unresolved. + */ + boolean isUnresolved(); + + /** + * Sets whether the model element is unresolved. + * + * @param unresolved whether the model element is unresolved + */ + void setUnresolved(boolean unresolved); + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Binding.java b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Binding.java new file mode 100644 index 0000000000..8d7d6958be --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Binding.java @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.assembly; + +import org.apache.tuscany.sca.policy.IntentAttachPoint; +import org.apache.tuscany.sca.policy.PolicySetAttachPoint; + +/** + * Represents a binding. + * + * @version $Rev$ $Date$ + */ +public interface Binding extends Base, IntentAttachPoint, PolicySetAttachPoint { + + /** + * Returns the binding URI. + * + * @return the binding uri + */ + String getURI(); + + /** + * Sets the binding URI. + * + * @param uri the binding uri + */ + void setURI(String uri); + + /** + * Returns the binding name. + * + * @return the binding name + */ + String getName(); + + /** + * Sets the binding name. + * + * @param name the binding name + */ + void setName(String name); +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Callback.java b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Callback.java new file mode 100644 index 0000000000..b50e4ec06b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Callback.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.assembly; + +import java.util.List; + +import org.apache.tuscany.sca.policy.IntentAttachPoint; +import org.apache.tuscany.sca.policy.PolicySetAttachPoint; + +/** + * Represents a callback object describing the bindings to use for callbacks. + * + * @version $Rev$ $Date$ + */ +public interface Callback extends Base, IntentAttachPoint, PolicySetAttachPoint { + + /** + * Returns the bindings supported for callbacks. + * + * @return the bindings supported for callbacks + */ + List getBindings(); + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Component.java b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Component.java new file mode 100644 index 0000000000..72ee71de8c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Component.java @@ -0,0 +1,133 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.assembly; + +import java.util.List; + +import org.apache.tuscany.sca.policy.IntentAttachPoint; +import org.apache.tuscany.sca.policy.PolicySetAttachPoint; + +/** + * Represents a component. A component is a configured instance of an + * implementation. + * + * @version $Rev$ $Date$ + */ +public interface Component extends Base, IntentAttachPoint, PolicySetAttachPoint, Visitable { + + /** + * Returns the URI of the component. + * + * @return the URI of the component + */ + String getURI(); + + /** + * Sets the URI of the component. + * + * @param uri the URI of the component + */ + void setURI(String uri); + + /** + * Returns the name of the component. + * + * @return the name of the component + */ + String getName(); + + /** + * Sets the name of the component. + * + * @param name the name of the component + */ + void setName(String name); + + /** + * Returns the component implementation. + * + * @return the component implementation + */ + Implementation getImplementation(); + + /** + * Sets the component implementation + * + * @param implementation the component implementation + */ + void setImplementation(Implementation implementation); + + /** + * Returns a list of references used by the component. + * + * @return a list of references used by the component + */ + List getReferences(); + + /** + * Returns a list of services exposed by the component. + * + * @return a list of services exposed by the component + */ + List getServices(); + + /** + * Returns a list of properties for the component. + * + * @return a list of properties + */ + List getProperties(); + + /** + * Returns a constraining type defining the shape of the component. + * + * @return a constraining type + */ + ConstrainingType getConstrainingType(); + + /** + * Sets a constraining type defining the shape of the component. + * + * @param constrainingType the constraining type + */ + void setConstrainingType(ConstrainingType constrainingType); + + /** + * Returns true if the component references should be autowired. + * + * @return whether component references should be autowired. + */ + boolean isAutowire(); + + /** + * Sets whether component references should be autowired. + * + * @param autowire whether component references should be autowired + */ + void setAutowire(boolean autowire); + + /** + * Returns a clone of the component. + * + * @return a clone of the component + * @throws CloneNotSupportedException + */ + Object clone() throws CloneNotSupportedException; + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ComponentProperty.java b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ComponentProperty.java new file mode 100644 index 0000000000..9a344afb09 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ComponentProperty.java @@ -0,0 +1,80 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.assembly; + +/** + * Represents a configured property of a component. + * + * @version $Rev$ $Date$ + */ +public interface ComponentProperty extends Property, Cloneable { + + /** + * Returns the property defined by the component implementation. + * + * @return the property defined by the component implementation + */ + Property getProperty(); + + /** + * Sets the property type that defines this property. + * + * @param type the property that defines this property + */ + void setProperty(Property property); + + /** + * Returns an xpath expression referencing a property of the enclosing + * composite. + * + * @return an xpath expression referencing a property of the enclosing + * composite + */ + String getSource(); + + /** + * Sets an xpath expression referencing a property of the enclosing + * composite. + * + * @param source an xpath expression referencing a property of the enclosing + * composite + */ + void setSource(String source); + + /** + * Returns a URI to a file containing the property value. + * + * @return a URI to a file containing the property value + */ + String getFile(); + + /** + * Sets a URI to a file containing the property value. + * + * @param file a URI to a file containing the property value + */ + void setFile(String file); + + /** + * Clone the component property. + * + * @return a clone of the component property + */ + Object clone() throws CloneNotSupportedException; +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ComponentReference.java b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ComponentReference.java new file mode 100644 index 0000000000..1f4b4f0801 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ComponentReference.java @@ -0,0 +1,64 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.assembly; + + +/** + * An instance of a reference associated with a particular component. + * + * @version $Rev$ $Date$ + */ +public interface ComponentReference extends Reference { + + /** + * Returns the reference defined by the implementation for this reference. + * + * @return + */ + Reference getReference(); + + /** + * Sets the reference defined by the implementation for this reference. + * + * @param reference + */ + void setReference(Reference reference); + + /** + * Returns true if the reference should be autowired. + * + * @return whether the reference should be autowired. + */ + boolean isAutowire(); + + /** + * Sets whether the reference should be autowired. + * + * @param autowire whether the reference should be autowired + */ + void setAutowire(boolean autowire); + + + /** + * Clone the component reference. + * + * @return a clone of the component reference + */ + Object clone() throws CloneNotSupportedException; +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ComponentService.java b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ComponentService.java new file mode 100644 index 0000000000..c0e42dbb93 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ComponentService.java @@ -0,0 +1,49 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.assembly; + + +/** + * An addressable instance of a service associated with a particular component. + * + * @version $Rev$ $Date$ + */ +public interface ComponentService extends Service { + + /** + * Returns the service defined by the implementation for this service. + * + * @return + */ + Service getService(); + + /** + * Sets the service defined by the implementation for this service. + * + * @param service + */ + void setService(Service service); + + /** + * Clone the component service. + * + * @return a clone of the component service + */ + Object clone() throws CloneNotSupportedException; +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ComponentType.java b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ComponentType.java new file mode 100644 index 0000000000..ffdef42aed --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ComponentType.java @@ -0,0 +1,80 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.assembly; + +import java.util.List; + +import org.apache.tuscany.sca.policy.IntentAttachPoint; +import org.apache.tuscany.sca.policy.PolicySetAttachPoint; + +/** + * Describes an implementation and represents its configurable aspects. + * + * @version $Rev$ $Date$ + */ +public interface ComponentType extends Base, IntentAttachPoint, PolicySetAttachPoint { + + /** + * Returns the URI of this component type. + * @return the URI of the component type + */ + String getURI(); + + /** + * Sets the URI of this component type. + * @param uri the URI of the component type + */ + void setURI(String uri); + + /** + * Returns a list of services that are offered. + * + * @return a list of services that are offered + */ + List getServices(); + + /** + * Returns the list of reference types that are used. + * + * @return the list of reference types that are used + */ + List getReferences(); + + /** + * Returns the list of properties that can be set. + * + * @return the list of properties that can be set + */ + List getProperties(); + + /** + * Returns a constraining type defining the shape of the implementation. + * + * @return a constraining type + */ + ConstrainingType getConstrainingType(); + + /** + * Sets a constraining type defining the shape of the implementation. + * + * @param constrainingType the constraining type to set + */ + void setConstrainingType(ConstrainingType constrainingType); + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Composite.java b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Composite.java new file mode 100644 index 0000000000..1fe402d829 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Composite.java @@ -0,0 +1,108 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.assembly; + +import java.util.List; + +import javax.xml.namespace.QName; + + +/** + * Represents a composite. + * + * @version $Rev$ $Date$ + */ +public interface Composite extends Implementation, Visitable { + + /** + * Returns the name of the composite. + * + * @return the name of the composite + */ + QName getName(); + + /** + * Sets the name of the composite. + * + * @param name the name of the composite + */ + void setName(QName name); + + /** + * Returns a list of composites included in this composite. + * + * @return a list of composites included in this composite. + */ + List getIncludes(); + + /** + * Returns a list of components contained in this composite. + * + * @return a list of components contained in this composite + */ + List getComponents(); + + /** + * Returns a list of wires contained in this composite. + * + * @return a list of wires contained in this composite + */ + List getWires(); + + /** + * Returns true if all the components within the composite must run in the + * same process. + * + * @return true if all the components within the composite must run in the + * same process + */ + boolean isLocal(); + + /** + * Sets whether all the components within the composite must run in the same + * process. + * + * @param local whether all the components within the composite must run in + * the same process + */ + void setLocal(boolean local); + + /** + * Returns true if autowiring is enabled in the composite. + * + * @return true if autowiring is enabled in the composite + */ + boolean isAutowire(); + + /** + * Sets whether autowiring is enabled in the composite. + * + * @param autowire whether autowiring is enabled in the composite + */ + void setAutowire(boolean autowire); + + /** + * Returns a clone of the component type. + * + * @return a clone of the component type + * @throws CloneNotSupportedException + */ + Object clone() throws CloneNotSupportedException; + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/CompositeReference.java b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/CompositeReference.java new file mode 100644 index 0000000000..d3fa80ba74 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/CompositeReference.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.assembly; + +import java.util.List; + +/** + * Represents composite reference. + * + * @version $Rev$ $Date$ + */ +public interface CompositeReference extends Reference { + + /** + * Returns the promoted composite references. + * + * @return the promoted composite references + */ + List getPromotedReferences(); + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/CompositeService.java b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/CompositeService.java new file mode 100644 index 0000000000..757e2bda2e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/CompositeService.java @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.assembly; + +/** + * Represents a composite service. + * + * @version $Rev$ $Date$ + */ +public interface CompositeService extends Service { + + /** + * Returns the promoted component service . + * + * @return the promoted component service. + */ + ComponentService getPromotedService(); + + /** + * Sets the promoted component service + * + * @param promotedService the promoted component service. + */ + void setPromotedService(ComponentService promotedService); + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ConstrainingType.java b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ConstrainingType.java new file mode 100644 index 0000000000..4119d0a268 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ConstrainingType.java @@ -0,0 +1,72 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.assembly; + +import java.util.List; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.policy.IntentAttachPoint; + +/** + * A constrainingType provides the "shape" for a component and its + * implementation. Any component configuration that points to a constrainingType + * is constrained by this shape. The constrainingType specifies the services, + * references and properties that must be implemented. + * + * @version $Rev$ $Date$ + */ +public interface ConstrainingType extends Base, IntentAttachPoint { + + /** + * Returns the name of the constrainingType. + * + * @return the name of the constrainingType + */ + QName getName(); + + /** + * Sets the name of the constrainingType. + * + * @param name the name of the constrainingType + */ + void setName(QName name); + + /** + * Returns a list of services that are offered. + * + * @return a list of services that are offered + */ + List getServices(); + + /** + * Returns the list of references that are used. + * + * @return the list of references that are used + */ + List getReferences(); + + /** + * Returns the list of properties that can be set. + * + * @return the list of properties that can be set + */ + List getProperties(); + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Contract.java b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Contract.java new file mode 100644 index 0000000000..830ede478a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Contract.java @@ -0,0 +1,63 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.assembly; + +import java.util.List; + +import org.apache.tuscany.sca.policy.PolicySetAttachPoint; + +/** + * Represents a contract. A contract can be either a service or a reference. + * + * @version $Rev$ $Date$ + */ +public interface Contract extends AbstractContract, PolicySetAttachPoint { + + /** + * Returns the bindings supported by this contract. + * + * @return the bindings supported by this contract + */ + List getBindings(); + + /** + * Returns a binding of the specified type or null if there is no such + * binding configured on this contract. + * + * @param the binding type + * @param bindingClass the binding type class + * @return the binding or null if there is no binding of the specified type + */ + B getBinding(Class bindingClass); + + /** + * Returns a callback definition of the bindings to use for callbacks. + * + * @return a definition of the bindings to use for callbacks + */ + Callback getCallback(); + + /** + * Sets a callback definition of the bindings to use for callbacks + * + * @param callback a definition of the bindings to use for callbacks + */ + void setCallback(Callback callback); + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/DefaultAssemblyFactory.java b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/DefaultAssemblyFactory.java new file mode 100644 index 0000000000..5dd256e3c4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/DefaultAssemblyFactory.java @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.assembly; + +import org.apache.tuscany.sca.assembly.impl.AssemblyFactoryImpl; + +/** + * A factory for the assembly model. + * + * @version $Rev$ $Date$ + */ +public class DefaultAssemblyFactory extends AssemblyFactoryImpl implements AssemblyFactory { + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/DefaultSCABindingFactory.java b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/DefaultSCABindingFactory.java new file mode 100644 index 0000000000..793a8f960b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/DefaultSCABindingFactory.java @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.assembly; + +import org.apache.tuscany.sca.assembly.impl.SCABindingFactoryImpl; + +/** + * A factory for the SCA binding model. + * + * @version $Rev$ $Date$ + */ +public class DefaultSCABindingFactory extends SCABindingFactoryImpl implements SCABindingFactory { + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Implementation.java b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Implementation.java new file mode 100644 index 0000000000..e79f9bccdb --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Implementation.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.assembly; + +/** + * Represents a component implementation. + * + * @version $Rev$ $Date$ + */ +public interface Implementation extends ComponentType { + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Multiplicity.java b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Multiplicity.java new file mode 100644 index 0000000000..5d15ce9938 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Multiplicity.java @@ -0,0 +1,49 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.assembly; + +/** + * Enumeration for multiplicity. Defines the number of wires that can connect a + * reference to target services. + * + * @version $Rev$ $Date$ + */ +public enum Multiplicity { + + /** + * Zero or one wire can have the reference as a source. + */ + ZERO_ONE, + + /** + * The default setting, one wire can have the reference as a source. + */ + ONE_ONE, + + /** + * Zero or more wires can have the reference as a source. + */ + ZERO_N, + + /** + * One or more wires can have the reference as a source. + */ + ONE_N + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Property.java b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Property.java new file mode 100644 index 0000000000..98089d66cb --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Property.java @@ -0,0 +1,41 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.assembly; + +import org.apache.tuscany.sca.policy.PolicySetAttachPoint; + +/** + * A property allows for the configuration of an implementation with externally + * set data values. An implementation can have zero or more properties. Each + * property has a data type, which may be either simple or complex. An + * implementation may also define a default value for a property. + * + * @version $Rev$ $Date$ + */ +public interface Property extends AbstractProperty, PolicySetAttachPoint { + + /** + * Returns a clone of the property. + * + * @return a clone of the property + * @throws CloneNotSupportedException + */ + Object clone() throws CloneNotSupportedException; + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Reference.java b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Reference.java new file mode 100644 index 0000000000..3b2d2b124c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Reference.java @@ -0,0 +1,64 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.assembly; + +import java.util.List; + +/** + * Represents a reference. References within an implementation represent links + * to services that the implementation uses that must be provided by other + * components. + * + * @version $Rev$ $Date$ + */ +public interface Reference extends AbstractReference, Contract { + + /** + * Returns a boolean value, "false" by default, which indicates that the + * implementation wires this reference dynamically. + * + * @return true if the implementation wires this reference dynamically + */ + boolean isWiredByImpl(); + + /** + * Sets a boolean value, "false" by default, which indicates that the + * implementation wires this reference dynamically. + * + * @param wiredByImpl whether the implementation wires this reference + * dynamically + */ + void setWiredByImpl(boolean wiredByImpl); + + /** + * Returns the targets of this reference. + * + * @return the targets of this reference. + */ + List getTargets(); + + /** + * Returns a clone of the reference. + * + * @return a clone of the reference + * @throws CloneNotSupportedException + */ + Object clone() throws CloneNotSupportedException; + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/SCABinding.java b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/SCABinding.java new file mode 100644 index 0000000000..eaf60aa6d9 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/SCABinding.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; + +/** + * Represents an SCA binding. + * + * @version $Rev$ $Date$ + */ +public interface SCABinding extends Binding { + + Component getComponent(); + + void setComponent(Component component); + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/SCABindingFactory.java b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/SCABindingFactory.java new file mode 100644 index 0000000000..0abfd13d10 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/SCABindingFactory.java @@ -0,0 +1,36 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.assembly; + + +/** + * A factory for the SCA binding model + * + * @version $Rev$ $Date$ + */ +public interface SCABindingFactory { + + /** + * Create a new SCA binding. + * + * @return a new SCA binding + */ + SCABinding createSCABinding(); + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Service.java b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Service.java new file mode 100644 index 0000000000..ea32efb769 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Service.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; + +/** + * Represents a service. Services are used to publish services provided by + * implementations, so that they are addressable by other components. + * + * @version $Rev$ $Date$ + */ +public interface Service extends AbstractService, Contract { + + /** + * Returns a clone of the service. + * + * @return a clone of the service + * @throws CloneNotSupportedException + */ + Object clone() throws CloneNotSupportedException; + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Visitable.java b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Visitable.java new file mode 100644 index 0000000000..6d3998b79e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Visitable.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; + +/** + * This interface is implemented by object that can accept a visitor. + */ +public interface Visitable { + + /** + * Accepts the given visitor. The visitor's visit method is called with this + * model object. If the visitor returns true, this method visits this + * object's children. + * + * @param visitor + * @return true if the model object's chidren should be visited, false if + * they should be skipped + */ + boolean accept(Visitor visitor); + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Visitor.java b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Visitor.java new file mode 100644 index 0000000000..a15354e401 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Visitor.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; + + +/** + * This interface is implemented by objects that visit assembly model trees. + */ +public interface Visitor { + + /** + * Visits the given assembly model object. + * + * @param object + * @return true if the model object's chidren should be visited, false if + * they should be skipped + */ + boolean visit(Base object); + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Wire.java b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Wire.java new file mode 100644 index 0000000000..58562eb5ad --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Wire.java @@ -0,0 +1,67 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.assembly; + +import org.apache.tuscany.sca.policy.IntentAttachPoint; +import org.apache.tuscany.sca.policy.PolicySetAttachPoint; + +/** + * Represents a wire. + * + * @version $Rev$ $Date$ + */ +public interface Wire extends Base, IntentAttachPoint, PolicySetAttachPoint { + + /** + * Returns the source of the wire. + * + * @return the source of the wire + */ + ComponentReference getSource(); + + /** + * Sets the source of the wire. + * + * @param source the source of the wire + */ + void setSource(ComponentReference source); + + /** + * Returns the target of the wire. + * + * @return the target of the wire + */ + ComponentService getTarget(); + + /** + * Sets the target of the wire. + * + * @param target the target of the wire + */ + void setTarget(ComponentService target); + + /** + * Returns a clone of the wire. + * + * @return a clone of the wire + * @throws CloneNotSupportedException + */ + Object clone() throws CloneNotSupportedException; + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/ComponentPreProcessor.java b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/ComponentPreProcessor.java new file mode 100644 index 0000000000..5f5856d051 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/ComponentPreProcessor.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.assembly.builder; + +import org.apache.tuscany.sca.assembly.Component; + +public interface ComponentPreProcessor { + + void preProcess(Component component); + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/CompositeBuilder.java b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/CompositeBuilder.java new file mode 100644 index 0000000000..26bdc3cffa --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/CompositeBuilder.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.assembly.builder; + +import org.apache.tuscany.sca.assembly.Composite; + +/** + * A builder that handles the configuration of the components inside a + * composite and the wiring of component references to component services. + * + * @version $Rev$ $Date$ + */ +public interface CompositeBuilder { + + /** + * Build, configure and wire a composite. + * + * @param composite + * @throws CompositeBuilderException + */ + void build(Composite composite) throws CompositeBuilderException; + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/CompositeBuilderException.java b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/CompositeBuilderException.java new file mode 100644 index 0000000000..5a2015f55e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/CompositeBuilderException.java @@ -0,0 +1,45 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.assembly.builder; + +/** + * Reports a composite builder exception. + * + * @version $Rev$ $Date$ + */ +public class CompositeBuilderException extends Exception { + private static final long serialVersionUID = -8916323176803443856L; + + public CompositeBuilderException() { + } + + public CompositeBuilderException(String message) { + super(message); + } + + public CompositeBuilderException(Throwable cause) { + super(cause); + } + + public CompositeBuilderException(String message, Throwable cause) { + super(message, cause); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/CompositeBuilderMonitor.java b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/CompositeBuilderMonitor.java new file mode 100644 index 0000000000..aecdf417f2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/CompositeBuilderMonitor.java @@ -0,0 +1,36 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.assembly.builder; + +/** + * A monitor for the composite builder. + * + * @version $Rev$ $Date$ + */ +public interface CompositeBuilderMonitor { + + /** + * Reports a build problem. + * + * @param problem + */ + void problem(Problem problem); + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/Problem.java b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/Problem.java new file mode 100644 index 0000000000..8965410438 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/Problem.java @@ -0,0 +1,45 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.assembly.builder; + + +/** + * Reports a composite assembly problem. + * + * @version $Rev$ $Date$ + */ +public interface Problem { + + public enum Severity { + INFO, + WARNING, + ERROR + } + + Severity getSeverity(); + + String getMessage(); + + Object getModel(); + + Object getResource(); + + Exception getCause(); +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBuilderImpl.java b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBuilderImpl.java new file mode 100644 index 0000000000..6234aed284 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBuilderImpl.java @@ -0,0 +1,1344 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.assembly.builder.impl; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.ComponentProperty; +import org.apache.tuscany.sca.assembly.ComponentReference; +import org.apache.tuscany.sca.assembly.ComponentService; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.CompositeReference; +import org.apache.tuscany.sca.assembly.CompositeService; +import org.apache.tuscany.sca.assembly.Implementation; +import org.apache.tuscany.sca.assembly.Multiplicity; +import org.apache.tuscany.sca.assembly.Property; +import org.apache.tuscany.sca.assembly.Reference; +import org.apache.tuscany.sca.assembly.SCABinding; +import org.apache.tuscany.sca.assembly.SCABindingFactory; +import org.apache.tuscany.sca.assembly.Service; +import org.apache.tuscany.sca.assembly.Wire; +import org.apache.tuscany.sca.assembly.builder.ComponentPreProcessor; +import org.apache.tuscany.sca.assembly.builder.CompositeBuilder; +import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException; +import org.apache.tuscany.sca.assembly.builder.CompositeBuilderMonitor; +import org.apache.tuscany.sca.assembly.builder.Problem; +import org.apache.tuscany.sca.assembly.builder.Problem.Severity; +import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; + +/** + * A builder that handles the configuration of the components inside a + * composite and the wiring of component references to component services. + * + * @version $Rev$ $Date$ + */ +public class CompositeBuilderImpl implements CompositeBuilder { + + private AssemblyFactory assemblyFactory; + private SCABindingFactory scaBindingFactory; + private InterfaceContractMapper interfaceContractMapper; + private CompositeBuilderMonitor monitor; + + /** + * Constructs a new composite util. + * + * @param assemblyFactory + * @param interfaceContractMapper + */ + public CompositeBuilderImpl(AssemblyFactory assemblyFactory, + SCABindingFactory scaBindingFactory, + InterfaceContractMapper interfaceContractMapper, + CompositeBuilderMonitor monitor) { + this.assemblyFactory = assemblyFactory; + this.scaBindingFactory = scaBindingFactory; + this.interfaceContractMapper = interfaceContractMapper; + + if (monitor != null) { + this.monitor = monitor; + } else { + // Create a default monitor that does nothing. + this.monitor = new CompositeBuilderMonitor() { + public void problem(Problem problem) { + } + }; + } + } + + public void build(Composite composite) throws CompositeBuilderException { + + // Collect and fuse includes + fuseIncludes(composite); + + // Expand nested composites + expandComposites(composite); + + // Configure all components + configureComponents(composite); + + // Wire the composite + wireComposite(composite); + + // Activate composite services + activateCompositeServices(composite); + + // Wire composite references + wireCompositeReferences(composite); + } + + /** + * Collect all includes in a graph of includes. + * + * @param composite + * @param includes + */ + private void collectIncludes(Composite composite, List includes) { + for (Composite include : composite.getIncludes()) { + includes.add(include); + collectIncludes(include, includes); + } + } + + /** + * Copy a list of includes into a composite. + * + * @param composite + * @param includes + */ + protected void fuseIncludes(Composite composite) { + + // First collect all includes + List includes = new ArrayList(); + collectIncludes(composite, includes); + + // Then clone them + for (Composite include : includes) { + Composite clone; + try { + clone = (Composite)include.clone(); + } catch (CloneNotSupportedException e) { + throw new RuntimeException(e); + } + composite.getComponents().addAll(clone.getComponents()); + composite.getServices().addAll(clone.getServices()); + composite.getReferences().addAll(clone.getReferences()); + composite.getProperties().addAll(clone.getProperties()); + composite.getWires().addAll(clone.getWires()); + composite.getPolicySets().addAll(clone.getPolicySets()); + composite.getRequiredIntents().addAll(clone.getRequiredIntents()); + } + + // Clear the list of includes + composite.getIncludes().clear(); + } + + /** + * Reconcile component services and services defined on the component type. + * + * @param component + * @param services + * @param componentServices + * @param problems + */ + private void reconcileServices(Component component, + Map services, + Map componentServices) { + + // Connect each component service to the corresponding service + for (ComponentService componentService : component.getServices()) { + Service service = services.get(componentService.getName()); + if (service != null) { + componentService.setService(service); + } else { + warning("Service not found for component service: " + component.getName() + "/" + componentService.getName(), component); + } + } + + // Create a component service for each service + if (component.getImplementation() != null) { + for (Service service : component.getImplementation().getServices()) { + if (!componentServices.containsKey(service.getName())) { + ComponentService componentService = assemblyFactory.createComponentService(); + componentService.setName(service.getName()); + componentService.setService(service); + component.getServices().add(componentService); + } + } + } + + // Reconcile each component service with its service + for (ComponentService componentService : component.getServices()) { + Service service = componentService.getService(); + if (service != null) { + + // Reconcile interface + if (componentService.getInterfaceContract() != null) { + if (!componentService.getInterfaceContract().equals(service.getInterfaceContract())) { + if (!interfaceContractMapper.isCompatible(componentService.getInterfaceContract(), service + .getInterfaceContract())) { + warning("Component service interface incompatible with service interface: " + component.getName() + "/" + componentService.getName(), component); + } + } + } else { + componentService.setInterfaceContract(service.getInterfaceContract()); + } + + // Reconcile bindings + if (componentService.getBindings().isEmpty()) { + componentService.getBindings().addAll(service.getBindings()); + } + } + + } + } + + /** + * Reconcile component references with the references defined on the + * component type. + * + * @param component + * @param references + * @param componentReferences + * @param problems + */ + private void reconcileReferences(Component component, + Map references, + Map componentReferences) { + + // Connect each component reference to the corresponding reference + for (ComponentReference componentReference : component.getReferences()) { + Reference reference = references.get(componentReference.getName()); + if (reference != null) { + componentReference.setReference(reference); + } else { + if (!componentReference.getName().startsWith("$self$.")) { + warning("Reference not found for component reference: " + component.getName() + "/" + componentReference.getName(), component); + } + } + } + + // Create a component reference for each reference + if (component.getImplementation() != null) { + for (Reference reference : component.getImplementation().getReferences()) { + if (!componentReferences.containsKey(reference.getName())) { + ComponentReference componentReference = assemblyFactory.createComponentReference(); + componentReference.setName(reference.getName()); + componentReference.setReference(reference); + component.getReferences().add(componentReference); + } + } + } + + // Reconcile each component reference with its reference + for (ComponentReference componentReference : component.getReferences()) { + Reference reference = componentReference.getReference(); + if (reference != null) { + + // Reconcile multiplicity + if (componentReference.getMultiplicity() != null) { + if (!ReferenceUtil.isValidMultiplicityOverride(reference.getMultiplicity(), componentReference + .getMultiplicity())) { + warning("Component reference multiplicity incompatible with reference multiplicity: " + component.getName() + "/" + componentReference.getName(), component); + } + } else { + componentReference.setMultiplicity(reference.getMultiplicity()); + } + + // Reconcile interface + if (componentReference.getInterfaceContract() != null) { + if (!componentReference.getInterfaceContract().equals(reference.getInterfaceContract())) { + if (!interfaceContractMapper.isCompatible(reference.getInterfaceContract(), componentReference + .getInterfaceContract())) { + warning("Component reference interface incompatible with reference interface: " + component.getName() + "/" + componentReference.getName(), component); + } + } + } else { + componentReference.setInterfaceContract(reference.getInterfaceContract()); + } + + // Reconcile bindings + if (componentReference.getBindings().isEmpty()) { + componentReference.getBindings().addAll(reference.getBindings()); + } + + // Propagate autowire setting from the component + if (component.isAutowire()) { + componentReference.setAutowire(true); + } + + // Reconcile targets + if (componentReference.getTargets().isEmpty()) { + componentReference.getTargets().addAll(reference.getTargets()); + } + } + } + } + + /** + * Reconcile component properties and the properties defined by the + * component type. + * + * @param component + * @param properties + * @param componentProperties + * @param problems + */ + private void reconcileProperties(Component component, + Map properties, + Map componentProperties) { + + // Connect component properties to their properties + for (ComponentProperty componentProperty : component.getProperties()) { + Property property = properties.get(componentProperty.getName()); + if (property != null) { + componentProperty.setProperty(property); + } else { + warning("Property not found for component property: " + component.getName() + "/" + componentProperty.getName(), component); + } + } + + // Create component properties for all properties + if (component.getImplementation() != null) { + for (Property property : component.getImplementation().getProperties()) { + if (!componentProperties.containsKey(property.getName())) { + ComponentProperty componentProperty = assemblyFactory.createComponentProperty(); + componentProperty.setName(property.getName()); + componentProperty.setMany(property.isMany()); + componentProperty.setXSDElement(property.getXSDElement()); + componentProperty.setXSDType(property.getXSDType()); + componentProperty.setProperty(property); + component.getProperties().add(componentProperty); + } + } + } + + // Reconcile component properties and their properties + for (ComponentProperty componentProperty : component.getProperties()) { + Property property = componentProperty.getProperty(); + if (property != null) { + + // Check that a component property does not override the + // mustSupply attribute + if (!property.isMustSupply() && componentProperty.isMustSupply()) { + warning("Component property mustSupply attribute incompatible with property: " + component.getName() + "/" + componentProperty.getName(), component); + } + + // Default to the mustSupply attribute specified on the property + if (!componentProperty.isMustSupply()) + componentProperty.setMustSupply(property.isMustSupply()); + + // Default to the value specified on the property + if (componentProperty.getValue() == null) { + componentProperty.setValue(property.getValue()); + } + + // Check that a value is supplied + if (componentProperty.getValue() == null && property.isMustSupply()) { + warning("No value configured on a mustSupply property: " + component.getName() + "/" + componentProperty.getName(), component); + } + + // Check that a a component property does not override the + // many attribute + if (!property.isMany() && componentProperty.isMany()) { + warning("Component property many attribute incompatible with property: " + component.getName() + "/" + componentProperty.getName(), component); + } + + // Default to the many attribute defined on the property + componentProperty.setMany(property.isMany()); + + // Default to the type and element defined on the property + if (componentProperty.getXSDType() == null) { + componentProperty.setXSDType(property.getXSDType()); + } + if (componentProperty.getXSDElement() == null) { + componentProperty.setXSDElement(property.getXSDElement()); + } + + // Check that a type or element are specified + if (componentProperty.getXSDElement() == null && componentProperty.getXSDType() == null) { + warning("No type specified on component property: " + component.getName() + "/" + componentProperty.getName(), component); + } + } + } + } + + /** + * Configure components in the composite. + * + * @param composite + * @param problems + */ + protected void configureComponents(Composite composite) { + configureComponents(composite, null); + } + + private void indexImplementationPropertiesServicesAndReferences(Component component, + Map services, + Map references, + Map properties) { + // First check that the component has a resolved implementation + Implementation implementation = component.getImplementation(); + if (implementation == null) { + + // A component must have an implementation + warning("No implementation for component: " + component.getName(), component); + + } else if (implementation.isUnresolved()) { + + // The implementation must be fully resolved + warning("Component implementation not found: " + component.getName() + + " : " + + implementation.getURI(), component); + + } else { + + // Index properties, services and references, also check for + // duplicates + for (Property property : implementation.getProperties()) { + if (properties.containsKey(property.getName())) { + warning("Duplicate property name: " + component.getName() + + "/" + + property.getName(), component); + } else { + properties.put(property.getName(), property); + } + } + for (Service service : implementation.getServices()) { + if (services.containsKey(service.getName())) { + warning("Duplicate service name: " + component.getName() + + "/" + + service.getName(), component); + } else { + services.put(service.getName(), service); + } + } + for (Reference reference : implementation.getReferences()) { + if (references.containsKey(reference.getName())) { + warning("Duplicate reference name: " + component.getName() + + "/" + + reference.getName(), component); + } else { + references.put(reference.getName(), reference); + } + } + } + + } + + private void indexComponentPropertiesServicesAndReferences(Component component, + Map componentServices, + Map componentReferences, + Map componentProperties) { + for (ComponentService componentService : component.getServices()) { + if (componentServices.containsKey(componentService.getName())) { + warning("Duplicate component service name: " + component.getName() + + "/" + + componentService.getName(), component); + } else { + componentServices.put(componentService.getName(), componentService); + } + + // Initialize binding names + for (Binding binding : componentService.getBindings()) { + if (binding.getName() == null) { + binding.setName(componentService.getName()); + } + } + } + for (ComponentReference componentReference : component.getReferences()) { + if (componentReferences.containsKey(componentReference.getName())) { + warning("Duplicate component reference name: " + component.getName() + + "/" + + componentReference.getName(), component); + } else { + componentReferences.put(componentReference.getName(), componentReference); + } + + // Initialize binding names + for (Binding binding : componentReference.getBindings()) { + if (binding.getName() == null) { + binding.setName(componentReference.getName()); + } + } + } + for (ComponentProperty componentProperty : component.getProperties()) { + if (componentProperties.containsKey(componentProperty.getName())) { + warning("Duplicate component property name: " + component.getName() + + "/" + + componentProperty.getName(), component); + } else { + componentProperties.put(componentProperty.getName(), componentProperty); + } + } + + } + + /** + * Configure components in the composite. + * + * @param composite + * @param uri + * @param problems + */ + private void configureComponents(Composite composite, String uri) { + + // Process nested composites recursively + for (Component component : composite.getComponents()) { + + // Initialize component URI + String componentURI; + if (uri == null) { + componentURI = component.getName(); + } else { + componentURI = uri + "/" + component.getName(); + } + component.setURI(componentURI); + + Implementation implementation = component.getImplementation(); + if (implementation instanceof Composite) { + + // Process nested composite + configureComponents((Composite)implementation, componentURI); + } + } + + // Set default binding names + for (Service service : composite.getServices()) { + for (Binding binding : service.getBindings()) { + if (binding.getName() == null) { + binding.setName(service.getName()); + } + } + } + for (Reference reference : composite.getReferences()) { + for (Binding binding : reference.getBindings()) { + if (binding.getName() == null) { + binding.setName(reference.getName()); + } + } + } + + // Initialize all component services and references + Map components = new HashMap(); + for (Component component : composite.getComponents()) { + + // Index all components and check for duplicates + if (components.containsKey(component.getName())) { + warning("Duplicate component name: " + composite.getName() + " : " + component.getName(), composite); + } else { + components.put(component.getName(), component); + } + + // Propagate the autowire flag from the composite to components + if (composite.isAutowire()) { + component.setAutowire(true); + } + + if (component.getImplementation() instanceof ComponentPreProcessor) { + ((ComponentPreProcessor)component.getImplementation()).preProcess(component); + } + + Map services = new HashMap(); + Map references = new HashMap(); + Map properties = new HashMap(); + //Index properties, services and references + indexImplementationPropertiesServicesAndReferences(component, services, references, properties); + + Map componentServices = new HashMap(); + Map componentReferences = new HashMap(); + Map componentProperties = new HashMap(); + //Index component services, references and properties + // Also check for duplicates + indexComponentPropertiesServicesAndReferences(component, componentServices, componentReferences, componentProperties); + + // Reconcile component services/references/properties and + // implementation + // services/references and create component + // services/references/properties + // for the services/references declared by the implementation + reconcileServices(component, services, componentServices); + reconcileReferences(component, references, componentReferences); + reconcileProperties(component, properties, componentProperties); + + // Create self references to the component's services + if (!(component.getImplementation() instanceof Composite)) { + createSelfReferences(component); + } + } + } + + /** + * Create SCA bindings for component services and references. + * + * @param composite + * @param componentServices + * @param componentReferences + * @param problems + */ + private void createSCABindings(Composite composite, + Map componentServices, + Map componentReferences) { + + for (Component component : composite.getComponents()) { + int i = 0; + for (ComponentService componentService : component.getServices()) { + String uri = component.getName() + '/' + componentService.getName(); + componentServices.put(uri, componentService); + if (i == 0) { + componentServices.put(component.getName(), componentService); + } + i++; + + // Create and configure an SCA binding for the service + SCABinding scaBinding = componentService.getBinding(SCABinding.class); + if (scaBinding == null) { + scaBinding = scaBindingFactory.createSCABinding(); + scaBinding.setName(componentService.getName()); + componentService.getBindings().add(scaBinding); + } + scaBinding.setURI(uri); + scaBinding.setComponent(component); + } + for (ComponentReference componentReference : component.getReferences()) { + String uri = component.getName() + '/' + componentReference.getName(); + componentReferences.put(uri, componentReference); + + // Create and configure an SCA binding for the reference + SCABinding scaBinding = componentReference.getBinding(SCABinding.class); + if (scaBinding == null) { + scaBinding = scaBindingFactory.createSCABinding(); + scaBinding.setName(componentReference.getName()); + componentReference.getBindings().add(scaBinding); + } + scaBinding.setURI(uri); + scaBinding.setComponent(component); + } + } + + } + + /** + * Connect composite services to the component services that they promote. + * + * @param composite + * @param componentServices + * @param problems + */ + private void connectCompositeServices(Composite composite, + Map componentServices) { + + // Propagate interfaces from inner composite components' services to + // their component services + for (Component component : composite.getComponents()) { + if (component.getImplementation() instanceof Composite) { + for (ComponentService componentService : component.getServices()) { + Service service = componentService.getService(); + if (service != null) { + if (componentService.getInterfaceContract() == null) { + componentService.setInterfaceContract(service.getInterfaceContract()); + } + } + } + } + } + + // Connect composite services to the component services that they + // promote + for (Service service : composite.getServices()) { + + CompositeService compositeService = (CompositeService)service; + ComponentService componentService = compositeService.getPromotedService(); + if (componentService != null && componentService.isUnresolved()) { + ComponentService promotedService = componentServices.get(componentService.getName()); + if (promotedService != null) { + + // Point to the resolved component service + compositeService.setPromotedService(promotedService); + + // Use the interface contract from the component service if + // none is specified on the composite service + if (compositeService.getInterfaceContract() == null) { + compositeService.setInterfaceContract(promotedService.getInterfaceContract()); + } + + } else { + warning("Promoted component service not found: " + componentService.getName(), composite); + } + } + } + + } + + /** + * Resolves promoted references. + * + * @param composite + * @param componentReferences + * @param problems + */ + private void connectCompositeReferences(Composite composite, + Map componentReferences) { + + // Propagate interfaces from inner composite components' references to + // their component references + for (Component component : composite.getComponents()) { + if (component.getImplementation() instanceof Composite) { + for (ComponentReference componentReference : component.getReferences()) { + Reference reference = componentReference.getReference(); + if (reference != null) { + if (componentReference.getInterfaceContract() == null) { + componentReference.setInterfaceContract(reference.getInterfaceContract()); + } + } + } + } + } + + // Connect composite references to the component references + // that they promote + for (Reference reference : composite.getReferences()) { + CompositeReference compositeReference = (CompositeReference)reference; + List promotedReferences = compositeReference.getPromotedReferences(); + for (int i = 0, n = promotedReferences.size(); i < n; i++) { + ComponentReference componentReference = promotedReferences.get(i); + if (componentReference.isUnresolved()) { + String componentReferenceName = componentReference.getName(); + componentReference = componentReferences.get(componentReferenceName); + if (componentReference != null) { + + // Point to the resolved component reference + promotedReferences.set(i, componentReference); + + // Use the interface contract from the component + // reference if none + // is specified on the composite reference + if (compositeReference.getInterfaceContract() == null) { + compositeReference.setInterfaceContract(componentReference.getInterfaceContract()); + } + + } else { + warning("Promoted component reference not found: " + componentReferenceName, composite); + } + } + } + } + } + + /** + * Connect references to their targets. + * + * @param composite + * @param componentServices + * @param componentReferences + * @param problems + */ + private void connectComponentReferences(Composite composite, + Map componentServices, + Map componentReferences) { + + for (ComponentReference componentReference : componentReferences.values()) { + List targets = componentReference.getTargets(); + + if (componentReference.isAutowire()) { + + // Find suitable targets in the current composite for an + // autowired reference + Multiplicity multiplicity = componentReference.getMultiplicity(); + for (Component component : composite.getComponents()) { + for (ComponentService componentService : component.getServices()) { + if (componentReference.getInterfaceContract() == null || interfaceContractMapper + .isCompatible(componentReference.getInterfaceContract(), componentService + .getInterfaceContract())) { + + targets.add(componentService); + if (multiplicity == Multiplicity.ZERO_ONE || multiplicity == Multiplicity.ONE_ONE) { + break; + } + } + } + } + + } else if (!targets.isEmpty()) { + + // Resolve targets specified on the component reference + for (int i = 0, n = targets.size(); i < n; i++) { + ComponentService target = targets.get(i); + if (target.isUnresolved()) { + ComponentService resolved = componentServices.get(target.getName()); + if (resolved != null) { + + // Check that the target component service provides + // a superset of + // the component reference interface + if (componentReference.getInterfaceContract() == null || interfaceContractMapper + .isCompatible(componentReference.getInterfaceContract(), resolved + .getInterfaceContract())) { + + targets.set(i, resolved); + } else { + warning("Incompatible interfaces on component reference and target: " + componentReference.getName() + " : " + target.getName(), composite); + } + } else { + warning("Component reference target not found: " + target.getName(), composite); + } + } + } + } else if (componentReference.getReference() != null) { + + // Resolve targets from the corresponding reference in the + // componentType + for (ComponentService target : componentReference.getReference().getTargets()) { + if (target.isUnresolved()) { + ComponentService resolved = componentServices.get(target.getName()); + if (resolved != null) { + + // Check that the target component service provides + // a superset of + // the component reference interface + if (componentReference.getInterfaceContract() == null || interfaceContractMapper + .isCompatible(componentReference.getInterfaceContract(), resolved + .getInterfaceContract())) { + + targets.add(resolved); + } else { + warning("Incompatible interfaces on component reference and target: " + componentReference.getName() + " : " + target.getName(), composite); + } + } else { + warning("Reference target not found: " + target.getName(), composite); + } + } + } + } + } + } + + /** + * Resolve wires and connect the sources to their targets + * + * @param composite + * @param componentServices + * @param componentReferences + * @param problems + */ + private void connectWires(Composite composite, + Map componentServices, + Map componentReferences) { + + // For each wire, resolve the source reference, the target service, and + // add it to the list of targets of the reference + List wires = composite.getWires(); + for (int i = 0, n = wires.size(); i < n; i++) { + Wire wire = wires.get(i); + + ComponentReference resolvedReference; + ComponentService resolvedService; + + // Resolve the source reference + ComponentReference source = wire.getSource(); + if (source != null && source.isUnresolved()) { + resolvedReference = componentReferences.get(source.getName()); + if (resolvedReference != null) { + wire.setSource(resolvedReference); + } else { + warning("Wire source not found: " + source.getName(), composite); + } + } else { + resolvedReference = wire.getSource(); + } + + // Resolve the target service + ComponentService target = wire.getTarget(); + if (target != null && target.isUnresolved()) { + resolvedService = componentServices.get(target.getName()); + if (resolvedService != null) { + wire.setTarget(target); + } else { + warning("Wire target not found: " + source.getName(), composite); + } + } else { + resolvedService = wire.getTarget(); + } + + // Add the target service to the list of targets of the + // reference + if (resolvedReference != null && resolvedService != null) { + // Check that the target component service provides + // a superset of + // the component reference interface + if (resolvedReference.getInterfaceContract() == null || interfaceContractMapper + .isCompatible(resolvedReference.getInterfaceContract(), resolvedService + .getInterfaceContract())) { + + resolvedReference.getTargets().add(resolvedService); + } else { + warning("Incompatible interfaces on wire source and target: " + source.getName() + " : " + target.getName(), composite); + } + } + } + + // Clear the list of wires + composite.getWires().clear(); + } + + /** + * Follow a service promotion chain down to the inner most (non composite) + * component service. + * + * @param topCompositeService + * @return + */ + private ComponentService getPromotedComponentService(CompositeService compositeService) { + ComponentService componentService = compositeService.getPromotedService(); + if (componentService != null) { + Service service = componentService.getService(); + if (componentService.getName() != null && service instanceof CompositeService) { + + // Continue to follow the service promotion chain + return getPromotedComponentService((CompositeService)service); + + } else { + + // Found a non-composite service + return componentService; + } + } else { + + // No promoted service + return null; + } + } + + /** + * Follow a reference promotion chain down to the inner most (non composite) + * component references. + * + * @param compositeReference + * @return + */ + private List getPromotedComponentReferences(CompositeReference compositeReference) { + List componentReferences = new ArrayList(); + collectPromotedComponentReferences(compositeReference, componentReferences); + return componentReferences; + } + + /** + * Follow a reference promotion chain down to the inner most (non composite) + * component references. + * + * @param compositeReference + * @param componentReferences + * @return + */ + private void collectPromotedComponentReferences(CompositeReference compositeReference, + List componentReferences) { + for (ComponentReference componentReference : compositeReference.getPromotedReferences()) { + Reference reference = componentReference.getReference(); + if (reference instanceof CompositeReference) { + + // Continue to follow the reference promotion chain + collectPromotedComponentReferences((CompositeReference)reference, componentReferences); + + } else if (reference != null) { + + // Found a non-composite reference + componentReferences.add(componentReference); + } + } + } + + /** + * Activate composite services in nested composites. + * + * @param composite + * @param problems + */ + protected void activateCompositeServices(Composite composite) { + + // Process nested composites recursively + for (Component component : composite.getComponents()) { + Implementation implementation = component.getImplementation(); + if (implementation instanceof Composite) { + + // First process nested composites + activateCompositeServices((Composite)implementation); + + // Process the component services declared on components + // in this composite + for (ComponentService componentService : component.getServices()) { + CompositeService compositeService = (CompositeService)componentService.getService(); + if (compositeService != null) { + + // Get the inner most promoted service + ComponentService promotedService = getPromotedComponentService(compositeService); + if (promotedService != null) { + + // Default to use the interface from the promoted service + if (compositeService.getInterfaceContract() == null) { + compositeService.setInterfaceContract(promotedService.getInterfaceContract()); + } + if (componentService.getInterfaceContract() == null) { + componentService.setInterfaceContract(promotedService.getInterfaceContract()); + } + + // Create a new component service to represent this composite + // service on the promoted component + SCABinding scaBinding = promotedService.getBinding(SCABinding.class); + if (scaBinding != null) { + Component promotedComponent = scaBinding.getComponent(); + ComponentService newComponentService = assemblyFactory.createComponentService(); + newComponentService.setName("$promoted$." + compositeService.getName()); + //newComponentService.setService(compositeService); + promotedComponent.getServices().add(newComponentService); + newComponentService.getBindings().add(scaBinding); + newComponentService.getBindings().addAll(compositeService.getBindings()); + newComponentService.setInterfaceContract(compositeService.getInterfaceContract()); + newComponentService.setCallback(compositeService.getCallback()); + + // FIXME: [rfeng] Set the service to promoted + newComponentService.setService(promotedService.getService()); + + // Change the composite service to now promote the newly + // created component service directly + compositeService.setPromotedService(newComponentService); + + } else { + warning("Promoted component service not found: " + promotedService.getName(), composite); + } + } + } + } + } + } + + // Process composite services declared in this composite + for (Service service : composite.getServices()) { + CompositeService compositeService = (CompositeService)service; + + // Get the inner most promoted service + ComponentService promotedService = getPromotedComponentService(compositeService); + if (promotedService != null) { + + // Default to use the interface from the promoted service + if (compositeService.getInterfaceContract() == null && promotedService.getInterfaceContract() != null) { + compositeService.setInterfaceContract(promotedService.getInterfaceContract()); + } + + // Create a new component service to represent this composite + // service on the promoted component + SCABinding scaBinding = promotedService.getBinding(SCABinding.class); + if (scaBinding != null) { + Component promotedComponent = scaBinding.getComponent(); + ComponentService newComponentService = assemblyFactory.createComponentService(); + newComponentService.setName("$promoted$." + compositeService.getName()); + //newComponentService.setService(compositeService); + promotedComponent.getServices().add(newComponentService); + newComponentService.getBindings().add(scaBinding); + newComponentService.getBindings().addAll(compositeService.getBindings()); + newComponentService.setInterfaceContract(compositeService.getInterfaceContract()); + newComponentService.setCallback(compositeService.getCallback()); + + // FIXME: [rfeng] Set the service to promoted + newComponentService.setService(promotedService.getService()); + + // Change the composite service to now promote the newly + // created component service directly + compositeService.setPromotedService(newComponentService); + } else { + warning("Promoted component service not found: " + promotedService.getName(), composite); + } + } + } + } + + /** + * Wire composite references in nested composites. + * + * @param composite + * @param problems + */ + protected void wireCompositeReferences(Composite composite) { + + // Process nested composites recursively + for (Component component : composite.getComponents()) { + Implementation implementation = component.getImplementation(); + if (implementation instanceof Composite) { + wireCompositeReferences((Composite)implementation); + } + } + + // Process composite references declared in this composite + for (Reference reference : composite.getReferences()) { + CompositeReference compositeReference = (CompositeReference)reference; + List promotedReferences = getPromotedComponentReferences(compositeReference); + for (ComponentReference promotedReference : promotedReferences) { + + // Override the configuration of the promoted reference + SCABinding scaBinding = promotedReference.getBinding(SCABinding.class); + promotedReference.getBindings().clear(); + promotedReference.getBindings().add(scaBinding); + promotedReference.getBindings().addAll(compositeReference.getBindings()); + } + } + + // Process the component references declared on components + // in this composite + for (Component component : composite.getComponents()) { + Implementation implementation = component.getImplementation(); + if (implementation instanceof Composite) { + for (ComponentReference componentReference : component.getReferences()) { + CompositeReference compositeReference = (CompositeReference)componentReference.getReference(); + if (compositeReference != null) { + List promotedReferences = getPromotedComponentReferences(compositeReference); + for (ComponentReference promotedReference : promotedReferences) { + + // Override the configuration of the promoted + // reference + SCABinding scaBinding = promotedReference.getBinding(SCABinding.class); + promotedReference.getBindings().clear(); + promotedReference.getBindings().add(scaBinding); + promotedReference.getBindings().addAll(componentReference.getBindings()); + + // Wire the promoted reference to the actual + // non-composite component services + promotedReference.getTargets().clear(); + for (ComponentService target : componentReference.getTargets()) { + if (target.getService() instanceof CompositeService) { + + // Wire to the actual component service + // promoted by a composite service + CompositeService compositeService = (CompositeService)target.getService(); + ComponentService componentService = compositeService.getPromotedService(); + if (componentService != null) { + promotedReference.getTargets().add(componentService); + } + } else { + + // Wire to a non-composite target service + promotedReference.getTargets().add(target); + } + } + } + } + } + } else { + for (ComponentReference componentReference : component.getReferences()) { + + // Wire the component reference to the actual + // non-composite component services + List targets = componentReference.getTargets(); + for (int i = 0, n = targets.size(); i componentServices = new HashMap(); + Map componentReferences = new HashMap(); + + // Create SCA bindings on all component services and references + createSCABindings(composite, componentServices, componentReferences); + + // Connect composite services and references to the component + // services and references that they promote + connectCompositeServices(composite, componentServices); + connectCompositeReferences(composite, componentReferences); + + // Connect component references to their targets + connectComponentReferences(composite, componentServices, componentReferences); + + // Connect component references as described in wires + connectWires(composite, componentServices, componentReferences); + + // Resolve sourced properties + resolveSourcedProperties(composite, null); + + // Validate that references are wired or promoted, according + // to their multiplicity + for (ComponentReference componentReference : componentReferences.values()) { + if (!ReferenceUtil.validateMultiplicityAndTargets(componentReference.getMultiplicity(), componentReference + .getTargets(), componentReference.getBindings())) { + if (componentReference.getTargets().isEmpty()) { + + // No warning if the reference is promoted out of the current composite + boolean promoted = false; + for (Reference reference: composite.getReferences()) { + CompositeReference compositeReference = (CompositeReference)reference; + if (compositeReference.getPromotedReferences().contains(componentReference)) { + promoted = true; + break; + } + } + if (!promoted) { + warning("No targets for reference: " + componentReference.getName(), composite); + } + } else { + warning("Too many targets on reference: " + componentReference.getName(), composite); + } + } + } + } + + private ComponentProperty getComponentPropertyByName(String propertyName, List properties) { + if (properties != null) { + for (ComponentProperty aProperty : properties) { + if (aProperty.getName().equals(propertyName)) { + return aProperty; + } + } + } + return null; + } + + + /** + * @param composite + */ + private void resolveSourcedProperties(Composite composite, List propertySettings) { + // Resolve properties + Map compositeProperties = new HashMap(); + ComponentProperty componentProperty = null; + for (Property p : composite.getProperties()) { + componentProperty = getComponentPropertyByName(p.getName(), propertySettings); + if ( componentProperty != null ) { + compositeProperties.put(p.getName(), componentProperty); + } else { + compositeProperties.put(p.getName(), p); + } + } + + for (Component component : composite.getComponents()) { + try { + PropertyUtil.sourceComponentProperties(compositeProperties, component); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + Implementation impl = component.getImplementation(); + if (impl instanceof Composite) { + resolveSourcedProperties((Composite)impl, component.getProperties()); + } + } + } + + + /** + * Expand composite component implementations. + * + * @param composite + * @param problems + */ + protected void expandComposites(Composite composite) { + for (Component component : composite.getComponents()) { + Implementation implementation = component.getImplementation(); + if (implementation instanceof Composite) { + + Composite compositeImplementation = (Composite)implementation; + Composite clone; + try { + clone = (Composite)compositeImplementation.clone(); + } catch (CloneNotSupportedException e) { + throw new RuntimeException(e); + } + component.setImplementation(clone); + expandComposites(clone); + } + } + } + + /** + * For all the services, create a corresponding self-reference. + * + * @param component + */ + private void createSelfReferences(Component component) { + for (ComponentService service : component.getServices()) { + ComponentReference componentReference = assemblyFactory.createComponentReference(); + componentReference.setName("$self$." + service.getName()); + componentReference.getBindings().addAll(service.getBindings()); + ComponentService componentService = assemblyFactory.createComponentService(); + componentService.setName(component.getName() + "/" + service.getName()); + componentService.setUnresolved(true); + componentReference.getTargets().add(componentService); + componentReference.getPolicySets().addAll(service.getPolicySets()); + componentReference.getRequiredIntents().addAll(service.getRequiredIntents()); + componentReference.setInterfaceContract(service.getInterfaceContract()); + componentReference.setMultiplicity(Multiplicity.ONE_ONE); + component.getReferences().add(componentReference); + } + } + + /** + * Report an error. + * + * @param problems + * @param message + * @param model + */ + @SuppressWarnings("unused") + private void error(String message, Object model) { + monitor.problem(new ProblemImpl(Severity.ERROR, message, model)); + } + + /** + * Report a warning. + * + * @param problems + * @param message + * @param model + */ + private void warning(String message, Object model) { + monitor.problem(new ProblemImpl(Severity.WARNING, message, model)); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ProblemImpl.java b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ProblemImpl.java new file mode 100644 index 0000000000..2b85cec9fa --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ProblemImpl.java @@ -0,0 +1,98 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.assembly.builder.impl; + +import org.apache.tuscany.sca.assembly.builder.Problem; + + +/** + * Reports a composite assembly problem. + * + * @version $Rev$ $Date$ + */ +public class ProblemImpl implements Problem { + + private String message; + private Severity severity; + private Object model; + private Object resource; + private Exception cause; + + /** + * Constructs a new problem. + * + * @param severity + * @param message + * @param model + */ + public ProblemImpl(Severity severity, String message, Object model) { + this.severity = severity; + this.message = message; + this.model = model; + } + + /** + * Constructs a new problem. + * + * @param severity + * @param message + * @param model + * @param resource + */ + public ProblemImpl(Severity severity, String message, Object model, Object resource) { + this.severity = severity; + this.message = message; + this.model = model; + this.resource = resource; + } + + /** + * Constructs a new problem. + * + * @param severity + * @param message + * @param cause + */ + public ProblemImpl(Severity severity, String message, Exception cause) { + this.severity = severity; + this.message = message; + this.cause = cause; + } + + public Severity getSeverity() { + return severity; + } + + public String getMessage() { + return message; + } + + public Object getModel() { + return model; + } + + public Object getResource() { + return resource; + } + + public Exception getCause() { + return cause; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/PropertyUtil.java b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/PropertyUtil.java new file mode 100644 index 0000000000..71be058795 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/PropertyUtil.java @@ -0,0 +1,189 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.assembly.builder.impl; + +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URL; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import javax.xml.namespace.NamespaceContext; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.Source; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMResult; +import javax.xml.transform.sax.SAXSource; +import javax.xml.xpath.XPath; +import javax.xml.xpath.XPathConstants; +import javax.xml.xpath.XPathExpression; +import javax.xml.xpath.XPathExpressionException; +import javax.xml.xpath.XPathFactory; + +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.ComponentProperty; +import org.apache.tuscany.sca.assembly.Property; +import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException; +import org.w3c.dom.Document; +import org.w3c.dom.Node; +import org.xml.sax.InputSource; + +/** + * Utility class to deal with processing of component properties that are taking values from the parent + * composite's properties or an external file. + */ +public class PropertyUtil { + private static final XPathFactory XPATH_FACTORY = XPathFactory.newInstance(); + private static final DocumentBuilderFactory DOC_BUILDER_FACTORY = DocumentBuilderFactory.newInstance(); + private static final TransformerFactory TRANSFORMER_FACTORY = TransformerFactory.newInstance(); + + static private Document evaluate(NamespaceContext nsContext, Node node, String xPathExpression) + throws XPathExpressionException, ParserConfigurationException { + XPath path = XPATH_FACTORY.newXPath(); + + if (nsContext != null) { + path.setNamespaceContext(nsContext); + } else { + path.setNamespaceContext(new DOMNamespaceContext(node)); + } + + XPathExpression expression = path.compile(xPathExpression); + Node result = (Node)expression.evaluate(node, XPathConstants.NODE); + if (result == null) { + return null; + } + + // TODO: How to wrap the result into a Document? + Document document = DOC_BUILDER_FACTORY.newDocumentBuilder().newDocument(); + if (result instanceof Document) { + return (Document)result; + } else { + //Element root = document.createElementNS(null, "value"); + //document.appendChild(root); + document.appendChild(document.importNode(result, true)); + return document; + } + } + + static private Document loadFromFile(String file) throws MalformedURLException, IOException, + TransformerException, ParserConfigurationException { + URI uri = URI.create(file); + URL url = null; + if (!uri.isAbsolute()) { + url = Thread.currentThread().getContextClassLoader().getResource(file); + } else { + url = uri.toURL(); + } + InputStream is = url.openStream(); + + Source streamSource = new SAXSource(new InputSource(is)); + DOMResult result = new DOMResult(); + javax.xml.transform.Transformer transformer = TRANSFORMER_FACTORY.newTransformer(); + transformer.transform(streamSource, result); + is.close(); + + return (Document)result.getNode(); + } + + static void sourceComponentProperties(Map compositeProperties, + Component componentDefinition) throws CompositeBuilderException, + ParserConfigurationException, + XPathExpressionException, + TransformerException, + IOException { + + List componentProperties = componentDefinition.getProperties(); + for (ComponentProperty aProperty : componentProperties) { + String source = aProperty.getSource(); + String file = aProperty.getFile(); + if (source != null) { + // $/... + int index = source.indexOf('/'); + if (index == -1) { + // Tolerating $prop + source = source + "/"; + index = source.length() - 1; + } + if (source.charAt(0) == '$') { + String name = source.substring(1, index); + Property compositeProp = compositeProperties.get(name); + if (compositeProp == null) { + throw new CompositeBuilderException("The 'source' cannot be resolved to a composite property: " + source); + } + + Document compositePropDefValues = (Document)compositeProp.getValue(); + + // Adding /value because the document root is "value" + String path = source.substring(index); + String xpath = null; + + if ("/".equals(path)) { + // trailing / is not legal for xpath + xpath = "/value"; + } else { + xpath = "/value" + path; + } + + // FIXME: How to deal with namespaces? + Document node = evaluate(null, compositePropDefValues, xpath); + + if (node != null) { + aProperty.setValue(node); + } + } else { + throw new CompositeBuilderException("The 'source' has an invalid value: " + source); + } + } else if (file != null) { + aProperty.setValue(loadFromFile(aProperty.getFile())); + + } + } + } + + private static class DOMNamespaceContext implements NamespaceContext { + private Node node; + + /** + * @param node + */ + public DOMNamespaceContext(Node node) { + super(); + this.node = node; + } + + public String getNamespaceURI(String prefix) { + return node.lookupNamespaceURI(prefix); + } + + public String getPrefix(String namespaceURI) { + return node.lookupPrefix(namespaceURI); + } + + public Iterator getPrefixes(String namespaceURI) { + return null; + } + + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ReferenceUtil.java b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ReferenceUtil.java new file mode 100644 index 0000000000..9802e9ba63 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ReferenceUtil.java @@ -0,0 +1,94 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.assembly.builder.impl; + +import java.util.List; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.Multiplicity; +import org.apache.tuscany.sca.assembly.SCABinding; + +/** + * This class encapsulates utility methods to deal with reference definitions + * + */ +class ReferenceUtil { + static boolean isValidMultiplicityOverride(Multiplicity definedMul, Multiplicity overridenMul) { + if (definedMul != overridenMul) { + switch (definedMul) { + case ZERO_N: + return overridenMul == Multiplicity.ZERO_ONE; + case ONE_N: + return overridenMul == Multiplicity.ONE_ONE; + default: + return false; + } + } else { + return true; + } + } + + static boolean validateMultiplicityAndTargets(Multiplicity multiplicity, + List targets, List bindings) { + + // Count targets + int count = targets.size(); + + //FIXME workaround, this validation is sometimes invoked too early + // before we get a chance to init the multiplicity attribute + if (multiplicity == null) { + return true; + } + + switch (multiplicity) { + case ZERO_N: + break; + case ZERO_ONE: + if (count > 1) { + return false; + } + break; + case ONE_ONE: + if (count != 1) { + if (count == 0) { + for (Binding binding: bindings) { + if (!(binding instanceof SCABinding)) { + return true; + } + } + } + return false; + } + break; + case ONE_N: + if (count < 1) { + if (count == 0) { + for (Binding binding: bindings) { + if (!(binding instanceof SCABinding)) { + return true; + } + } + } + return false; + } + break; + } + return true; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/AbstractPropertyImpl.java b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/AbstractPropertyImpl.java new file mode 100644 index 0000000000..989aea1237 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/AbstractPropertyImpl.java @@ -0,0 +1,102 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.assembly.impl; + +import java.util.ArrayList; +import java.util.List; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.AbstractProperty; +import org.apache.tuscany.sca.policy.Intent; + +/** + * Represents an abstract property. + * + * @version $Rev$ $Date$ + */ +public class AbstractPropertyImpl extends BaseImpl implements AbstractProperty { + private Object value; + private String name; + private QName xsdType; + private QName xsdElement; + private boolean many; + private boolean mustSupply; + private List requiredIntents = new ArrayList(); + + /** + * Constructs a new abstract property. + */ + protected AbstractPropertyImpl() { + } + + public Object getValue() { + return value; + } + + public String getName() { + return name; + } + + public QName getXSDElement() { + return xsdElement; + } + + public QName getXSDType() { + return xsdType; + } + + public boolean isMany() { + return many; + } + + public boolean isMustSupply() { + return mustSupply; + } + + public void setValue(Object defaultValue) { + this.value = defaultValue; + } + + public void setMany(boolean many) { + this.many = many; + } + + public void setMustSupply(boolean mustSupply) { + this.mustSupply = mustSupply; + } + + public void setName(String name) { + this.name = name; + } + + public void setXSDElement(QName element) { + this.xsdElement = element; + } + + public void setXSDType(QName type) { + this.xsdType = type; + } + + public List getRequiredIntents() { + return requiredIntents; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/AbstractReferenceImpl.java b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/AbstractReferenceImpl.java new file mode 100644 index 0000000000..d0ee3832c5 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/AbstractReferenceImpl.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.assembly.impl; + +import org.apache.tuscany.sca.assembly.AbstractReference; +import org.apache.tuscany.sca.assembly.Multiplicity; + +/** + * Represents an abstract reference + * + * @version $Rev$ $Date$ + */ +public class AbstractReferenceImpl extends ContractImpl implements AbstractReference { + private Multiplicity multiplicity = Multiplicity.ONE_ONE; + + /** + * Constructs a new abstract reference. + */ + protected AbstractReferenceImpl() { + } + + public Multiplicity getMultiplicity() { + return multiplicity; + } + + public void setMultiplicity(Multiplicity multiplicity) { + this.multiplicity = multiplicity; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/AbstractServiceImpl.java b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/AbstractServiceImpl.java new file mode 100644 index 0000000000..346764b1b4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/AbstractServiceImpl.java @@ -0,0 +1,36 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.assembly.impl; + +import org.apache.tuscany.sca.assembly.AbstractService; + +/** + * Represents an abstract service + * + * @version $Rev$ $Date$ + */ +public class AbstractServiceImpl extends ContractImpl implements AbstractService { + + /** + * Constructs a new abstract service. + */ + protected AbstractServiceImpl() { + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/AssemblyFactoryImpl.java b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/AssemblyFactoryImpl.java new file mode 100644 index 0000000000..1e623d35f2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/AssemblyFactoryImpl.java @@ -0,0 +1,121 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.assembly.impl; + +import org.apache.tuscany.sca.assembly.AbstractProperty; +import org.apache.tuscany.sca.assembly.AbstractReference; +import org.apache.tuscany.sca.assembly.AbstractService; +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.Callback; +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.ComponentProperty; +import org.apache.tuscany.sca.assembly.ComponentReference; +import org.apache.tuscany.sca.assembly.ComponentService; +import org.apache.tuscany.sca.assembly.ComponentType; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.CompositeReference; +import org.apache.tuscany.sca.assembly.CompositeService; +import org.apache.tuscany.sca.assembly.ConstrainingType; +import org.apache.tuscany.sca.assembly.Property; +import org.apache.tuscany.sca.assembly.Reference; +import org.apache.tuscany.sca.assembly.Service; +import org.apache.tuscany.sca.assembly.Wire; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.impl.OperationImpl; + +/** + * A factory for the assembly model. + * + * @version $Rev$ $Date$ + */ +public abstract class AssemblyFactoryImpl implements AssemblyFactory { + + public AbstractProperty createAbstractProperty() { + return new AbstractPropertyImpl(); + } + + public AbstractReference createAbstractReference() { + return new AbstractReferenceImpl(); + } + + public AbstractService createAbstractService() { + return new AbstractServiceImpl(); + } + + public Callback createCallback() { + return new CallbackImpl(); + } + + public Component createComponent() { + return new ComponentImpl(); + } + + public ComponentProperty createComponentProperty() { + return new ComponentPropertyImpl(); + } + + public ComponentReference createComponentReference() { + return new ComponentReferenceImpl(); + } + + public ComponentService createComponentService() { + return new ComponentServiceImpl(); + } + + public ComponentType createComponentType() { + return new ComponentTypeImpl(); + } + + public Composite createComposite() { + return new CompositeImpl(); + } + + public CompositeReference createCompositeReference() { + return new CompositeReferenceImpl(); + } + + public CompositeService createCompositeService() { + return new CompositeServiceImpl(); + } + + public ConstrainingType createConstrainingType() { + return new ConstrainingTypeImpl(); + } + + public Property createProperty() { + return new PropertyImpl(); + } + + public Reference createReference() { + return new ReferenceImpl(); + } + + public Service createService() { + return new ServiceImpl(); + } + + public Wire createWire() { + return new WireImpl(); + } + + public Operation createOperation() { + return new OperationImpl(); + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/BaseImpl.java b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/BaseImpl.java new file mode 100644 index 0000000000..40c07d2e4f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/BaseImpl.java @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.assembly.impl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.sca.assembly.Base; +import org.apache.tuscany.sca.assembly.Visitable; +import org.apache.tuscany.sca.assembly.Visitor; + +/** + * Convenience base class for assembly model objects. + * + * @version $Rev$ $Date$ + */ +public abstract class BaseImpl implements Base, Visitable { + private List extensions = new ArrayList(); + private boolean unresolved; + + /** + * Constructs a new base model object. + */ + protected BaseImpl() { + } + + public List getExtensions() { + return extensions; + } + + public boolean isUnresolved() { + return unresolved; + } + + public void setUnresolved(boolean undefined) { + this.unresolved = undefined; + } + + public boolean accept(Visitor visitor) { + return visitor.visit(this); + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/CallbackImpl.java b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/CallbackImpl.java new file mode 100644 index 0000000000..87ef907a80 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/CallbackImpl.java @@ -0,0 +1,62 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.assembly.impl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.Callback; +import org.apache.tuscany.sca.assembly.Visitor; +import org.apache.tuscany.sca.policy.Intent; +import org.apache.tuscany.sca.policy.PolicySet; + +/** + * Represents a reference. + * + * @version $Rev$ $Date$ + */ +public class CallbackImpl extends BaseImpl implements Callback { + private List bindings = new ArrayList(); + private List policySets = new ArrayList(); + private List requiredIntents = new ArrayList(); + + protected CallbackImpl() { + } + + public List getBindings() { + return bindings; + } + + public List getPolicySets() { + return policySets; + } + + public List getRequiredIntents() { + return requiredIntents; + } + + public boolean accept(Visitor visitor) { + if (!super.accept(visitor)) { + return false; + } + return true; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentImpl.java b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentImpl.java new file mode 100644 index 0000000000..ec837c060c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentImpl.java @@ -0,0 +1,157 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.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.assembly.Visitor; +import org.apache.tuscany.sca.policy.Intent; +import org.apache.tuscany.sca.policy.PolicySet; + +/** + * Represents a component. + * + * @version $Rev$ $Date$ + */ +public class ComponentImpl extends BaseImpl implements Component, Cloneable { + private ConstrainingType constrainingType; + private Implementation implementation; + private String name; + private String uri; + private List properties = new ArrayList(); + private List references = new ArrayList(); + private List services = new ArrayList(); + private List requiredIntents = new ArrayList(); + private List policySets = new ArrayList(); + private boolean autowire; + + /** + * Constructs a new component. + */ + protected ComponentImpl() { + } + + @Override + public Object clone() throws CloneNotSupportedException { + ComponentImpl clone = (ComponentImpl)super.clone(); + + clone.properties = new ArrayList(); + for (ComponentProperty property: getProperties()) { + clone.properties.add((ComponentProperty)property.clone()); + } + clone.references = new ArrayList(); + for (ComponentReference reference: getReferences()) { + clone.references.add((ComponentReference)reference.clone()); + } + clone.services = new ArrayList(); + for (ComponentService service: getServices()) { + clone.services.add((ComponentService)service.clone()); + } + return clone; + } + + public String getURI() { + return uri; + } + + public void setURI(String uri) { + this.uri = uri; + } + + public ConstrainingType getConstrainingType() { + return constrainingType; + } + + public Implementation getImplementation() { + return implementation; + } + + public String getName() { + return name; + } + + public List getProperties() { + return properties; + } + + public List getReferences() { + return references; + } + + public List getServices() { + return services; + } + + public void setConstrainingType(ConstrainingType constrainingType) { + this.constrainingType = constrainingType; + } + + public void setImplementation(Implementation implementation) { + this.implementation = implementation; + } + + public void setName(String name) { + this.name = name; + } + + public List getRequiredIntents() { + return requiredIntents; + } + + public List getPolicySets() { + return policySets; + } + + public boolean isAutowire() { + return autowire; + } + + public void setAutowire(boolean autowire) { + this.autowire = autowire; + } + + public boolean accept(Visitor visitor) { + if (!super.accept(visitor)) { + return false; + } + for (ComponentProperty property : properties) { + if (!visitor.visit(property)) { + return false; + } + } + for (ComponentReference reference : references) { + if (!visitor.visit(reference)) { + return false; + } + } + for (ComponentService service : services) { + if (!visitor.visit(service)) { + return false; + } + } + return true; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentPropertyImpl.java b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentPropertyImpl.java new file mode 100644 index 0000000000..8a9b8e446d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentPropertyImpl.java @@ -0,0 +1,78 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.assembly.impl; + +import org.apache.tuscany.sca.assembly.ComponentProperty; +import org.apache.tuscany.sca.assembly.Property; + +/** + * Represents a component property. + * + * @version $Rev$ $Date$ + */ +public class ComponentPropertyImpl extends PropertyImpl implements ComponentProperty, Cloneable { + private String file; + private Property property; + private String source; + + /** + * Constructs a new component property. + */ + protected ComponentPropertyImpl() { + } + + @Override + public Object clone() throws CloneNotSupportedException { + return super.clone(); + } + + public Object getValue() { + if (super.getValue() == null && property != null) { + return property.getValue(); + } else { + return super.getValue(); + } + } + + public String getFile() { + return file; + } + + public Property getProperty() { + return property; + } + + public String getSource() { + return source; + } + + public void setFile(String file) { + this.file = file; + } + + public void setProperty(Property property) { + this.property = property; + } + + public void setSource(String source) { + this.source = source; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentReferenceImpl.java b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentReferenceImpl.java new file mode 100644 index 0000000000..bd593f7502 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentReferenceImpl.java @@ -0,0 +1,72 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.assembly.impl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.sca.assembly.ComponentReference; +import org.apache.tuscany.sca.assembly.CompositeReference; +import org.apache.tuscany.sca.assembly.Reference; + +/** + * Represents a component reference + * + * @version $Rev$ $Date$ + */ +public class ComponentReferenceImpl extends ReferenceImpl implements ComponentReference, Cloneable { + private Reference reference; + private boolean autowire; + private List promotedAs = new ArrayList(); + + /** + * Constructs a new component reference. + */ + protected ComponentReferenceImpl() { + // Set multiplicity to null so that by default it'll inherit from the Reference + setMultiplicity(null); + } + + @Override + public Object clone() throws CloneNotSupportedException { + return super.clone(); + } + + public Reference getReference() { + return reference; + } + + public void setReference(Reference reference) { + this.reference = reference; + } + + public boolean isAutowire() { + return autowire; + } + + public void setAutowire(boolean autowire) { + this.autowire = autowire; + } + + public List promotedAs() { + return promotedAs; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentServiceImpl.java b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentServiceImpl.java new file mode 100644 index 0000000000..66883133d7 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentServiceImpl.java @@ -0,0 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.assembly.impl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.sca.assembly.ComponentService; +import org.apache.tuscany.sca.assembly.CompositeService; +import org.apache.tuscany.sca.assembly.Service; + +/** + * Represents a component service + * + * @version $Rev$ $Date$ + */ +public class ComponentServiceImpl extends ServiceImpl implements ComponentService, Cloneable { + private Service service; + private List promotedAs = new ArrayList(); + + /** + * Constructs a new component service. + */ + protected ComponentServiceImpl() { + } + + @Override + public Object clone() throws CloneNotSupportedException { + return super.clone(); + } + + public Service getService() { + return service; + } + + public void setService(Service service) { + this.service = service; + } + + public List promotedAs() { + return promotedAs; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentTypeImpl.java b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentTypeImpl.java new file mode 100644 index 0000000000..e57f25551a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentTypeImpl.java @@ -0,0 +1,151 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.assembly.impl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.sca.assembly.ComponentType; +import org.apache.tuscany.sca.assembly.ConstrainingType; +import org.apache.tuscany.sca.assembly.Property; +import org.apache.tuscany.sca.assembly.Reference; +import org.apache.tuscany.sca.assembly.Service; +import org.apache.tuscany.sca.assembly.Visitor; +import org.apache.tuscany.sca.policy.Intent; +import org.apache.tuscany.sca.policy.PolicySet; + +/** + * Represents a component type. + * + * @version $Rev$ $Date$ + */ +public class ComponentTypeImpl extends BaseImpl implements ComponentType, Cloneable { + private String uri; + private ConstrainingType constrainingType; + private List properties = new ArrayList(); + private List references = new ArrayList(); + private List services = new ArrayList(); + private List requiredIntents = new ArrayList(); + private List policySets = new ArrayList(); + + /** + * Constructs a new component type. + */ + protected ComponentTypeImpl() { + } + + @Override + public Object clone() throws CloneNotSupportedException { + ComponentTypeImpl clone = (ComponentTypeImpl)super.clone(); + + clone.services = new ArrayList(); + for (Service service: getServices()) { + clone.services.add((Service)service.clone()); + } + clone.references = new ArrayList(); + for (Reference reference: getReferences()) { + clone.references.add((Reference)reference.clone()); + } + clone.properties = new ArrayList(); + for (Property property: getProperties()) { + clone.properties.add((Property)property.clone()); + } + return clone; + } + + public String getURI() { + return uri; + } + + public void setURI(String uri) { + this.uri = uri; + } + + public ConstrainingType getConstrainingType() { + return constrainingType; + } + + public List getProperties() { + return properties; + } + + public List getReferences() { + return references; + } + + public List getServices() { + return services; + } + + public void setConstrainingType(ConstrainingType constrainingType) { + this.constrainingType = constrainingType; + } + + public List getRequiredIntents() { + return requiredIntents; + } + + public List getPolicySets() { + return policySets; + } + + public boolean accept(Visitor visitor) { + if (!super.accept(visitor)) { + return false; + } + for (Property property : properties) { + if (!visitor.visit(property)) { + return false; + } + } + for (Reference reference : references) { + if (!visitor.visit(reference)) { + return false; + } + } + for (Service service : services) { + if (!visitor.visit(service)) { + return false; + } + } + return true; + } + + @Override + public int hashCode() { + return String.valueOf(getURI()).hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (obj == this) { + return true; + } else { + if (obj instanceof ComponentType) { + if (getURI() != null) { + return getURI().equals(((ComponentType)obj).getURI()); + } else { + return ((ComponentType)obj).getURI() == null; + } + } else { + return false; + } + } + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/CompositeImpl.java b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/CompositeImpl.java new file mode 100644 index 0000000000..5c40f9445b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/CompositeImpl.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.assembly.impl; + +import java.util.ArrayList; +import java.util.List; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.Visitor; +import org.apache.tuscany.sca.assembly.Wire; + +public class CompositeImpl extends ComponentTypeImpl implements Composite, Cloneable { + private List components = new ArrayList(); + private List includes = new ArrayList(); + private QName name; + private List wires = new ArrayList(); + private boolean autowire; + private boolean local = true; + + /** + * Constructs a new composite. + */ + protected CompositeImpl() { + } + + @Override + public Object clone() throws CloneNotSupportedException { + CompositeImpl clone = (CompositeImpl)super.clone(); + + clone.components = new ArrayList(); + for (Component component: getComponents()) { + clone.components.add((Component)component.clone()); + } + clone.wires = new ArrayList(); + for (Wire wire: getWires()) { + clone.wires.add((Wire)wire.clone()); + } + return clone; + } + + public List getComponents() { + return components; + } + + public List getIncludes() { + return includes; + } + + public QName getName() { + return name; + } + + public List getWires() { + return wires; + } + + public boolean isAutowire() { + return autowire; + } + + public boolean isLocal() { + return local; + } + + public void setAutowire(boolean autowire) { + this.autowire = autowire; + } + + public void setLocal(boolean local) { + this.local = local; + } + + public void setName(QName name) { + this.name = name; + } + + @Override + public boolean accept(Visitor visitor) { + boolean result = super.accept(visitor); + if (!result) { + return false; + } + + for (Component component: components) { + if (!component.accept(visitor)) { + return false; + } + } + + for (Wire wire: wires) { + if (!visitor.visit(wire)) + return false; + } + return true; + } + + @Override + public int hashCode() { + return String.valueOf(getName()).hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (obj == this) { + return true; + } else if (obj instanceof Composite) { + if (getName() != null) { + return getName().equals(((Composite)obj).getName()); + } else { + return ((Composite)obj).getName() == null; + } + } else { + return false; + } + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/CompositeReferenceImpl.java b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/CompositeReferenceImpl.java new file mode 100644 index 0000000000..4348e08fcb --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/CompositeReferenceImpl.java @@ -0,0 +1,51 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.assembly.impl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.sca.assembly.ComponentReference; +import org.apache.tuscany.sca.assembly.CompositeReference; + +/** + * Represents a composite reference. + * + * @version $Rev$ $Date$ + */ +public class CompositeReferenceImpl extends ReferenceImpl implements CompositeReference, Cloneable { + private List promotedReferences = new ArrayList(); + + /** + * Constructs a new composite reference. + */ + protected CompositeReferenceImpl() { + } + + @Override + public Object clone() throws CloneNotSupportedException { + return super.clone(); + } + + public List getPromotedReferences() { + return promotedReferences; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/CompositeServiceImpl.java b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/CompositeServiceImpl.java new file mode 100644 index 0000000000..19a6ed56c2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/CompositeServiceImpl.java @@ -0,0 +1,51 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.assembly.impl; + +import org.apache.tuscany.sca.assembly.ComponentService; +import org.apache.tuscany.sca.assembly.CompositeService; + +/** + * Represents a composite service + * + * @version $Rev$ $Date$ + */ +public class CompositeServiceImpl extends ServiceImpl implements CompositeService, Cloneable { + private ComponentService promotedService; + + /** + * Constructs a new composite service. + */ + protected CompositeServiceImpl() { + } + + @Override + public Object clone() throws CloneNotSupportedException { + return super.clone(); + } + + public ComponentService getPromotedService() { + return promotedService; + } + + public void setPromotedService(ComponentService promotedService) { + this.promotedService = promotedService; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ConstrainingTypeImpl.java b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ConstrainingTypeImpl.java new file mode 100644 index 0000000000..f9fbae6659 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ConstrainingTypeImpl.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.assembly.impl; + +import java.util.ArrayList; +import java.util.List; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.AbstractProperty; +import org.apache.tuscany.sca.assembly.AbstractReference; +import org.apache.tuscany.sca.assembly.AbstractService; +import org.apache.tuscany.sca.assembly.ConstrainingType; +import org.apache.tuscany.sca.assembly.Visitor; +import org.apache.tuscany.sca.policy.Intent; + +/** + * Represents a constraining type. + * + * @version $Rev$ $Date$ + */ +public class ConstrainingTypeImpl extends BaseImpl implements ConstrainingType { + private QName name; + private List properties = new ArrayList(); + private List references = new ArrayList(); + private List services = new ArrayList(); + private List requiredIntents = new ArrayList(); + + /** + * Constructs a new ConstrainingType + */ + protected ConstrainingTypeImpl() { + } + + public QName getName() { + return name; + } + + public void setName(QName name) { + this.name = name; + } + + public List getProperties() { + return properties; + } + + public List getReferences() { + return references; + } + + public List getServices() { + return services; + } + + public List getRequiredIntents() { + return requiredIntents; + } + + public boolean accept(Visitor visitor) { + if (!super.accept(visitor)) { + return false; + } + for (AbstractProperty property : properties) { + if (!visitor.visit(property)) { + return false; + } + } + for (AbstractReference reference : references) { + if (!visitor.visit(reference)) { + return false; + } + } + for (AbstractService service : services) { + if (!visitor.visit(service)) { + return false; + } + } + return true; + } + + @Override + public int hashCode() { + return String.valueOf(getName()).hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (obj == this) { + return true; + } else if (obj instanceof ConstrainingType) { + if (getName() != null) { + return getName().equals(((ConstrainingType)obj).getName()); + } else { + return ((ConstrainingType)obj).getName() == null; + } + } else { + return false; + } + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ContractImpl.java b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ContractImpl.java new file mode 100644 index 0000000000..d295384305 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ContractImpl.java @@ -0,0 +1,59 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.assembly.impl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.sca.assembly.AbstractContract; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.policy.Intent; + +public class ContractImpl extends BaseImpl implements AbstractContract { + private InterfaceContract interfaceContract; + private String name; + private List requiredIntents = new ArrayList(); + + /** + * Constructs a new contract. + */ + protected ContractImpl() { + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public InterfaceContract getInterfaceContract() { + return interfaceContract; + } + + public void setInterfaceContract(InterfaceContract interfaceContract) { + this.interfaceContract = interfaceContract; + } + + public List getRequiredIntents() { + return requiredIntents; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/PropertyImpl.java b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/PropertyImpl.java new file mode 100644 index 0000000000..ebdcdf580b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/PropertyImpl.java @@ -0,0 +1,51 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.assembly.impl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.sca.assembly.Property; +import org.apache.tuscany.sca.policy.PolicySet; + +/** + * Represents a property. + * + * @version $Rev$ $Date$ + */ +public class PropertyImpl extends AbstractPropertyImpl implements Property, Cloneable { + private List policySets = new ArrayList(); + + /** + * Constructs a new property. + */ + protected PropertyImpl() { + } + + @Override + public Object clone() throws CloneNotSupportedException { + return super.clone(); + } + + public List getPolicySets() { + return policySets; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ReferenceImpl.java b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ReferenceImpl.java new file mode 100644 index 0000000000..5ceb5bb950 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ReferenceImpl.java @@ -0,0 +1,95 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.assembly.impl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.Callback; +import org.apache.tuscany.sca.assembly.ComponentService; +import org.apache.tuscany.sca.assembly.Reference; +import org.apache.tuscany.sca.policy.PolicySet; + +/** + * Represents a reference. + * + * @version $Rev$ $Date$ + */ +public class ReferenceImpl extends AbstractReferenceImpl implements Reference, Cloneable { + private List bindings = new ArrayList(); + private boolean wiredByImpl; + private List policySets = new ArrayList(); + private List targets = new ArrayList(); + private Callback callback; + + /** + * Constructs a new reference. + */ + protected ReferenceImpl() { + } + + @Override + public Object clone() throws CloneNotSupportedException { + ReferenceImpl clone = (ReferenceImpl)super.clone(); + clone.bindings = new ArrayList(); + clone.bindings.addAll(getBindings()); + clone.targets = new ArrayList(); + clone.targets.addAll(getTargets()); + return clone; + } + + public List getBindings() { + return bindings; + } + + public B getBinding(Class bindingClass) { + for (Binding binding : bindings) { + if (bindingClass.isInstance(binding)) { + return bindingClass.cast(binding); + } + } + return null; + } + + public boolean isWiredByImpl() { + return wiredByImpl; + } + + public void setWiredByImpl(boolean wiredByImpl) { + this.wiredByImpl = wiredByImpl; + } + + public List getPolicySets() { + return policySets; + } + + public List getTargets() { + return targets; + } + + public Callback getCallback() { + return callback; + } + + public void setCallback(Callback callback) { + this.callback = callback; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/SCABindingFactoryImpl.java b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/SCABindingFactoryImpl.java new file mode 100644 index 0000000000..402b90706d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/SCABindingFactoryImpl.java @@ -0,0 +1,36 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.assembly.impl; + +import org.apache.tuscany.sca.assembly.SCABinding; +import org.apache.tuscany.sca.assembly.SCABindingFactory; + +/** + * A factory for the SCA binding model. + * + * @version $Rev$ $Date$ + */ +public abstract class SCABindingFactoryImpl implements SCABindingFactory { + + public SCABinding createSCABinding() { + return new SCABindingImpl(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/SCABindingImpl.java b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/SCABindingImpl.java new file mode 100644 index 0000000000..93b7d7a88f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/SCABindingImpl.java @@ -0,0 +1,91 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.assembly.impl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.SCABinding; +import org.apache.tuscany.sca.policy.Intent; +import org.apache.tuscany.sca.policy.PolicySet; + +/** + * Represents an SCA binding. + * + * @version $Rev$ $Date$ + */ +public class SCABindingImpl implements SCABinding { + private String name; + private String uri; + private List policySets = new ArrayList(); + private List requiredIntents = new ArrayList(); + private List extensions = new ArrayList(); + + private Component component; + + /** + * Constructs a new SCA binding. + */ + protected SCABindingImpl() { + } + + public Component getComponent() { + return component; + } + + public void setComponent(Component component) { + this.component = component; + } + + public String getName() { + return name; + } + + public String getURI() { + return uri; + } + + public void setName(String name) { + this.name = name; + } + + public void setURI(String uri) { + this.uri = uri; + } + + public List getRequiredIntents() { + return requiredIntents; + } + + public List getPolicySets() { + return policySets; + } + + public List getExtensions() { + return extensions; + } + + public boolean isUnresolved() { + return false; + } + + public void setUnresolved(boolean unresolved) { + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ServiceImpl.java b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ServiceImpl.java new file mode 100644 index 0000000000..c5bf3a10d0 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ServiceImpl.java @@ -0,0 +1,79 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.assembly.impl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.Callback; +import org.apache.tuscany.sca.assembly.Service; +import org.apache.tuscany.sca.policy.PolicySet; + +/** + * Represents a reference. + * + * @version $Rev$ $Date$ + */ +public class ServiceImpl extends AbstractServiceImpl implements Service, Cloneable { + private List bindings = new ArrayList(); + private List policySets = new ArrayList(); + private Callback callback; + + /** + * Constructs a new service. + */ + protected ServiceImpl() { + } + + @Override + public Object clone() throws CloneNotSupportedException { + ServiceImpl clone = (ServiceImpl)super.clone(); + clone.bindings = new ArrayList(); + clone.bindings.addAll(getBindings()); + return clone; + } + + public List getBindings() { + return bindings; + } + + public B getBinding(Class bindingClass) { + for (Binding binding : bindings) { + if (bindingClass.isInstance(binding)) { + return bindingClass.cast(binding); + } + } + return null; + } + + public List getPolicySets() { + return policySets; + } + + public Callback getCallback() { + return callback; + } + + public void setCallback(Callback callback) { + this.callback = callback; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/WireImpl.java b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/WireImpl.java new file mode 100644 index 0000000000..06db488fba --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/WireImpl.java @@ -0,0 +1,76 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.assembly.impl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.sca.assembly.ComponentReference; +import org.apache.tuscany.sca.assembly.ComponentService; +import org.apache.tuscany.sca.assembly.Wire; +import org.apache.tuscany.sca.policy.Intent; +import org.apache.tuscany.sca.policy.PolicySet; + +/** + * Represents a wire + * + * @version $Rev$ $Date$ + */ +public class WireImpl extends BaseImpl implements Wire, Cloneable { + private ComponentReference source; + private ComponentService target; + private List requiredIntents = new ArrayList(); + private List policySets = new ArrayList(); + + /** + * Constructs a new wire. + */ + protected WireImpl() { + } + + @Override + public Object clone() throws CloneNotSupportedException { + return super.clone(); + } + + public ComponentReference getSource() { + return source; + } + + public ComponentService getTarget() { + return target; + } + + public void setSource(ComponentReference source) { + this.source = source; + } + + public void setTarget(ComponentService target) { + this.target = target; + } + + public List getRequiredIntents() { + return requiredIntents; + } + + public List getPolicySets() { + return policySets; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/util/PrintUtil.java b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/util/PrintUtil.java new file mode 100644 index 0000000000..08b39f976b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/util/PrintUtil.java @@ -0,0 +1,172 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.assembly.util; + +import java.beans.BeanInfo; +import java.beans.IntrospectionException; +import java.beans.Introspector; +import java.beans.PropertyDescriptor; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.io.PrintWriter; +import java.lang.reflect.Method; +import java.util.Arrays; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.w3c.dom.Node; + +/** + * A simple print utility class to help print model instances. + * + * @version $Rev$ $Date$ + */ +public class PrintUtil { + + private PrintWriter out; + private int indent; + + public PrintUtil(OutputStream out) { + this.out = new PrintWriter(new OutputStreamWriter(out), true); + } + + void indent() { + for (int i = 0; i < indent; i++) { + out.print(" "); + } + } + + /** + * Print an object. + * + * @param object + */ + public void print(Object object) { + Set objects = new HashSet(); + print(object, objects); + } + + /** + * Print an object. + * + * @param object + */ + private void print(Object object, Set printed) { + if (object == null) { + return; + } + int id = System.identityHashCode(object); + if (printed.contains(id)) { + + // If we've already printed an object, print just it's hashcode + indent(); + out.println(object.getClass().getName() + "@" + id); + } else { + printed.add(id); + try { + + // Print the object class name + indent(); + out.println(object.getClass().getSimpleName() + " {"); + + // Get the object's properties + BeanInfo beanInfo = Introspector.getBeanInfo(object.getClass()); + for (PropertyDescriptor propertyDescriptor : beanInfo.getPropertyDescriptors()) { + try { + + // Get the value of each property + Method getter = propertyDescriptor.getReadMethod(); + if (getter == null) { + continue; + } + Object value = getter.invoke(object); + if (value != null) { + + // Convert array value into a list + if (value.getClass().isArray()) { + value = Arrays.asList((Object[])value); + } + + // Print elements in a list + if (value instanceof List) { + if (!((List)value).isEmpty()) { + indent++; + indent(); + out.println(propertyDescriptor.getName() + "= ["); + + // Print each element, recursively + for (Object element : (List)value) { + indent++; + print(element, printed); + indent--; + } + indent(); + out.println(" ]"); + indent--; + } + } else { + Class valueClass = value.getClass(); + + // Print a primitive, java built in type or + // enum, using toString() + if (valueClass.isPrimitive() || valueClass.getName().startsWith("java.") + || valueClass.getName().startsWith("javax.") + || valueClass.isEnum()) { + if (!propertyDescriptor.getName().equals("class")) { + if (!(Boolean.FALSE.equals(value))) { + indent++; + indent(); + out.println(propertyDescriptor.getName() + "=" + value.toString()); + indent--; + } + } + } else if (value instanceof Node) { + indent++; + indent(); + out.println(propertyDescriptor.getName() + "=" + value.toString()); + indent--; + } else { + + // Print an object, recursively + indent++; + indent(); + out.println(propertyDescriptor.getName() + "= {"); + indent++; + print(value, printed); + indent--; + indent(); + out.println("}"); + indent--; + } + } + } + } catch (Exception e) { + } + } + indent(); + out.println("}"); + } catch (IntrospectionException e) { + indent(); + out.println(e); + } + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/AssemblyFactoryTestCase.java b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/AssemblyFactoryTestCase.java new file mode 100644 index 0000000000..cde42cbc62 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/AssemblyFactoryTestCase.java @@ -0,0 +1,212 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.assembly; + +import javax.xml.namespace.QName; + +import junit.framework.TestCase; + + +/** + * Test building of assembly model instances using the assembly factory. + * + * @version $Rev$ $Date$ + */ +public class AssemblyFactoryTestCase extends TestCase { + + AssemblyFactory factory; + + public void setUp() throws Exception { + factory = new DefaultAssemblyFactory(); + } + + public void tearDown() throws Exception { + factory = null; + } + + public void testCreateComponent() { + createComponent("AccountServiceComponent1"); + } + + public void testCreateComponentType() { + createComponentType(); + } + + public void testCreateComposite() { + createComposite(); + } + + public void testCreateConstrainingType() { + createConstrainingType(); + } + + /** + * Create a composite + */ + Composite createComposite() { + Composite c = factory.createComposite(); + + Component c1 = createComponent("AccountServiceComponent1"); + c.getComponents().add(c1); + Component c2 = createComponent("AccountServiceComponent2"); + c.getComponents().add(c2); + + Wire w = factory.createWire(); + w.setSource(c1.getReferences().get(0)); + w.setTarget(c2.getServices().get(0)); + c.getWires().add(w); + + CompositeService cs = factory.createCompositeService(); + cs.setName("AccountService"); + cs.setPromotedService(c1.getServices().get(0)); + cs.setInterfaceContract(new TestInterfaceContract(factory)); + c.getServices().add(cs); + cs.getBindings().add(new TestBinding(factory)); + + CompositeReference cr = factory.createCompositeReference(); + cr.setName("StockQuoteService"); + cr.getPromotedReferences().add(c2.getReferences().get(1)); + cr.setInterfaceContract(new TestInterfaceContract(factory)); + c.getReferences().add(cr); + cr.getBindings().add(new TestBinding(factory)); + + return c; + } + + /** + * Create a new component + */ + Component createComponent(String name) { + Component c = factory.createComponent(); + c.setName(name); + + ConstrainingType constraint = createConstrainingType(); + c.setConstrainingType(constraint); + + Implementation i = new TestImplementation(factory); + c.setImplementation(i); + + ComponentProperty p = factory.createComponentProperty(); + p.setName("currency"); + p.setValue("USD"); + p.setMustSupply(true); + p.setXSDType(new QName("", "")); + p.setProperty(i.getProperties().get(0)); + c.getProperties().add(p); + + ComponentReference ref1 = factory.createComponentReference(); + ref1.setName("accountDataService"); + ref1.setMultiplicity(Multiplicity.ONE_ONE); + ref1.setInterfaceContract(new TestInterfaceContract(factory)); + ref1.setReference(i.getReferences().get(0)); + c.getReferences().add(ref1); + ref1.getBindings().add(new TestBinding(factory)); + + ComponentReference ref2 = factory.createComponentReference(); + ref2.setName("stockQuoteService"); + ref2.setMultiplicity(Multiplicity.ONE_ONE); + ref2.setInterfaceContract(new TestInterfaceContract(factory)); + ref2.setReference(i.getReferences().get(1)); + c.getReferences().add(ref2); + ref2.getBindings().add(new TestBinding(factory)); + + ComponentService s = factory.createComponentService(); + s.setName("AccountService"); + s.setInterfaceContract(new TestInterfaceContract(factory)); + s.setService(i.getServices().get(0)); + c.getServices().add(s); + s.getBindings().add(new TestBinding(factory)); + + return c; + } + + /** + * Create a new component type + * + * @return + */ + ComponentType createComponentType() { + ComponentType ctype = factory.createComponentType(); + + Property p = factory.createProperty(); + p.setName("currency"); + p.setValue("USD"); + p.setMustSupply(true); + p.setXSDType(new QName("", "")); + ctype.getProperties().add(p); + + Reference ref1 = factory.createReference(); + ref1.setName("accountDataService"); + ref1.setInterfaceContract(new TestInterfaceContract(factory)); + ref1.setMultiplicity(Multiplicity.ONE_ONE); + ctype.getReferences().add(ref1); + ref1.getBindings().add(new TestBinding(factory)); + + Reference ref2 = factory.createReference(); + ref2.setName("stockQuoteService"); + ref2.setInterfaceContract(new TestInterfaceContract(factory)); + ref2.setMultiplicity(Multiplicity.ONE_ONE); + ctype.getReferences().add(ref2); + ref2.getBindings().add(new TestBinding(factory)); + + Service s = factory.createService(); + s.setName("AccountService"); + s.setInterfaceContract(new TestInterfaceContract(factory)); + ctype.getServices().add(s); + s.getBindings().add(new TestBinding(factory)); + + return ctype; + } + + /** + * Create a new constraining type + * + * @return + */ + ConstrainingType createConstrainingType() { + ConstrainingType ctype = factory.createConstrainingType(); + + AbstractProperty p = factory.createAbstractProperty(); + p.setName("currency"); + p.setValue("USD"); + p.setMustSupply(true); + p.setXSDType(new QName("", "")); + ctype.getProperties().add(p); + + AbstractReference ref1 = factory.createAbstractReference(); + ref1.setName("accountDataService"); + ref1.setInterfaceContract(new TestInterfaceContract(factory)); + ref1.setMultiplicity(Multiplicity.ONE_ONE); + ctype.getReferences().add(ref1); + + AbstractReference ref2 = factory.createAbstractReference(); + ref2.setName("stockQuoteService"); + ref2.setInterfaceContract(new TestInterfaceContract(factory)); + ref2.setMultiplicity(Multiplicity.ONE_ONE); + ctype.getReferences().add(ref2); + + AbstractService s = factory.createAbstractService(); + s.setName("AccountService"); + s.setInterfaceContract(new TestInterfaceContract(factory)); + ctype.getServices().add(s); + + return ctype; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestBinding.java b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestBinding.java new file mode 100644 index 0000000000..9b3ac4c2d4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestBinding.java @@ -0,0 +1,69 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.assembly; + +import java.util.List; + +import org.apache.tuscany.sca.policy.Intent; +import org.apache.tuscany.sca.policy.PolicySet; + +/** + * A test interface model. + * + * @version $Rev$ $Date$ + */ +public class TestBinding implements Binding { + + public TestBinding(AssemblyFactory factory) { + setURI("http://test"); + } + + public String getName() { + return null; + } + + public String getURI() { + return "http://test"; + } + + public void setName(String name) { + } + + public void setURI(String uri) { + } + + public List getPolicySets() { + return null; + } + + public List getRequiredIntents() { + return null; + } + + public List getExtensions() { + return null; + } + + public void setUnresolved(boolean unresolved) { + } + + public boolean isUnresolved() { + return false; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestImplementation.java b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestImplementation.java new file mode 100644 index 0000000000..9e34fafb05 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestImplementation.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; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.impl.ComponentTypeImpl; + +/** + * A test component implementation model. + * + * @version $Rev$ $Date$ + */ +public class TestImplementation extends ComponentTypeImpl implements Implementation { + + public TestImplementation(AssemblyFactory factory) { + + Property p = factory.createProperty(); + p.setName("currency"); + p.setValue("USD"); + p.setMustSupply(true); + p.setXSDType(new QName("", "")); + getProperties().add(p); + + Reference ref1 = factory.createReference(); + ref1.setName("accountDataService"); + ref1.setMultiplicity(Multiplicity.ONE_ONE); + getReferences().add(ref1); + ref1.getBindings().add(new TestBinding(factory)); + + Reference ref2 = factory.createReference(); + ref2.setName("stockQuoteService"); + ref2.setMultiplicity(Multiplicity.ONE_ONE); + ref2.setInterfaceContract(new TestInterfaceContract(factory)); + getReferences().add(ref2); + ref2.getBindings().add(new TestBinding(factory)); + + Service s = factory.createService(); + s.setName("AccountService"); + s.setInterfaceContract(new TestInterfaceContract(factory)); + getServices().add(s); + s.getBindings().add(new TestBinding(factory)); + + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestInterface.java b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestInterface.java new file mode 100644 index 0000000000..dbe0cb8225 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestInterface.java @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.assembly; + +import org.apache.tuscany.sca.interfacedef.Interface; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.impl.InterfaceImpl; + +/** + * A test interface model. + * + * @version $Rev$ $Date$ + */ +public class TestInterface extends InterfaceImpl implements Interface { + + public TestInterface(AssemblyFactory factory) { + + setRemotable(true); + + Operation operation = new TestOperation(); + operation.setName("test"); + getOperations().add(operation); + + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestInterfaceContract.java b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestInterfaceContract.java new file mode 100644 index 0000000000..ee6b95edc9 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestInterfaceContract.java @@ -0,0 +1,41 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.assembly; + +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.impl.InterfaceContractImpl; + +/** + * A test interface contract model. + * + * @version $Rev$ $Date$ + */ +public class TestInterfaceContract extends InterfaceContractImpl implements InterfaceContract { + + public TestInterfaceContract(AssemblyFactory factory) { + + TestInterface testInterface = new TestInterface(factory); + setInterface(testInterface); + + TestInterface testCallbackInterface = new TestInterface(factory); + setCallbackInterface(testCallbackInterface); + + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestOperation.java b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestOperation.java new file mode 100644 index 0000000000..460672c1ef --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestOperation.java @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.assembly; + +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.impl.OperationImpl; + +/** + * A test operation model. + * + * @version $Rev$ $Date$ + */ +public class TestOperation extends OperationImpl implements Operation { + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBuilderTestCase.java b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBuilderTestCase.java new file mode 100644 index 0000000000..aeb076a392 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBuilderTestCase.java @@ -0,0 +1,135 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.assembly.builder.impl; + +import javax.xml.namespace.QName; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.CompositeReference; +import org.apache.tuscany.sca.assembly.CompositeService; +import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory; +import org.apache.tuscany.sca.assembly.DefaultSCABindingFactory; +import org.apache.tuscany.sca.assembly.SCABindingFactory; +import org.apache.tuscany.sca.interfacedef.impl.InterfaceContractMapperImpl; + +public class CompositeBuilderTestCase extends TestCase { + + private CompositeBuilderImpl compositeUtil; + private AssemblyFactory assemblyFactory; + private SCABindingFactory scaBindingFactory; + + protected void setUp() throws Exception { + assemblyFactory = new DefaultAssemblyFactory(); + scaBindingFactory = new DefaultSCABindingFactory(); + + compositeUtil = new CompositeBuilderImpl(assemblyFactory, scaBindingFactory, new InterfaceContractMapperImpl(), null); + } + + protected void tearDown() throws Exception { + compositeUtil = null; + assemblyFactory = null; + } + + public void testFuseIncludes() { + Composite c1 = assemblyFactory.createComposite(); + c1.setName(new QName("http://foo", "C1")); + Component a = assemblyFactory.createComponent(); + a.setName("a"); + c1.getComponents().add(a); + CompositeService s = assemblyFactory.createCompositeService(); + s.setName("s"); + c1.getServices().add(s); + CompositeReference r = assemblyFactory.createCompositeReference(); + r.setName("r"); + c1.getReferences().add(r); + + Composite c2 = assemblyFactory.createComposite(); + c2.setName(new QName("http://foo", "C2")); + c1.getIncludes().add(c2); + Component b = assemblyFactory.createComponent(); + b.setName("b"); + c2.getComponents().add(b); + + Composite c = assemblyFactory.createComposite(); + c.setName(new QName("http://foo", "C")); + c.getIncludes().add(c1); + + compositeUtil.fuseIncludes(c); + + assertTrue(c.getComponents().get(0).getName().equals("a")); + assertTrue(c.getComponents().get(1).getName().equals("b")); + assertTrue(c.getServices().get(0).getName().equals("s")); + assertTrue(c.getReferences().get(0).getName().equals("r")); + } + + public void testExpandComposites() { + Composite c1 = assemblyFactory.createComposite(); + c1.setName(new QName("http://foo", "C1")); + Component a = assemblyFactory.createComponent(); + a.setName("a"); + c1.getComponents().add(a); + CompositeService s = assemblyFactory.createCompositeService(); + s.setName("s"); + c1.getServices().add(s); + CompositeReference r = assemblyFactory.createCompositeReference(); + r.setName("r"); + c1.getReferences().add(r); + + Composite c2 = assemblyFactory.createComposite(); + c2.setName(new QName("http://foo", "C2")); + Component b = assemblyFactory.createComponent(); + b.setName("b"); + c2.getComponents().add(b); + + Composite c = assemblyFactory.createComposite(); + c.setName(new QName("http://foo", "C")); + Component x = assemblyFactory.createComponent(); + x.setName("x"); + x.setImplementation(c1); + c.getComponents().add(x); + Component y = assemblyFactory.createComponent(); + y.setName("y"); + y.setImplementation(c2); + c.getComponents().add(y); + Component z = assemblyFactory.createComponent(); + z.setName("z"); + z.setImplementation(c1); + c.getComponents().add(z); + + compositeUtil.expandComposites(c); + + assertTrue(c.getComponents().get(0).getImplementation() != c1); + assertTrue(c.getComponents().get(1).getImplementation() != c2); + assertTrue(c.getComponents().get(2).getImplementation() != c1); + + Composite i = (Composite)c.getComponents().get(0).getImplementation(); + assertTrue(i.getComponents().get(0) != a); + assertTrue(i.getComponents().get(0).getName().equals("a")); + assertTrue(i.getServices().get(0).getName().equals("s")); + assertTrue(i.getServices().get(0) != s); + assertTrue(i.getReferences().get(0).getName().equals("r")); + assertTrue(i.getReferences().get(0) != r); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ajax/DISCLAIMER b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ajax/DISCLAIMER new file mode 100644 index 0000000000..d68a410903 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ajax/DISCLAIMER @@ -0,0 +1,8 @@ +Apache Tuscany is an effort undergoing incubation at The Apache Software +Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is +required of all newly accepted projects until a further review indicates that +the infrastructure, communications, and decision making process have stabilized +in a manner consistent with other successful ASF projects. While incubation +status is not necessarily a reflection of the completeness or stability of the +code, it does indicate that the project has yet to be fully endorsed by the ASF. + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ajax/LICENSE b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ajax/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ajax/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ajax/NOTICE b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ajax/NOTICE new file mode 100644 index 0000000000..94481d6cfa --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ajax/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2007 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ajax/pom.xml b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ajax/pom.xml new file mode 100644 index 0000000000..87c6f7f8da --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ajax/pom.xml @@ -0,0 +1,76 @@ + + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 0.91-incubating-SNAPSHOT + ../pom.xml + + + tuscany-binding-ajax + Apache Tuscany Binding for AJAX clients + + + + + org.apache.tuscany.sca + tuscany-extension-helper + 0.91-incubating-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-host-http + 0.91-incubating-SNAPSHOT + + + + org.directwebremoting + dwr + 2.0.1 + + + + javax.servlet + servlet-api + 2.4 + provided + + + + junit + junit + 3.8.1 + test + + + + org.easymock + easymock + 2.2 + test + + + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ajax/src/main/java/org/apache/tuscany/sca/binding/ajax/AjaxBinding.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ajax/src/main/java/org/apache/tuscany/sca/binding/ajax/AjaxBinding.java new file mode 100644 index 0000000000..9e244e5e5a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ajax/src/main/java/org/apache/tuscany/sca/binding/ajax/AjaxBinding.java @@ -0,0 +1,32 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.ajax; + + + + +/** + * The runtime representation of the SCDL + */ +public class AjaxBinding { + + // Empty as doesn't use any additional attributes or elements (yet). + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ajax/src/main/java/org/apache/tuscany/sca/binding/ajax/AjaxBindingActivator.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ajax/src/main/java/org/apache/tuscany/sca/binding/ajax/AjaxBindingActivator.java new file mode 100644 index 0000000000..5483473961 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ajax/src/main/java/org/apache/tuscany/sca/binding/ajax/AjaxBindingActivator.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.ajax; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.http.ServletHost; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; +import org.apache.tuscany.sca.spi.BindingActivator; +import org.apache.tuscany.sca.spi.ComponentLifecycle; +import org.apache.tuscany.sca.spi.InvokerFactory; + +public class AjaxBindingActivator implements BindingActivator{ + + private ServletHost servletHost; + + public AjaxBindingActivator(ServletHost servletHost) { + this.servletHost = servletHost; + } + + public Class getBindingClass() { + return AjaxBinding.class; + } + + public InvokerFactory createInvokerFactory(RuntimeComponent rc, RuntimeComponentReference rcr, Binding b, AjaxBinding ab) { + return new AjaxInvokerFactory(rc, rcr, b, ab, servletHost); + } + + public ComponentLifecycle createService(RuntimeComponent rc, RuntimeComponentService rcs, Binding b, AjaxBinding ab) { + return new AjaxService(rc, rcs, b, ab, servletHost); + } + + public InvokerFactory createInvokerFactory(RuntimeComponent rc, RuntimeComponentReference rcr, AjaxBinding binding) { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ajax/src/main/java/org/apache/tuscany/sca/binding/ajax/AjaxInvoker.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ajax/src/main/java/org/apache/tuscany/sca/binding/ajax/AjaxInvoker.java new file mode 100644 index 0000000000..c05ae7ab09 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ajax/src/main/java/org/apache/tuscany/sca/binding/ajax/AjaxInvoker.java @@ -0,0 +1,88 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.ajax; + +import java.util.Collection; + +import org.apache.tuscany.sca.core.invocation.MessageImpl; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.directwebremoting.ScriptBuffer; +import org.directwebremoting.WebContext; +import org.directwebremoting.WebContextFactory; +import org.directwebremoting.proxy.dwr.Util; + +public class AjaxInvoker implements Invoker { + + protected String referenceFunction; + + public AjaxInvoker(String referenceName, Operation operation) { + this.referenceFunction = referenceName + "." + operation.getName(); + } + + public Message invoke(Message requestMsg) { + + invoke((Object[])requestMsg.getBody()); + + // Ajax references can not return anything + return new MessageImpl(); + } + + public void invoke(Object[] args) { + + // TODO: this only works if its the same thread as request + WebContext wctx = WebContextFactory.get(); + String currentPage = wctx.getCurrentPage(); + + // Get a DWR Util proxy for all the browsers on the current page: + Collection sessions = wctx.getScriptSessionsByPage(currentPage); + Util utilAll = new Util(sessions); + + ScriptBuffer referenceInvoke = getInvokeFragment(args, wctx); + + // add the reference call to the Util proxy which will cause DWR to + // asynchronously send it to be run on each active browser client + utilAll.addScript(referenceInvoke); + } + + /** + * Creates a fragment of JavaScript code to invoke the reference function + * Eg: ".(arg1, arg2,...);" + */ + protected ScriptBuffer getInvokeFragment(Object[] args, WebContext wctx) { + + ScriptBuffer sb = new ScriptBuffer(); + sb.appendScript(referenceFunction); + sb.appendScript("("); + if (args != null) { + for (int i = 0; i < args.length; i++) { + sb.appendData(args[i]); + if (i < (args.length - 1)) { + sb.appendScript(", "); + } + } + } + sb.appendScript(");"); + + return sb; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ajax/src/main/java/org/apache/tuscany/sca/binding/ajax/AjaxInvokerFactory.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ajax/src/main/java/org/apache/tuscany/sca/binding/ajax/AjaxInvokerFactory.java new file mode 100644 index 0000000000..a1493c5e7f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ajax/src/main/java/org/apache/tuscany/sca/binding/ajax/AjaxInvokerFactory.java @@ -0,0 +1,69 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.ajax; + +import static org.apache.tuscany.sca.binding.ajax.AjaxService.SERVLET_PATH; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.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; +import org.apache.tuscany.sca.spi.ComponentLifecycle; +import org.apache.tuscany.sca.spi.InvokerFactory; + +public class AjaxInvokerFactory implements InvokerFactory, ComponentLifecycle { + + protected RuntimeComponent runtimeComponent; + protected RuntimeComponentReference runtimeComponentReference; + protected Binding binding; + protected ServletHost servletHost; + + public AjaxInvokerFactory(RuntimeComponent rc, RuntimeComponentReference rcr, Binding b, AjaxBinding ab, ServletHost servletHost) { + this.runtimeComponent = rc; + this.runtimeComponentReference = rcr; + this.binding = b; + this.servletHost = servletHost; + } + + public Invoker createInvoker(Operation operation) { + return new AjaxInvoker(binding.getName(), operation); + } + + public void start() { + + // there is no "getServlet" method on ServletHost so this has to use remove/add + + AjaxServlet servlet = (AjaxServlet) servletHost.removeServletMapping(SERVLET_PATH); + if (servlet == null) { + servlet = new AjaxServlet(); + } + + servlet.addReference(binding.getName()); + + servletHost.addServletMapping(SERVLET_PATH, servlet); + } + + public void stop() { + servletHost.removeServletMapping(SERVLET_PATH); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ajax/src/main/java/org/apache/tuscany/sca/binding/ajax/AjaxService.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ajax/src/main/java/org/apache/tuscany/sca/binding/ajax/AjaxService.java new file mode 100644 index 0000000000..3a6f327dd6 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ajax/src/main/java/org/apache/tuscany/sca/binding/ajax/AjaxService.java @@ -0,0 +1,66 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.ajax; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.http.ServletHost; +import org.apache.tuscany.sca.interfacedef.java.JavaInterface; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; +import org.apache.tuscany.sca.spi.ComponentLifecycle; + +public class AjaxService implements ComponentLifecycle { + + RuntimeComponent rc; + RuntimeComponentService rcs; + Binding binding; + protected ServletHost servletHost; + + public static final String SERVLET_PATH = AjaxServlet.AJAX_SERVLET_PATH + "/*"; + + public AjaxService(RuntimeComponent rc, RuntimeComponentService rcs, Binding binding, AjaxBinding ab, ServletHost servletHost) { + this.rc = rc; + this.rcs = rcs; + this.binding = binding; + this.servletHost = servletHost; + } + + public void start() { + + // there is no "getServlet" method on ServletHost so this has to use remove/add + + AjaxServlet servlet = (AjaxServlet) servletHost.removeServletMapping(SERVLET_PATH); + if (servlet == null) { + servlet = new AjaxServlet(); + } + + Class type = ((JavaInterface)rcs.getInterfaceContract().getInterface()).getJavaClass(); + Object instance = rc.createSelfReference(type).getService(); + + servlet.addService(binding.getName(), type, instance); + + servletHost.addServletMapping(SERVLET_PATH, servlet); + } + + public void stop() { + servletHost.removeServletMapping(SERVLET_PATH); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ajax/src/main/java/org/apache/tuscany/sca/binding/ajax/AjaxServlet.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ajax/src/main/java/org/apache/tuscany/sca/binding/ajax/AjaxServlet.java new file mode 100644 index 0000000000..c4209bfbf7 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ajax/src/main/java/org/apache/tuscany/sca/binding/ajax/AjaxServlet.java @@ -0,0 +1,444 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.ajax; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.PrintWriter; +import java.io.UnsupportedEncodingException; +import java.security.Principal; +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.Locale; +import java.util.Map; + +import javax.servlet.RequestDispatcher; +import javax.servlet.ServletConfig; +import javax.servlet.ServletContext; +import javax.servlet.ServletException; +import javax.servlet.ServletInputStream; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +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 Ajax binding + * + * Handles requests for SCA services and references that use , + * and also the HTTP GET for the Tuscany ajax system script "scaDomain.js" + */ +public class AjaxServlet extends DwrServlet { + private static final long serialVersionUID = 1L; + + transient protected Map services; + transient protected List referenceNames; + transient protected boolean initialized; + transient protected Map initParams; + + protected static final String SCADOMAIN_SCRIPT_PATH = "/scaDomain.js"; + public static final String AJAX_SERVLET_PATH = "/SCADomain"; + + public AjaxServlet() { + 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(patchRequest((HttpServletRequest)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 . + */ + protected 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. + */ + protected void tuscanyFooter(HttpServletRequest request, PrintWriter out) { + out.println("/** Apache Tuscany scaDomain.js Footer */"); + out.println(); + out.println("function scaDomain() { }"); + out.println(); + + // Alter the value of these variables in DWR engine.js to add in this servlet's path + out.println("dwr.engine._ModePlainCall = '" + AJAX_SERVLET_PATH + "/call/plaincall/';"); + out.println("dwr.engine._ModeHtmlCall = '" + AJAX_SERVLET_PATH + "/call/htmlcall/';"); + out.println("dwr.engine._ModePlainPoll = '" + AJAX_SERVLET_PATH + "/call/plainpoll/';"); + out.println("dwr.engine._ModeHtmlPoll = '" + AJAX_SERVLET_PATH + "/call/htmlpoll/';"); + + out.println(); + out.println("// SCA sevices"); + + // 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 + */ + protected 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 + 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. + */ + protected 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; + } + + /** + * This changes the value returned from getPathInfo so that it does not include + * the path prefix of this Servlet. The DWR servlet expects its handlers to be + * at the root, eg /call/plaincall/, so they aren't found if the value request + * getPathInfo returns includes this servlets path, eg /SCADomain/call/plaincall/ + */ + protected HttpServletRequest patchRequest(final HttpServletRequest req) { + + final String translatedPath = req.getPathInfo().substring(AJAX_SERVLET_PATH.length()); + + HttpServletRequest patchedRequest = new HttpServletRequest() { + public Object getAttribute(String arg0) { + return req.getAttribute(arg0); + } + public Enumeration getAttributeNames() { + return req.getAttributeNames(); + } + public String getCharacterEncoding() { + return req.getCharacterEncoding(); + } + public int getContentLength() { + return req.getContentLength(); + } + public String getContentType() { + return req.getContentType(); + } + public ServletInputStream getInputStream() throws IOException { + return req.getInputStream(); + } + public String getLocalAddr() { + return req.getLocalAddr(); + } + public String getLocalName() { + return req.getLocalName(); + } + public int getLocalPort() { + return req.getLocalPort(); + } + public Locale getLocale() { + return req.getLocale(); + } + public Enumeration getLocales() { + return req.getLocales(); + } + public String getParameter(String arg0) { + return req.getParameter(arg0); + } + public Map getParameterMap() { + return req.getParameterMap(); + } + public Enumeration getParameterNames() { + return req.getParameterNames(); + } + public String[] getParameterValues(String arg0) { + return req.getParameterValues(arg0); + } + public String getProtocol() { + return req.getProtocol(); + } + public BufferedReader getReader() throws IOException { + return req.getReader(); + } + @SuppressWarnings("deprecation") + public String getRealPath(String arg0) { + return req.getRealPath(arg0); + } + public String getRemoteAddr() { + return req.getRemoteAddr(); + } + public String getRemoteHost() { + return req.getRemoteHost(); + } + public int getRemotePort() { + return req.getRemotePort(); + } + public RequestDispatcher getRequestDispatcher(String arg0) { + return req.getRequestDispatcher(arg0); + } + public String getScheme() { + return req.getScheme(); + } + public String getServerName() { + return req.getServerName(); + } + public int getServerPort() { + return req.getServerPort(); + } + public boolean isSecure() { + return req.isSecure(); + } + public void removeAttribute(String arg0) { + req.removeAttribute(arg0); + } + public void setAttribute(String arg0, Object arg1) { + req.setAttribute(arg0, arg1); + } + public void setCharacterEncoding(String arg0) throws UnsupportedEncodingException { + req.setCharacterEncoding(arg0); + } + public String getAuthType() { + return req.getAuthType(); + } + public String getContextPath() { + return req.getContextPath(); + } + public Cookie[] getCookies() { + return req.getCookies(); + } + public long getDateHeader(String arg0) { + return req.getDateHeader(arg0); + } + public String getHeader(String arg0) { + return req.getHeader(arg0); + } + public Enumeration getHeaderNames() { + return req.getHeaderNames(); + } + public Enumeration getHeaders(String arg0) { + return req.getHeaders(arg0); + } + public int getIntHeader(String arg0) { + return req.getIntHeader(arg0); + } + public String getMethod() { + return req.getMethod(); + } + public String getPathInfo() { + + // *** return the translated path + + return translatedPath; + } + public String getPathTranslated() { + return req.getPathTranslated(); + } + public String getQueryString() { + return req.getQueryString(); + } + public String getRemoteUser() { + return req.getRemoteUser(); + } + public String getRequestURI() { + return req.getRequestURI(); + } + public StringBuffer getRequestURL() { + return req.getRequestURL(); + } + public String getRequestedSessionId() { + return req.getRequestedSessionId(); + } + public String getServletPath() { + return req.getServletPath(); + } + public HttpSession getSession() { + return req.getSession(); + } + public HttpSession getSession(boolean arg0) { + return req.getSession(arg0); + } + public Principal getUserPrincipal() { + return req.getUserPrincipal(); + } + public boolean isRequestedSessionIdFromCookie() { + return req.isRequestedSessionIdFromCookie(); + } + public boolean isRequestedSessionIdFromURL() { + return req.isRequestedSessionIdFromURL(); + } + @SuppressWarnings("deprecation") + public boolean isRequestedSessionIdFromUrl() { + return req.isRequestedSessionIdFromUrl(); + } + public boolean isRequestedSessionIdValid() { + return req.isRequestedSessionIdValid(); + } + public boolean isUserInRole(String arg0) { + return req.isUserInRole(arg0); + } + + }; + return patchedRequest; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ajax/src/main/resources/META-INF/services/org.apache.tuscany.sca.spi.BindingActivator b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ajax/src/main/resources/META-INF/services/org.apache.tuscany.sca.spi.BindingActivator new file mode 100644 index 0000000000..d09c9f4306 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ajax/src/main/resources/META-INF/services/org.apache.tuscany.sca.spi.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.ajax.AjaxBindingActivator + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/DISCLAIMER b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/DISCLAIMER new file mode 100644 index 0000000000..d68a410903 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/DISCLAIMER @@ -0,0 +1,8 @@ +Apache Tuscany is an effort undergoing incubation at The Apache Software +Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is +required of all newly accepted projects until a further review indicates that +the infrastructure, communications, and decision making process have stabilized +in a manner consistent with other successful ASF projects. While incubation +status is not necessarily a reflection of the completeness or stability of the +code, it does indicate that the project has yet to be fully endorsed by the ASF. + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/LICENSE b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/NOTICE b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/NOTICE new file mode 100644 index 0000000000..94481d6cfa --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2007 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/pom.xml b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/pom.xml new file mode 100644 index 0000000000..7d38a027ea --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/pom.xml @@ -0,0 +1,456 @@ + + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 0.91-incubating-SNAPSHOT + ../pom.xml + + + tuscany-binding-ejb + Apache Tuscany Binding for Stateless Session Bean + Implementation of Stateless Session Bean binding + + + + + org.apache.tuscany.sca + tuscany-extension-helper + 0.91-incubating-SNAPSHOT + + + + org.apache.geronimo.specs + geronimo-ejb_2.1_spec + 1.0.1 + compile + + + + cglib + cglib-nodep + 2.1_3 + runtime + + + + junit + junit + 3.8.1 + test + + + + org.easymock + easymock + 2.2 + test + + + + org.apache.tuscany.sca + tuscany-implementation-java-runtime + 0.91-incubating-SNAPSHOT + test + + + + org.apache.geronimo.specs + geronimo-j2ee-jacc_1.0_spec + 1.0 + test + + + + + + + openejb + openejb-core + 2.1.1 + test + + + + geronimo + geronimo-connector + + + geronimo + geronimo-core + + + geronimo + geronimo-client + + + geronimo + geronimo-common + + + geronimo + geronimo-deployment + + + geronimo + geronimo-j2ee + + + geronimo + geronimo-management + + + geronimo + geronimo-kernel + + + activeio + activeio + + + geronimo + geronimo-security + + + geronimo + geronimo-timer + + + geronimo + geronimo-transaction + + + geronimo + geronimo-axis + + + geronimo + geronimo-axis-builder + + + geronimo + geronimo-naming + + + geronimo + geronimo-system + + + geronimo + geronimo-util + + + org.apache.geronimo.specs + geronimo-j2ee-deployment_1.1_spec + + + geronimo-spec + geronimo-spec-corba + + + org.apache.geronimo.specs + geronimo-jta_1.0.1B_spec + + + org.apache.geronimo.specs + geronimo-ejb_2.1_spec + + + org.apache.geronimo.specs + geronimo-servlet_2.4_spec + + + org.apache.geronimo.specs + geronimo-j2ee-connector_1.5_spec + + + org.apache.geronimo.specs + geronimo-j2ee-jacc_1.0_spec + + + org.apache.geronimo.specs + geronimo-jms_1.1_spec + + + org.apache.geronimo.specs + geronimo-j2ee-management_1.0_spec + + + org.apache.geronimo.specs + geronimo-jaxrpc_1.1_spec + + + org.apache.geronimo.specs + geronimo-saaj_1.1_spec + + + org.apache.geronimo.specs + geronimo-qname_1.1_spec + + + geronimo + geronimo-webservices + + + tranql + tranql + + + antlr + antlr + + + axion + axion + + + castor + castor + + + oro + oro + + + cglib + cglib-nodep + + + commons-logging + commons-logging + + + commons-primitives + commons-primitives + + + concurrent + concurrent + + + log4j + log4j + + + mx4j + mx4j + + + regexp + regexp + + + xerces + xercesImpl + + + xerces + xmlParserAPIs + + + commons-cli + commons-cli + + + asm + asm + + + axis + axis + + + xmlbeans + xbean + + + commons-jelly + commons-jelly-tags-velocity + + + velocity + velocity + + + + + + geronimo + geronimo-security + 1.1.1 + test + + + org.apache.geronimo.specs + geronimo-j2ee-jacc_1.0_spec + + + geronimo + geronimo-common + + + geronimo + geronimo-util + + + geronimo + geronimo-core + + + geronimo + geronimo-j2ee + + + geronimo + geronimo-management + + + geronimo + geronimo-kernel + + + geronimo + geronimo-system + + + + cglib + cglib-nodep + + + concurrent + concurrent + + + activeio + activeio + + + commons-logging + commons-logging + + + mx4j + mx4j + + + regexp + regexp + + + hsqldb + hsqldb + + + log4j + log4j + + + commons-jelly + commons-jelly-tags-velocity + + + velocity + velocity + + + + + + geronimo + geronimo-common + 1.1.1 + test + + + commons-jelly + commons-jelly-tags-velocity + + + log4j + log4j + + + mx4j + mx4j + + + + + + geronimo + geronimo-kernel + 1.1.1 + test + + + log4j + log4j + + + org.apache.geronimo.specs + geronimo-qname + + + org.apache.geronimo.specs + geronimo-qname_1.1_spec + + + xstream + xstream + + + log4j + log4j + + + commons-jelly + commons-jelly-tags-velocity + + + xpp3 + xpp3 + + + mx4j + mx4j + + + org.apache.geronimo.specs + geronimo-j2ee-management_1.0_spec + + + org.apache.geronimo.specs + geronimo-j2ee-deployment_1.1_spec + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/EJBBinding.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/EJBBinding.java new file mode 100644 index 0000000000..c4b72ed274 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/EJBBinding.java @@ -0,0 +1,102 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.ejb; + + + +/** + * An implementation of EJBBinding. + */ +public class EJBBinding { + + /** + * corba location For exmaple, + * "corbaname:iiop:localhost:2809/NameServiceServerRoot#ejb/MyEJBHome" + */ + private String uri; + + /** + * homeInterface. remote or local + */ + private String homeInterface; + + /** + * The ejb-link-name attribute allows a SCA client to bind to an EJB that is + * packaged in the same JEE EAR file as the SCA client. This is functionally + * equivalent to using the subelement of the element + * in s EJB deployment descriptor. Used only for Service binding + */ + private String ejbLinkName; + + /** + * Gets the homeInterface. + * + * @return home interface of the service binding + */ + public String getHomeInterface() { + return homeInterface; + } + + /** + * Set homeInterface + * + * @param homeInterface + */ + public void setHomeInterface(String homeInterface) { + this.homeInterface = homeInterface; + } + + /** + * get ejb-link-name + * + * @return ejb-link-name + */ + public String getEjbLinkName() { + return ejbLinkName; + } + + /** + * Set ejb-link-name + * + * @param ejb-link-name + */ + public void setEjbLinkName(String ejbLinkName) { + this.ejbLinkName = ejbLinkName; + } + + // TODO: uri needs to be part of runtime extension helper + + /** + * Sets binding URI. + * + * @param value the binding uri + */ + public void setUri(String value) { + this.uri = value; + } + + /** + * gets binding URI. + * + * @return value the binding uri + */ + public String getUri() { + return uri; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/EJBBindingActivator.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/EJBBindingActivator.java new file mode 100644 index 0000000000..5538186dc4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/EJBBindingActivator.java @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.ejb; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.java.JavaInterface; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; +import org.apache.tuscany.sca.spi.BindingActivator; +import org.apache.tuscany.sca.spi.ComponentLifecycle; +import org.apache.tuscany.sca.spi.InvokerFactory; +import org.osoa.sca.ServiceRuntimeException; + +public class EJBBindingActivator implements BindingActivator { + + public InvokerFactory createInvokerFactory(RuntimeComponent rc, RuntimeComponentReference rcr, final Binding b, final EJBBinding binding) { + // TODO: assumes a Java interface, need to support tuscany generic Interface + final Class si = ((JavaInterface)rcr.getInterfaceContract().getInterface()).getJavaClass(); + return new InvokerFactory() { + public Invoker createInvoker(Operation operation) { + return new EJBTargetInvoker((EJBBinding)binding, si, operation); + } + }; + } + + public ComponentLifecycle createService(RuntimeComponent rc, RuntimeComponentService rcs, Binding b, EJBBinding binding) { + throw new ServiceRuntimeException("services not yet implemented for binding.ejb"); + } + + public Class getBindingClass() { + return EJBBinding.class; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/EJBTargetInvoker.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/EJBTargetInvoker.java new file mode 100644 index 0000000000..0c384c2c7b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/EJBTargetInvoker.java @@ -0,0 +1,79 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.ejb; + +import org.apache.tuscany.sca.binding.ejb.util.EJBHandler; +import org.apache.tuscany.sca.binding.ejb.util.NamingEndpoint; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; + +/** + * EJBTargetInvoker + */ +public class EJBTargetInvoker implements Invoker { + + private Operation operation; + private String location; + private Class serviceInterface; + + public EJBTargetInvoker(EJBBinding ejbBinding, Class serviceInterface, Operation operation) { + this.serviceInterface = serviceInterface; + this.location = ejbBinding.getUri(); + this.operation = operation; + } + + public Message invoke(Message msg) { + try { + Object resp = doInvoke(msg.getBody()); + msg.setBody(resp); + } catch (Throwable e) { + e.printStackTrace(); + msg.setBody(e); + } + return msg; + } + + /** + * Invoke a EJB operation + * + * @param payload + * @return + */ + public Object doInvoke(final Object payload) { + + // construct NamingendPoint + NamingEndpoint endpoint = getNamingEndpoint(); + + // lookup home and ejb stub + EJBHandler ejbHandler = new EJBHandler(endpoint, serviceInterface); + + String methodName = operation.getName(); + + // invoke business method on ejb + Object response = ejbHandler.invoke(methodName, (Object[])payload); + + return response; + } + + protected NamingEndpoint getNamingEndpoint() { + return new NamingEndpoint(location); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/AttributeMode.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/AttributeMode.java new file mode 100644 index 0000000000..437debd2e4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/AttributeMode.java @@ -0,0 +1,62 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.ejb.java2idl; + +import java.io.ObjectStreamException; +import org.omg.CORBA.BAD_PARAM; +import org.omg.CORBA.portable.IDLEntity; + +/** + * Mode of an IDL attribute + */ +public final class AttributeMode implements IDLEntity { + private static final long serialVersionUID = 4193442157999151834L; + + private int value; + + public static final int _ATTR_NORMAL = 0; + + public static final AttributeMode ATTR_NORMAL = new AttributeMode(_ATTR_NORMAL); + + public static final int _ATTR_READONLY = 1; + + public static final AttributeMode ATTR_READONLY = new AttributeMode(_ATTR_READONLY); + + public int value() { + return value; + } + + public static AttributeMode from_int(int i) { + switch (i) { + case _ATTR_NORMAL: + return ATTR_NORMAL; + case _ATTR_READONLY: + return ATTR_READONLY; + } + throw new BAD_PARAM(); + } + + private AttributeMode(int i) { + value = i; + } + + Object readResolve() throws ObjectStreamException { + return from_int(value()); + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/AttributeType.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/AttributeType.java new file mode 100644 index 0000000000..0aa94b087e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/AttributeType.java @@ -0,0 +1,136 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.ejb.java2idl; + +import java.lang.reflect.Method; +import java.rmi.Remote; + +/** + * IDL Attribute + */ +public class AttributeType extends IDLType { + + /** + * Attribute mode. + */ + private AttributeMode mode; + + /** + * Read Method. + */ + private Method readMethod = null; + /** + * Write Method. This is null for read-only attributes. + */ + private Method writeMethod = null; + /** + * Read method type. + */ + private OperationType readOperationType = null; + /** + * Write method type. This is null for read-only attributes. + */ + private OperationType writeOperationType = null; + + /** + * Create an attribute type. + */ + private AttributeType(String javaName, AttributeMode mode, Method readMethod, Method writeMethod) { + super(IDLUtil.javaToIDLName(javaName), javaName); + this.mode = mode; + // this.cls = readMethod.getReturnType(); + this.readMethod = readMethod; + this.writeMethod = writeMethod; + // Only do operation type if the attribute is in a remote interface. + if (readMethod.getDeclaringClass().isInterface() && Remote.class.isAssignableFrom(readMethod + .getDeclaringClass())) { + readOperationType = new OperationType(readMethod); + if (writeMethod != null) + writeOperationType = new OperationType(writeMethod); + setIDLName(getIDLName()); // Fixup operation names + } + } + + /** + * Create an attribute type for a read-only attribute. + */ + AttributeType(String javaName, Method accessor) { + this(javaName, AttributeMode.ATTR_READONLY, accessor, null); + } + + /** + * Create an attribute type for a read-write attribute. + */ + AttributeType(String javaName, Method accessor, Method mutator) { + this(javaName, AttributeMode.ATTR_NORMAL, accessor, mutator); + } + + /** + * Return the attribute mode. + */ + public AttributeMode getMode() { + return mode; + } + + /** + * Return the accessor method + */ + public Method getReadMethod() { + return readMethod; + } + + /** + * Return the mutator method + */ + public Method getWriteMethod() { + return writeMethod; + } + + /** + * Return the accessor operation type + */ + public OperationType getReadOperationType() { + return readOperationType; + } + + /** + * Return the mutator operation type + */ + public OperationType getWriteOperationType() { + return writeOperationType; + } + + /** + * Set the unqualified IDL name. This also sets the names of the associated + * operations. + */ + void setIDLName(String idlName) { + super.setIDLName(idlName); + // If the first char is an uppercase letter and the second char is not + // an uppercase letter, then convert the first char to lowercase. + char ch0 = idlName.charAt(0); + if (Character.isUpperCase(ch0) && (idlName.length() <= 1 || (!Character.isUpperCase(idlName.charAt(1))))) { + idlName = Character.toLowerCase(ch0) + idlName.substring(1); + } + if (readOperationType != null) + readOperationType.setIDLName("_get_" + idlName); + if (writeOperationType != null) + writeOperationType.setIDLName("_set_" + idlName); + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/ClassType.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/ClassType.java new file mode 100644 index 0000000000..b6e2dba87e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/ClassType.java @@ -0,0 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.ejb.java2idl; + +/** + * IDL types. + */ +public class ClassType extends IDLType { + + /** + * java class. + */ + protected Class javaClass; + + private static String getJavaName(Class cls) { + if (cls == null) + throw new IllegalArgumentException("Class cannot be null."); + String s = cls.getName(); + int index = s.lastIndexOf('.'); + if (index == -1) + return s; + else + return s.substring(index + 1); + } + + public ClassType(Class cls, String idlName, String javaName) { + super(idlName, javaName); + this.javaClass = cls; + } + + public ClassType(Class cls, String javaName) { + this(cls, IDLUtil.javaToIDLName(javaName), javaName); + } + + public ClassType(Class cls) { + this(cls, getJavaName(cls)); + } + + /** + * Return java class. + */ + public Class getJavaClass() { + return javaClass; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/ConstantType.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/ConstantType.java new file mode 100644 index 0000000000..5a6cc78317 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/ConstantType.java @@ -0,0 +1,68 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.ejb.java2idl; + +import org.omg.CORBA.Any; + +/** + * IDL Constant + */ +public class ConstantType extends IDLType { + + /** + * Java type of constant. + */ + private Class type; + /** + * The value of the constant. + */ + private Object value; + + ConstantType(String javaName, Class type, Object value) { + super(javaName); + if (type == void.class || (!type.isPrimitive()) && type != java.lang.String.class) + throw new IllegalArgumentException("Illegal type for constant: " + type.getName()); + this.type = type; + this.value = value; + } + + /** + * Return my Java type. + */ + public Class getType() { + return type; + } + + /** + * Return my value. + */ + public Object getValue() { + return value; + } + + /** + * Insert the constant value into the argument Any. + */ + public void insertValue(Any any) { + if (type == String.class) + any.insert_wstring((String)value); // 1.3.5.10 Map to wstring + else + IDLUtil.insertAnyPrimitive(any, value); + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/ContainerType.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/ContainerType.java new file mode 100644 index 0000000000..18216db742 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/ContainerType.java @@ -0,0 +1,791 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.ejb.java2idl; + +import java.io.Externalizable; +import java.io.ObjectStreamClass; +import java.io.Serializable; +import java.lang.ref.SoftReference; +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.rmi.RemoteException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; +import java.util.WeakHashMap; + +/** + * Common base class of ValueType and InterfaceType. + */ +public abstract class ContainerType extends ClassType { + + /** Flags a method as overloaded. */ + protected final byte M_OVERLOADED = 1; + /** Flags a method as the accessor of a read-write property. */ + protected final byte M_READ = 2; + /** Flags a method as the mutator of a read-write property. */ + protected final byte M_WRITE = 4; + /** Flags a method as the accessor of a read-only property. */ + protected final byte M_READONLY = 8; + /** Flags a method as being inherited. */ + protected final byte M_INHERITED = 16; + /** + * Flags a method as being the writeObject() method used for serialization. + */ + protected final byte M_WRITEOBJECT = 32; + /** Flags a field as being a constant (public final static). */ + protected final byte F_CONSTANT = 1; + /** + * Flags a field as being the special public final static + * java.io.ObjectStreamField[] serialPersistentFields + * field. + */ + protected final byte F_SPFFIELD = 2; + + /** + * Array of all java methods. + */ + protected Method[] methods; + /** + * Array with flags for all java methods. + */ + protected byte[] m_flags; + /** + * Index of the mutator for read-write attributes. Only entries + * i where (m_flags[i]&M_READ) != 0 are used. + * These entries contain the index of the mutator method corresponding to + * the accessor method. + */ + protected int[] setters; + /** + * Array of all java fields. + */ + protected Field[] fields; + /** + * Array with flags for all java fields. + */ + protected byte[] f_flags; + /** + * The class hash code, as specified in "The Common Object Request Broker: + * Architecture and Specification" (01-02-33), section 10.6.2. + */ + protected long classHashCode = 0; + /** + * The repository ID. This is in the RMI hashed format, like + * "RMI:java.util.Hashtable:C03324C0EA357270:13BB0F25214AE4B8". + */ + protected String repositoryId; + /** + * The prefix and postfix of members repository ID. These are used to + * calculate member repository IDs and are like "RMI:java.util.Hashtable." + * and ":C03324C0EA357270:13BB0F25214AE4B8". + */ + protected String memberPrefix, memberPostfix; + /** + * Array of type of the interfaces implemented/extended here. + */ + protected InterfaceType[] interfaces; + /** + * Array of type of the abstract base valuetypes implemented/extended here. + */ + protected ValueType[] abstractBaseValuetypes; + /** + * Array of attributes. + */ + protected AttributeType[] attributes; + /** + * Array of Constants. + */ + protected ConstantType[] constants; + /** + * Array of operations. + */ + protected OperationType[] operations; + + /** + * A cache for the fully qualified IDL name of the IDL module we belong to. + */ + private String idlModuleName = null; + + protected ContainerType(Class cls) { + super(cls); + if (cls == java.lang.Object.class || cls == java.io.Serializable.class || cls == java.io.Externalizable.class) + throw new IllegalArgumentException("Cannot parse special class: " + cls.getName()); + this.javaClass = cls; + } + + protected void parse() { + parseInterfaces(); + parseMethods(); + parseFields(); + calculateClassHashCode(); + calculateRepositoryId(); + parseAttributes(); + parseConstants(); + parseOperations(); + fixupOverloadedOperationNames(); + } + + /** + * Return the interfaces. + */ + public InterfaceType[] getInterfaces() { + return (InterfaceType[])interfaces.clone(); + } + + /** + * Return the abstract base valuetypes. + */ + public ValueType[] getAbstractBaseValuetypes() { + return (ValueType[])abstractBaseValuetypes.clone(); + } + + /** + * Return the attributes. + */ + public AttributeType[] getAttributes() { + return (AttributeType[])attributes.clone(); + } + + /** + * Return the constants. + */ + public ConstantType[] getConstants() { + return (ConstantType[])constants.clone(); + } + + /** + * Return the operations. + */ + public OperationType[] getOperations() { + return (OperationType[])operations.clone(); + } + + /** + * Return the repository ID. + */ + public String getRepositoryId() { + return repositoryId; + } + + /** + * Return a repository ID for a member. + * + * @param memberName The Java name of the member. + */ + public String getMemberRepositoryId(String memberName) { + return memberPrefix + escapeIRName(memberName) + memberPostfix; + } + + /** + * Return the fully qualified IDL module name that this type should be + * placed in. + */ + public String getIDLModuleName() { + if (idlModuleName == null) { + String pkgName = javaClass.getPackage().getName(); + StringBuffer b = new StringBuffer(); + while (!"".equals(pkgName)) { + int idx = pkgName.indexOf('.'); + String n = (idx == -1) ? pkgName : pkgName.substring(0, idx); + b.append("::").append(IDLUtil.javaToIDLName(n)); + pkgName = (idx == -1) ? "" : pkgName.substring(idx + 1); + } + idlModuleName = b.toString(); + } + return idlModuleName; + } + + // Protected ----------------------------------------------------- + /** + * Convert an integer to a 16-digit hex string. + */ + protected String toHexString(int i) { + String s = Integer.toHexString(i).toUpperCase(); + if (s.length() < 8) + return "00000000".substring(0, 8 - s.length()) + s; + else + return s; + } + + /** + * Convert a long to a 16-digit hex string. + */ + protected String toHexString(long l) { + String s = Long.toHexString(l).toUpperCase(); + if (s.length() < 16) + return "0000000000000000".substring(0, 16 - s.length()) + s; + else + return s; + } + + /** + * Check if a method is an accessor. + */ + protected boolean isReadMethod(Method m) { + Class returnType = m.getReturnType(); + if (!m.getName().startsWith("get")) + if (!m.getName().startsWith("is") || !(returnType == boolean.class)) + return false; + if (returnType == void.class) + return false; + if (m.getParameterTypes().length != 0) + return false; + return hasNonAppExceptions(m); + } + + /** + * Check if a method is a mutator. + */ + protected boolean isWriteMethod(Method m) { + if (!m.getName().startsWith("set")) + return false; + if (m.getReturnType() != void.class) + return false; + if (m.getParameterTypes().length != 1) + return false; + return hasNonAppExceptions(m); + } + + private static boolean isCheckedException(Class type) { + /* + * Is a checked exception + */ + if (!Throwable.class.isAssignableFrom(type)) + return false; + + if (Error.class.isAssignableFrom(type)) + return false; + + if (RuntimeException.class.isAssignableFrom(type)) + return false; + return true; + } + + /** + * Check if a method throws anything checked other than + * java.rmi.RemoteException and its subclasses. + */ + protected boolean hasNonAppExceptions(Method m) { + Class[] ex = m.getExceptionTypes(); + for (int i = 0; i < ex.length; ++i) { + if (!isCheckedException(ex[i])) + continue; + if (!RemoteException.class.isAssignableFrom(ex[i])) + return false; + } + return true; + } + + /** + * Analyse the fields of the class. This will fill in the + * fields and f_flags arrays. + */ + protected void parseFields() { + fields = javaClass.getDeclaredFields(); + f_flags = new byte[fields.length]; + for (int i = 0; i < fields.length; ++i) { + int mods = fields[i].getModifiers(); + if (Modifier.isFinal(mods) && Modifier.isStatic(mods) && Modifier.isPublic(mods)) + f_flags[i] |= F_CONSTANT; + } + } + + /** + * Analyse the interfaces of the class. This will fill in the + * interfaces array. + */ + protected void parseInterfaces() { + Class[] intfs = javaClass.getInterfaces(); + ArrayList a = new ArrayList(); + ArrayList b = new ArrayList(); + for (int i = 0; i < intfs.length; ++i) { + // Ignore java.rmi.Remote + if (intfs[i] == java.rmi.Remote.class) + continue; + // Ignore java.io.Serializable + if (intfs[i] == java.io.Serializable.class) + continue; + // Ignore java.io.Externalizable + if (intfs[i] == java.io.Externalizable.class) + continue; + if (!Java2IDLUtil.isAbstractValueType(intfs[i])) { + a.add(InterfaceType.getInterfaceType(intfs[i])); + } else { + b.add(ValueType.getValueType(intfs[i])); + } + } + interfaces = new InterfaceType[a.size()]; + interfaces = (InterfaceType[])a.toArray(interfaces); + abstractBaseValuetypes = new ValueType[b.size()]; + abstractBaseValuetypes = (ValueType[])b.toArray(abstractBaseValuetypes); + } + + /** + * Analyse the methods of the class. This will fill in the + * methods and m_flags arrays. + */ + protected void parseMethods() { + // The dynamic stub and skeleton strategy generation mechanism + // requires the inclusion of inherited methods in the type of + // remote interfaces. To speed things up, inherited methods are + // not considered in the type of a class or non-remote interface. + if (javaClass.isInterface() && java.rmi.Remote.class.isAssignableFrom(javaClass)) + methods = javaClass.getMethods(); + else + methods = javaClass.getDeclaredMethods(); + m_flags = new byte[methods.length]; + setters = new int[methods.length]; + // Find read-write properties + for (int i = 0; i < methods.length; ++i) + setters[i] = -1; // no mutator here + for (int i = 0; i < methods.length; ++i) { + if (isReadMethod(methods[i]) && (m_flags[i] & M_READ) == 0) { + String attrName = attributeReadName(methods[i].getName()); + Class iReturn = methods[i].getReturnType(); + for (int j = i + 1; j < methods.length; ++j) { + if (isWriteMethod(methods[j]) && (m_flags[j] & M_WRITE) == 0 + && attrName.equals(attributeWriteName(methods[j].getName()))) { + Class[] jParams = methods[j].getParameterTypes(); + if (jParams.length == 1 && jParams[0] == iReturn) { + m_flags[i] |= M_READ; + m_flags[j] |= M_WRITE; + setters[i] = j; + break; + } + } + } + } else if (isWriteMethod(methods[i]) && (m_flags[i] & M_WRITE) == 0) { + String attrName = attributeWriteName(methods[i].getName()); + Class[] iParams = methods[i].getParameterTypes(); + for (int j = i + 1; j < methods.length; ++j) { + if (isReadMethod(methods[j]) && (m_flags[j] & M_READ) == 0 + && attrName.equals(attributeReadName(methods[j].getName()))) { + Class jReturn = methods[j].getReturnType(); + if (iParams.length == 1 && iParams[0] == jReturn) { + m_flags[i] |= M_WRITE; + m_flags[j] |= M_READ; + setters[j] = i; + break; + } + } + } + } + } + // Find read-only properties + for (int i = 0; i < methods.length; ++i) + if ((m_flags[i] & (M_READ | M_WRITE)) == 0 && isReadMethod(methods[i])) + m_flags[i] |= M_READONLY; + // Check for overloaded and inherited methods + for (int i = 0; i < methods.length; ++i) { + if ((m_flags[i] & (M_READ | M_WRITE | M_READONLY)) == 0) { + String iName = methods[i].getName(); + for (int j = i + 1; j < methods.length; ++j) { + if (iName.equals(methods[j].getName())) { + m_flags[i] |= M_OVERLOADED; + m_flags[j] |= M_OVERLOADED; + } + } + } + if (methods[i].getDeclaringClass() != javaClass) + m_flags[i] |= M_INHERITED; + } + } + + /** + * Convert an attribute read method name in Java format to an attribute name + * in Java format. + */ + protected String attributeReadName(String name) { + if (name.startsWith("get")) + name = name.substring(3); + else if (name.startsWith("is")) + name = name.substring(2); + else + throw new IllegalArgumentException("Not an accessor: " + name); + return name; + } + + /** + * Convert an attribute write method name in Java format to an attribute + * name in Java format. + */ + protected String attributeWriteName(String name) { + if (name.startsWith("set")) + name = name.substring(3); + else + throw new IllegalArgumentException("Not an accessor: " + name); + return name; + } + + /** + * Analyse constants. This will fill in the constants array. + */ + protected void parseConstants() { + ArrayList a = new ArrayList(); + for (int i = 0; i < fields.length; ++i) { + if ((f_flags[i] & F_CONSTANT) == 0) + continue; + Class type = fields[i].getType(); + // Only map primitives and java.lang.String + if (!type.isPrimitive() && type != java.lang.String.class) { + // It is an RMI/IIOP violation for interfaces. + if (javaClass.isInterface()) + throw new IDLViolationException("Field \"" + fields[i].getName() + + "\" of interface \"" + + javaClass.getName() + + "\" is a constant, but not of one " + + "of the primitive types, or String.", "1.2.3"); + continue; + } + String name = fields[i].getName(); + Object value; + try { + value = fields[i].get(null); + } catch (Exception ex) { + throw new RuntimeException(ex.toString()); + } + a.add(new ConstantType(name, type, value)); + } + constants = new ConstantType[a.size()]; + constants = (ConstantType[])a.toArray(constants); + } + + /** + * Analyse attributes. This will fill in the attributes + * array. + */ + protected void parseAttributes() { + ArrayList a = new ArrayList(); + for (int i = 0; i < methods.length; ++i) { + // if ((m_flags[i]&M_INHERITED) != 0) + // continue; + if ((m_flags[i] & (M_READ | M_READONLY)) != 0) { + // Read method of an attribute. + String name = attributeReadName(methods[i].getName()); + if ((m_flags[i] & M_READONLY) != 0) + a.add(new AttributeType(name, methods[i])); + else + a.add(new AttributeType(name, methods[i], methods[setters[i]])); + } + } + + attributes = new AttributeType[a.size()]; + attributes = (AttributeType[])a.toArray(attributes); + } + + /** + * Analyse operations. This will fill in the operations + * array. This implementation just creates an empty array; override in + * subclasses for a real type. + */ + protected void parseOperations() { + operations = new OperationType[0]; + } + + /** + * Fixup overloaded operation names. As specified in section 1.3.2.6. + */ + protected void fixupOverloadedOperationNames() { + for (int i = 0; i < methods.length; ++i) { + if ((m_flags[i] & M_OVERLOADED) == 0) + continue; + // Find the operation + OperationType oa = null; + for (int opIdx = 0; oa == null && opIdx < operations.length; ++opIdx) + if (operations[opIdx].getMethod().equals(methods[i])) + oa = operations[opIdx]; + if (oa == null) + continue; // This method is not mapped. + // Calculate new IDL name + ParameterType[] parms = oa.getParameters(); + StringBuffer b = new StringBuffer(oa.getIDLName()); + if (parms.length == 0) + b.append("__"); + for (int j = 0; j < parms.length; ++j) { + String s = parms[j].getTypeIDLName(); + if (s.startsWith("::")) + s = s.substring(2); + b.append('_'); + while (!"".equals(s)) { + int idx = s.indexOf("::"); + b.append('_'); + if (idx == -1) { + b.append(s); + s = ""; + } else { + b.append(s.substring(0, idx)); + s = s.substring(idx + 2); + } + } + } + // Set new IDL name + oa.setIDLName(b.toString()); + } + } + + /** + * Fixup names differing only in case. As specified in section 1.3.2.7. + */ + protected void fixupCaseNames() { + ArrayList entries = getContainedEntries(); + boolean[] clash = new boolean[entries.size()]; + String[] upperNames = new String[entries.size()]; + for (int i = 0; i < entries.size(); ++i) { + IDLType aa = (IDLType)entries.get(i); + clash[i] = false; + upperNames[i] = aa.getIDLName().toUpperCase(); + for (int j = 0; j < i; ++j) { + if (upperNames[i].equals(upperNames[j])) { + clash[i] = true; + clash[j] = true; + } + } + } + for (int i = 0; i < entries.size(); ++i) { + if (!clash[i]) + continue; + IDLType aa = (IDLType)entries.get(i); + boolean noUpper = true; + String name = aa.getIDLName(); + StringBuffer b = new StringBuffer(name); + b.append('_'); + for (int j = 0; j < name.length(); ++j) { + if (!Character.isUpperCase(name.charAt(j))) + continue; + if (noUpper) + noUpper = false; + else + b.append('_'); + b.append(j); + } + aa.setIDLName(b.toString()); + } + } + + /** + * Return a list of all the entries contained here. + * + * @param entries The list of entries contained here. Entries in this list + * must be subclasses of AbstractType. + */ + abstract protected ArrayList getContainedEntries(); + + /** + * Return the class hash code, as specified in "The Common Object Request + * Broker: Architecture and Specification" (01-02-33), section 10.6.2. + */ + protected void calculateClassHashCode() { + // The simple cases + if (javaClass.isInterface()) + classHashCode = 0; + else if (!Serializable.class.isAssignableFrom(javaClass)) + classHashCode = 0; + else if (Externalizable.class.isAssignableFrom(javaClass)) + classHashCode = 1; + else + // Go ask Util class for the hash code + classHashCode = IDLUtil.getClassHashCode(javaClass); + } + + /** + * Escape non-ISO characters for an IR name. + */ + protected String escapeIRName(String name) { + StringBuffer b = new StringBuffer(); + for (int i = 0; i < name.length(); ++i) { + char c = name.charAt(i); + if (c < 256) + b.append(c); + else + b.append("\\U").append(toHexString((int)c)); + } + return b.toString(); + } + + /** + * Return the IR global ID of the given class or interface. This is + * described in section 1.3.5.7. The returned string is in the RMI hashed + * format, like "RMI:java.util.Hashtable:C03324C0EA357270:13BB0F25214AE4B8". + */ + protected void calculateRepositoryId() { + if (javaClass.isArray() || javaClass.isPrimitive()) + throw new IllegalArgumentException("Not a class or interface."); + if (javaClass.isInterface() && org.omg.CORBA.Object.class.isAssignableFrom(javaClass) + && org.omg.CORBA.portable.IDLEntity.class.isAssignableFrom(javaClass)) { + StringBuffer b = new StringBuffer("IDL:"); + b.append(javaClass.getPackage().getName().replace('.', '/')); + b.append('/'); + String base = javaClass.getName(); + base = base.substring(base.lastIndexOf('.') + 1); + b.append(base).append(":1.0"); + repositoryId = b.toString(); + } else { + StringBuffer b = new StringBuffer("RMI:"); + b.append(escapeIRName(javaClass.getName())); + memberPrefix = b.toString() + "."; + String hashStr = toHexString(classHashCode); + b.append(':').append(hashStr); + ObjectStreamClass osClass = ObjectStreamClass.lookup(javaClass); + if (osClass != null) { + long serialVersionUID = osClass.getSerialVersionUID(); + String SVUID = toHexString(serialVersionUID); + if (classHashCode != serialVersionUID) + b.append(':').append(SVUID); + memberPostfix = ":" + hashStr + ":" + SVUID; + } else + memberPostfix = ":" + hashStr; + repositoryId = b.toString(); + } + } + + /** + * A simple aggregate of work-in-progress, and the thread doing the work. + */ + private static class Task { + ContainerType type; + Thread thread; + + Task(ContainerType type, Thread thread) { + this.type = type; + this.thread = thread; + } + } + + /** + * Instances of this class cache the most complex types. The types cached + * are: + *
    + *
  • InterfaceType for interfaces.
  • + *
  • ValueType for value types.
  • + *
  • ExceptionType for exceptions.
  • + *
+ * Besides caching work already done, this caches work in progress, as we + * need to know about this to handle cyclic graphs of parses. When a thread + * re-enters the getType() metohd, an unfinished type will be + * returned if the same thread is already working on this type. + */ + protected static class WorkCache { + /** + * The type constructor of our type class. This constructor takes a + * single argument of type Class. + */ + private Constructor constructor; + + /** + * This maps the classes of completely done parses to soft references of + * their type. + */ + private Map workDone; + + /** + * This maps the classes of parses in progress to their type. + */ + private Map workInProgress; + + /** + * Create a new work cache manager. + * + * @param containerType The class of the type type we cache here. + */ + WorkCache(Class containerType) { + // Find the constructor and initializer. + try { + constructor = containerType.getDeclaredConstructor(new Class[] {Class.class}); + } catch (NoSuchMethodException ex) { + throw new IllegalArgumentException("Bad Class: " + ex.toString()); + } + workDone = new WeakHashMap(); + workInProgress = new HashMap(); + } + + /** + * Returns an type. If the calling thread is currently doing an type of + * this class, an unfinished type is returned. + */ + ContainerType getType(Class cls) { + ContainerType ret; + synchronized (this) { + ret = lookupDone(cls); + if (ret != null) + return ret; + // is it work-in-progress? + Task inProgress = (Task)workInProgress.get(cls); + if (inProgress != null) { + if (inProgress.thread == Thread.currentThread()) + return inProgress.type; // return unfinished + // Do not wait for the other thread: We may deadlock + // Double work is better than deadlock... + } + ret = createTask(cls); + } + // Do the work + parse(cls, ret); + // We did it + synchronized (this) { + workInProgress.remove(cls); + workDone.put(cls, new SoftReference(ret)); + notifyAll(); + } + return ret; + } + + /** + * Lookup an type in the fully done map. + */ + private ContainerType lookupDone(Class cls) { + SoftReference ref = (SoftReference)workDone.get(cls); + if (ref == null) + return null; + ContainerType ret = (ContainerType)ref.get(); + if (ret == null) + workDone.remove(cls); // clear map entry if soft ref. was + // cleared. + return ret; + } + + /** + * Create new work-in-progress. + */ + private ContainerType createTask(Class cls) { + try { + ContainerType type = (ContainerType)constructor.newInstance(new Object[] {cls}); + workInProgress.put(cls, new Task(type, Thread.currentThread())); + return type; + } catch (Exception ex) { + // Ignore it + return null; + } + } + + private void parse(Class cls, ContainerType ret) { + try { + ret.parse(); + } finally { + synchronized (this) { + workInProgress.remove(cls); + } + } + } + + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/ExceptionType.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/ExceptionType.java new file mode 100644 index 0000000000..d3b47802cb --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/ExceptionType.java @@ -0,0 +1,73 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.ejb.java2idl; + +import java.util.StringTokenizer; + +/** + * IDL Exception + */ +public class ExceptionType extends ValueType { + + private static WorkCache cache = new WorkCache(ExceptionType.class); + + private String repositoryId; + + public static ExceptionType getExceptionType(Class cls) { + return (ExceptionType)cache.getType(cls); + } + + protected ExceptionType(Class cls) { + super(cls); + } + + protected void parse() { + super.parse(); + if (!Exception.class.isAssignableFrom(javaClass) || RuntimeException.class.isAssignableFrom(javaClass)) + throw new IDLViolationException("Exception type " + javaClass.getName() + " must be a checked exception.", + "1.2.6"); + // calculate exceptionRepositoryId + StringBuffer b = new StringBuffer("IDL:"); + String base = javaClass.getName(); + if (base.endsWith("Exception")) + base = base.substring(0, base.length() - 9); + StringTokenizer tokenizer = new StringTokenizer(base, "."); + while (tokenizer.hasMoreTokens()) { + String token = tokenizer.nextToken(); + if (tokenizer.hasMoreTokens()) { + // Defect 281395 + b.append(IDLUtil.javaToIDLName(token)); + b.append('/'); + } else { + b.append(IDLUtil.javaToIDLName(token + "Ex")); + } + } + b.append(":1.0"); + repositoryId = b.toString(); + } + + /** + * Return the repository ID for the mapping of this analysis to an + * exception. + */ + public String getExceptionRepositoryId() { + return repositoryId; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/IDLType.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/IDLType.java new file mode 100644 index 0000000000..eae70245ca --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/IDLType.java @@ -0,0 +1,65 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.ejb.java2idl; + +/** + * Abstract base class for all IDL types. + */ +abstract class IDLType { + + /** + * Unqualified IDL name. + */ + protected String idlName; + /** + * Unqualified java name. + */ + protected String javaName; + + IDLType(String idlName, String javaName) { + this.idlName = idlName; + this.javaName = javaName; + } + + IDLType(String javaName) { + this(IDLUtil.javaToIDLName(javaName), javaName); + } + + /** + * Return my unqualified IDL name. + */ + public String getIDLName() { + return idlName; + } + + /** + * Return unqualified java name. + */ + public String getJavaName() { + return javaName; + } + + /** + * Set unqualified IDL name. + */ + void setIDLName(String idlName) { + this.idlName = idlName; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/IDLUtil.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/IDLUtil.java new file mode 100644 index 0000000000..fe8698122c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/IDLUtil.java @@ -0,0 +1,464 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.ejb.java2idl; + +import java.io.ByteArrayOutputStream; +import java.io.DataOutputStream; +import java.io.Externalizable; +import java.io.IOException; +import java.io.ObjectOutputStream; +import java.io.ObjectStreamClass; +import java.io.Serializable; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.rmi.Remote; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Map; +import java.util.Set; +import java.util.SortedSet; +import java.util.TreeSet; +import java.util.WeakHashMap; + +import org.omg.CORBA.Any; + +/** + * This is a RMI/IIOP metadata conversion utility class. + */ +public class IDLUtil { + + /** + * Return the IDL type name for the given class. Here we use the mapping for + * parameter types and return values. + */ + public static String getTypeIDLName(Class cls) { + if (cls.isPrimitive()) + return PrimitiveType.getPrimitiveType(cls).getIDLName(); + if (cls.isArray()) { + int dimension = 0; + Class type = cls; + while (type.isArray()) { + dimension++; + type = type.getComponentType(); + } + String baseName = getTypeIDLName(type); + int index = baseName.lastIndexOf("::"); + String prefix = ""; + String suffix = baseName; + if (index != -1) { + prefix = baseName.substring(0, index); + suffix = baseName.substring(index + 2); + } + String name = "::org::omg::boxedRMI" + prefix + "::seq" + dimension + "_" + suffix; + return name; + } + + // special classes + if (cls == java.lang.String.class) + return "::CORBA::WStringValue"; + if (cls == java.lang.Object.class) + return "::java::lang::_Object"; + if (cls == java.lang.Class.class) + return "::javax::rmi::CORBA::ClassDesc"; + if (cls == java.io.Serializable.class) + return "::java::io::Serializable"; + if (cls == java.io.Externalizable.class) + return "::java::io::Externalizable"; + if (cls == java.rmi.Remote.class) + return "::java::rmi::Remote"; + if (cls == org.omg.CORBA.Object.class) + return "::CORBA::Object"; + // remote interface? + if (cls.isInterface() && java.rmi.Remote.class.isAssignableFrom(cls)) { + InterfaceType ia = InterfaceType.getInterfaceType(cls); + return ia.getIDLModuleName() + "::" + ia.getIDLName(); + } + // IDL interface? + if (cls.isInterface() && org.omg.CORBA.Object.class.isAssignableFrom(cls) + && org.omg.CORBA.portable.IDLEntity.class.isAssignableFrom(cls)) { + InterfaceType ia = InterfaceType.getInterfaceType(cls); + return ia.getIDLModuleName() + "::" + ia.getIDLName(); + } + // exception? + if (Throwable.class.isAssignableFrom(cls)) { + if (Exception.class.isAssignableFrom(cls) && !RuntimeException.class.isAssignableFrom(cls)) { + ExceptionType ea = ExceptionType.getExceptionType(cls); + return ea.getIDLModuleName() + "::" + ea.getIDLName(); + } + } + // got to be value + ValueType va = ValueType.getValueType(cls); + return va.getIDLModuleName() + "::" + va.getIDLName(); + } + + /** + * Check if this class is valid for RMI/IIOP mapping. This method will + * either throw an exception or return true. + */ + public static boolean isValidRMIIIOP(Class cls) { + if (cls.isPrimitive()) + return true; + if (cls.isArray()) + return isValidRMIIIOP(cls.getComponentType()); + // special interfaces + if (cls == Serializable.class || cls == Externalizable.class) + return true; + // interface? + if (cls.isInterface() && Remote.class.isAssignableFrom(cls)) { + InterfaceType.getInterfaceType(cls); + return true; + } + // exception? + if (Throwable.class.isAssignableFrom(cls)) { + if (Exception.class.isAssignableFrom(cls) && (!RuntimeException.class.isAssignableFrom(cls))) { + ExceptionType.getExceptionType(cls); + } + return true; + } + // special values + if (cls == Object.class || cls == String.class || cls == Class.class) + return true; + // got to be value + ValueType.getValueType(cls); + return true; + } + + /** + * Insert a java primitive into an Any. The primitive is assumed to be + * wrapped in one of the primitive wrapper classes. + */ + public static void insertAnyPrimitive(Any any, Object primitive) { + Class type = primitive.getClass(); + if (type == Boolean.class) + any.insert_boolean(((Boolean)primitive).booleanValue()); + else if (type == Character.class) + any.insert_wchar(((Character)primitive).charValue()); + else if (type == Byte.class) + any.insert_octet(((Byte)primitive).byteValue()); + else if (type == Short.class) + any.insert_short(((Short)primitive).shortValue()); + else if (type == Integer.class) + any.insert_long(((Integer)primitive).intValue()); + else if (type == Long.class) + any.insert_longlong(((Long)primitive).longValue()); + else if (type == Float.class) + any.insert_float(((Float)primitive).floatValue()); + else if (type == Double.class) + any.insert_double(((Double)primitive).doubleValue()); + else + throw new IllegalArgumentException(type.getName() + "is not a primitive type"); + } + + /** + * Map Java name to IDL name, as per sections 1.3.2.3, 1.3.2.4 and 1.3.2.2. + * This only works for a single name component, without a qualifying dot. + */ + public static String javaToIDLName(String name) { + if (name == null || "".equals(name)) + throw new IllegalArgumentException("Illegal name: " + name); + if (name.indexOf('.') != -1) + throw new IllegalArgumentException("Qualified name is not supported: " + name); + StringBuffer res = new StringBuffer(name.length()); + if (name.charAt(0) == '_') + res.append('J'); // 1.3.2.3 + for (int i = 0; i < name.length(); ++i) { + char c = name.charAt(i); + if (isLegalIDLIdentifierChar(c)) + res.append(c); + else + // 1.3.2.4 + res.append('U').append(toHexString((int)c)); + } + String s = res.toString(); + if (isReservedIDLKeyword(s)) + return "_" + s; + else + return s; + } + + /** + * Return the IR global ID of the given class or interface. This is + * described in section 1.3.5.7. + */ + public static String getIRIdentifier(Class cls) { + if (cls.isPrimitive()) + throw new IllegalArgumentException("Primitive type doesn't have IR IDs."); + String result = (String)classIRIdentifierCache.get(cls); + if (result != null) + return result; + String name = cls.getName(); + StringBuffer b = new StringBuffer("RMI:"); + for (int i = 0; i < name.length(); ++i) { + char c = name.charAt(i); + if (c < 256) + b.append(c); + else + b.append("\\U").append(toHexString((int)c)); + } + long clsHash = getClassHashCode(cls); + b.append(':').append(toHexString(clsHash)); + ObjectStreamClass osClass = ObjectStreamClass.lookup(cls); + if (osClass != null) { + long serialVersionUID = osClass.getSerialVersionUID(); + if (clsHash != serialVersionUID) + b.append(':').append(toHexString(serialVersionUID)); + } + result = b.toString(); + classIRIdentifierCache.put(cls, result); + return result; + } + + /** + * A cache for calculated class hash codes. + */ + private static Map classHashCodeCache = Collections.synchronizedMap(new WeakHashMap()); + /** + * A cache for class IR identifiers. + */ + private static Map classIRIdentifierCache = Collections.synchronizedMap(new WeakHashMap()); + /** + * Reserved IDL keywords. Section 1.3.2.2 says that Java identifiers with + * these names should have prepended an underscore. + */ + + private static final Set reservedIDLKeywordSet = new HashSet(); + static { + String[] reservedIDLKeywords = new String[] {"abstract", "any", "attribute", "boolean", "case", "char", + "const", "context", "custom", "default", "double", "exception", + "enum", "factory", "FALSE", "fixed", "float", "in", "inout", + "interface", "local", "long", "module", "native", "Object", + "octet", "oneway", "out", "private", "public", "raises", + "readonly", "sequence", "short", "string", "struct", "supports", + "switch", "TRUE", "truncatable", "typedef", "unsigned", "union", + "ValueBase", "valuetype", "void", "wchar", "wstring"}; + for (int i = 0; i < reservedIDLKeywords.length; i++) + reservedIDLKeywordSet.add(reservedIDLKeywords[i]); + } + + /** + * Convert an integer to a 16-digit hex string. + */ + private static String toHexString(int i) { + String s = Integer.toHexString(i).toUpperCase(); + if (s.length() < 8) + return "00000000".substring(8 - s.length()) + s; + else + return s; + } + + /** + * Convert a long to a 16-digit hex string. + */ + private static String toHexString(long l) { + String s = Long.toHexString(l).toUpperCase(); + if (s.length() < 16) + return "0000000000000000".substring(16 - s.length()) + s; + else + return s; + } + + /** + * Determine if the argument is a reserved IDL keyword. + */ + private static boolean isReservedIDLKeyword(String s) { + return reservedIDLKeywordSet.contains(s); + /* + * // TODO: faster lookup for (int i = 0; i < + * reservedIDLKeywords.length; ++i) if + * (reservedIDLKeywords[i].equals(s)) return true; return false; + */ + } + + /** + * Determine if a char is a legal IDL identifier character. + */ + private static boolean isLegalIDLIdentifierChar(char c) { + if (c >= 0x61 && c <= 0x7a) + return true; // lower case letter + if (c >= 0x30 && c <= 0x39) + return true; // digit + if (c >= 0x41 && c <= 0x5a) + return true; // upper case letter + if (c == '_') + return true; // underscore + return false; + } + + /** + * Return the class hash code, as specified in "The Common Object Request + * Broker: Architecture and Specification" (01-02-33), section 10.6.2. + */ + static long getClassHashCode(Class cls) { + // The simple cases + if (cls.isInterface()) + return 0; + if (!Serializable.class.isAssignableFrom(cls)) + return 0; + if (Externalizable.class.isAssignableFrom(cls)) + return 1; + // Try cache + Long l = (Long)classHashCodeCache.get(cls); + if (l != null) + return l.longValue(); + // Has to calculate the hash. + ByteArrayOutputStream baos = new ByteArrayOutputStream(256); + DataOutputStream dos = new DataOutputStream(baos); + // Step 1 + Class superClass = cls.getSuperclass(); + if (superClass != null && superClass != Object.class) { + try { + dos.writeLong(getClassHashCode(superClass)); + } catch (IOException ex) { + throw new RuntimeException("Unexpected IOException: " + ex); + } + } + // Step 2 + boolean hasWriteObject = false; + try { + Method m; + int mods; + m = cls.getDeclaredMethod("writeObject", new Class[] {ObjectOutputStream.class}); + mods = m.getModifiers(); + if (!Modifier.isPrivate(mods) && !Modifier.isStatic(mods)) + hasWriteObject = true; + } catch (NoSuchMethodException ex) { + // ignore + } + try { + dos.writeInt(hasWriteObject ? 2 : 1); + } catch (IOException ex) { + throw new RuntimeException("Unexpected IOException: " + ex); + } + // Step 3 + Field[] fields = cls.getDeclaredFields(); + SortedSet set = new TreeSet(new FieldComparator()); + for (int i = 0; i < fields.length; ++i) { + int mods = fields[i].getModifiers(); + if (!Modifier.isStatic(mods) && !Modifier.isTransient(mods)) + set.add(fields[i]); + } + Iterator iter = set.iterator(); + try { + while (iter.hasNext()) { + Field f = (Field)iter.next(); + dos.writeUTF(f.getName()); + dos.writeUTF(getSignature(f.getType())); + } + } catch (IOException ex) { + throw new RuntimeException("Unexpected IOException: " + ex); + } + // Convert to byte[] + try { + dos.flush(); + } catch (IOException ex) { + throw new RuntimeException("Unexpected IOException: " + ex); + } + byte[] bytes = baos.toByteArray(); + // Calculate SHA digest + MessageDigest digest; + try { + digest = MessageDigest.getInstance("SHA"); + } catch (NoSuchAlgorithmException ex) { + throw new RuntimeException("No SHA MEssageDigest: " + ex); + } + digest.update(bytes); + byte[] sha = digest.digest(); + // Calculate hash as per section 10.6.2 + long hash = 0; + for (int i = 0; i < Math.min(8, sha.length); i++) { + hash += (long)(sha[i] & 255) << (i * 8); + } + // Save in cache + classHashCodeCache.put(cls, new Long(hash)); + return hash; + } + + /** + * Calculate the signature of a class, according to the Java VM + * specification, section 4.3.2. + */ + private static String getSignature(Class cls) { + if (cls.isArray()) + return "[" + cls.getComponentType(); + if (cls.isPrimitive()) { + if (cls == Byte.TYPE) + return "B"; + if (cls == Character.TYPE) + return "C"; + if (cls == Double.TYPE) + return "D"; + if (cls == Float.TYPE) + return "F"; + if (cls == Integer.TYPE) + return "I"; + if (cls == Long.TYPE) + return "J"; + if (cls == Short.TYPE) + return "S"; + if (cls == Boolean.TYPE) + return "Z"; + throw new RuntimeException("Unknown primitive class."); + } + return "L" + cls.getName().replace('.', '/') + ";"; + } + + /** + * Handle mappings for primitive types, as per section 1.3.3. + */ + static String primitiveTypeIDLName(Class type) { + if (type == Void.TYPE) + return "void"; + if (type == Boolean.TYPE) + return "boolean"; + if (type == Character.TYPE) + return "wchar"; + if (type == Byte.TYPE) + return "octet"; + if (type == Short.TYPE) + return "short"; + if (type == Integer.TYPE) + return "long"; + if (type == Long.TYPE) + return "long long"; + if (type == Float.TYPE) + return "float"; + if (type == Double.TYPE) + return "double"; + throw new IllegalArgumentException(type + "is not a primitive type."); + } + + /** + * A Comparator for Fields, ordering the + * fields according to the lexicographic ordering of their Java names. + */ + private static class FieldComparator implements Comparator { + public int compare(Object o1, Object o2) { + if (o1 == o2) + return 0; + String n1 = ((Field)o1).getName(); + String n2 = ((Field)o2).getName(); + return n1.compareTo(n2); + } + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/IDLViolationException.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/IDLViolationException.java new file mode 100644 index 0000000000..712a284b09 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/IDLViolationException.java @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.ejb.java2idl; + +import org.osoa.sca.ServiceRuntimeException; + +/** + * Exception denoting an RMI/IIOP Java-To-IDL mapping spec violation. + */ +public class IDLViolationException extends ServiceRuntimeException { + + private static final long serialVersionUID = 3334304081465286631L; + + /** + * The section violated. + */ + private String section; + + public IDLViolationException(String msg) { + super(msg); + } + + public IDLViolationException(String msg, String section) { + this(msg); + this.section = section; + } + + /** + * Return the section violated. + */ + public String getSection() { + return section; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/InterfaceType.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/InterfaceType.java new file mode 100644 index 0000000000..6943eb7a6f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/InterfaceType.java @@ -0,0 +1,158 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.ejb.java2idl; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + +/** + * IDL Interface Routines here are conforming to the "Java(TM) Language to IDL + * Mapping Specification", version 1.1 (01-06-07). + */ +public class InterfaceType extends ContainerType { + + private boolean abstractInterface; + private String[] typeIDs; + + /** + * Map of IDL operation names to operation parses. + */ + private Map operationTypeMap; + + private static WorkCache cache = new WorkCache(InterfaceType.class); + + public static InterfaceType getInterfaceType(Class cls) { + return (InterfaceType)cache.getType(cls); + } + + protected InterfaceType(Class cls) { + super(cls); + } + + protected void parse() { + super.parse(); + if (!javaClass.isInterface()) + throw new IllegalArgumentException("Class [" + javaClass.getName() + "] is not an interface."); + abstractInterface = Java2IDLUtil.isAbstractInterface(javaClass); + calculateOperationTypeMap(); + calculateAllTypeIds(); + fixupCaseNames(); + } + + public boolean isAbstractInterface() { + return abstractInterface; + } + + private boolean isRemoteInterface() { + return (!abstractInterface); + } + + public String[] getTypeIDs() { + return (String[])typeIDs.clone(); + } + + /** + * Return a list of all the entries contained here. + * + * @param entries The list of entries contained here. Entries in this list + * are subclasses of AbstractType. + */ + protected ArrayList getContainedEntries() { + ArrayList ret = new ArrayList(constants.length + attributes.length + operations.length); + for (int i = 0; i < constants.length; ++i) + ret.add(constants[i]); + for (int i = 0; i < attributes.length; ++i) + ret.add(attributes[i]); + for (int i = 0; i < operations.length; ++i) + ret.add(operations[i]); + return ret; + } + + /** + * Analyse operations. This will fill in the operations + * array. + */ + protected void parseOperations() { + int operationCount = 0; + for (int i = 0; i < methods.length; ++i) + if ((m_flags[i] & (M_READ | M_WRITE | M_READONLY)) == 0) + ++operationCount; + operations = new OperationType[operationCount]; + operationCount = 0; + for (int i = 0; i < methods.length; ++i) { + if ((m_flags[i] & (M_READ | M_WRITE | M_READONLY)) == 0) { + operations[operationCount] = new OperationType(methods[i]); + ++operationCount; + } + } + } + + /** + * Calculate the map that maps IDL operation names to operation parses. + * Besides mapped operations, this map also contains the attribute accessor + * and mutator operations. + */ + protected void calculateOperationTypeMap() { + operationTypeMap = new HashMap(); + OperationType oa; + // Map the operations + for (int i = 0; i < operations.length; ++i) { + oa = operations[i]; + operationTypeMap.put(oa.getIDLName(), oa); + } + // Map the attributes + for (int i = 0; i < attributes.length; ++i) { + AttributeType attr = attributes[i]; + oa = attr.getReadOperationType(); + // Not having an accessor analysis means that + // the attribute is not in a remote interface + if (oa != null) { + operationTypeMap.put(oa.getIDLName(), oa); + oa = attr.getWriteOperationType(); + if (oa != null) + operationTypeMap.put(oa.getIDLName(), oa); + } + } + } + + /** + * Calculate the array containing all type ids of this interface, in the + * format that org.omg.CORBA.portable.Servant._all_interfaces() is expected + * to return. + */ + protected void calculateAllTypeIds() { + if (!isRemoteInterface()) { + typeIDs = new String[0]; + } else { + ArrayList a = new ArrayList(); + InterfaceType[] intfs = getInterfaces(); + for (int i = 0; i < intfs.length; ++i) { + String[] ss = intfs[i].getTypeIDs(); + for (int j = 0; j < ss.length; ++j) + if (!a.contains(ss[j])) + a.add(ss[j]); + } + typeIDs = new String[a.size() + 1]; + typeIDs[0] = getRepositoryId(); + for (int i = 1; i <= a.size(); ++i) + typeIDs[i] = (String)a.get(a.size() - i); + } + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/Java2IDL.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/Java2IDL.java new file mode 100644 index 0000000000..79cbce55b8 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/Java2IDL.java @@ -0,0 +1,51 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.ejb.java2idl; + +import java.util.HashMap; +import java.util.Map; + +/** + * Utility class responsible for Java To IDL Mapping + */ +public class Java2IDL { + + public static Map getIDLMapping(Class type) { + InterfaceType interfaceType = InterfaceType.getInterfaceType(type); + Map names = new HashMap(); + AttributeType[] attrs = interfaceType.getAttributes(); + for (int i = 0; i < attrs.length; i++) { + OperationType op = attrs[i].getReadOperationType(); + if (op != null) { + names.put(op.getMethod(), op); + } + op = attrs[i].getWriteOperationType(); + if (op != null) { + names.put(op.getMethod(), op); + } + } + OperationType[] ops = interfaceType.getOperations(); + for (int i = 0; i < ops.length; i++) { + names.put(ops[i].getMethod(), ops[i]); + } + // Generate the method _ids(), declared as abstract in ObjectImpl + interfaceType.getTypeIDs(); + return names; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/Java2IDLUtil.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/Java2IDLUtil.java new file mode 100644 index 0000000000..b50ec4a04b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/Java2IDLUtil.java @@ -0,0 +1,403 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.ejb.java2idl; + +import java.io.Serializable; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.rmi.Remote; +import java.rmi.RemoteException; + +/** + * Java to IDL Language Mapping Specificiation v1.3 (formal/03-09-04) IDL + * Utilities + */ +public class Java2IDLUtil { + + /* + * checks if the method includes java.rmi.RemoteException or its subclass in + * its throws clause. + */ + private static boolean throwsRemoteException(Method method) { + Class[] exTypes = method.getExceptionTypes(); + for (int i = 0; i < exTypes.length; ++i) { + if (RemoteException.class.isAssignableFrom(exTypes[i])) + return true; + } + return false; + } + + /* + * checks if the given class is declared as static (inner classes only) + */ + private static boolean isStatic(Class c) { + return (Modifier.isStatic(c.getModifiers())); + } + + /** + * 1.2.1 Overview of Conforming RMI/IDL Types A conforming RMI/IDL type is a + * Java type whose values may be transmitted across an RMI/IDL remote + * interface at run-time. A Java data type is a conforming RMI/IDL type if + * it is: one of the Java primitive types (see Section 1.2.2, "Primitive + * Types," on page 1-2). a conforming remote interface (as defined in + * Section 1.2.3, "RMI/IDL Remote Interfaces," on page 1-3). a conforming + * value type (as defined in Section 1.2.4, "RMI/IDL Value Types," on page + * 1-4). an array of conforming RMI/IDL types (see Section 1.2.5, "RMI/IDL + * Arrays," on page 1-5). a conforming exception type (see Section 1.2.6, + * "RMI/IDL Exception Types," on page 1-5). a conforming CORBA object + * reference type (see Section 1.2.7, "CORBA Object Reference Types," on + * page 1-6). a conforming IDL entity type (see Section 1.2.8, "IDL Entity + * Types," on page 1-6). + * + * @param type + * @return + */ + public static boolean isIDLType(Class type) { + /* + * Primitive types. Spec 28.2.2 + */ + if (isPrimitiveType(type)) + return true; + + /* + * Conforming array. Spec 28.2.5 + */ + if (isIDLArray(type)) + return true; + + /* + * Conforming CORBA reference type. Spec 28.2.7 + */ + if (isCORBAObjectType(type)) + return true; + + /* + * Conforming IDL Entity type. Spec 28.2.8 + */ + if (isEntityType(type)) + return true; + + /* + * Conforming remote interface. Spec 28.2.3 + */ + if (isRemoteInterface(type)) + return true; + + /* + * Conforming exception. Spec 28.2.6 + */ + if (isExceptionType(type)) + return true; + + /* + * Conforming value type. Spec 28.2.4 + */ + if (isValueType(type)) + return true; + + return false; + } + + /** + * Section 1.2.3 RMI/IDL Remote Interfaces + * + * @param type + * @return + */ + public static boolean isRemoteInterface(Class type) { + + /* + * The interface is or inherits from java.rmi.Remote either directly or + * indirectly. + */ + if (!Remote.class.isAssignableFrom(type)) + return false; + + /* + * All methods in the interface are defined to throw + * java.rmi.RemoteException or a superclass of java.rmi.RemoteException. + * Throughout this section, references to methods in the interface + * include methods in any inherited interfaces + */ + Method[] methods = type.getMethods(); + for (int i = 0; i < methods.length; i++) { + if (!throwsRemoteException(methods[i])) { + return false; + } + + /* + * All checked exception classes used in method declarations (other + * than java.rmi.RemoteException and its subclasses) are conforming + * RMI/IDL exception types (see Section 1.2.6, "RMI/IDL Exception + * Types," on page 1-5).1 + */ + Class[] exTypes = methods[i].getExceptionTypes(); + for (int j = 0; j < exTypes.length; j++) { + if (!isExceptionType(exTypes[j])) + return false; + } + } + + // TODO: Check method overloading from inherited interfaces + /* + * Method names may be overloaded. However, when an interface directly + * inherits from several base interfaces, it is forbidden for there to + * be method name conflicts between the inherited interfaces. This + * outlaws the case where an interface A defines a method "foo," an + * interface B also defines a method "foo," and an interface C tries to + * inherit from both A and B. + */ + + /* + * Constant definitions in the form of interface variables are + * permitted. The constant value must be a compile-time constant of one + * of the RMI/IDL primitive types or String. + */ + Field[] fields = type.getFields(); + for (int k = 0; k < fields.length; k++) { + Class fieldType = fields[k].getType(); + if (fieldType.isPrimitive() || fieldType == String.class) + continue; + return false; + } + return true; + } + + /** + * Section 1.3.11 + * + * @param type The java class + * @return true if it is an IDL abstract interface + */ + public static boolean isAbstractInterface(Class type) { + /* + * It must be a Java interface. + */ + if (!type.isInterface()) + return false; + + /* + * It must not be the interface of a CORBA object. + */ + if (org.omg.CORBA.Object.class.isAssignableFrom(type)) + return false; + + /* + * It must not extend java.rmi.Remote directly or indirectly. + */ + if (Remote.class.isAssignableFrom(type)) + return false; + + Method[] methods = type.getMethods(); + + for (int i = 0; i < methods.length; i++) { + /* + * All methods MUST throw java.rmi.RemoteException or a subclass. + */ + if (!throwsRemoteException(methods[i])) { + return false; + } + } + return true; + } + + /** + * 1.2.6 RMI/IDL Exception Types An RMI/IDL exception type is a checked + * exception class (as defined by the Java Language Specification). Since + * checked exception classes extend java.lang.Throwable, which implements + * java.io.Serializable, it is unnecessary for an RMI/IDL exception class to + * directly implement java.io.Serializable. + */ + public static boolean isExceptionType(Class type) { + + /* + * Is a checked exception + */ + if (!Throwable.class.isAssignableFrom(type)) + return false; + + if (Error.class.isAssignableFrom(type)) + return false; + + if (RuntimeException.class.isAssignableFrom(type)) + return false; + + /* + * meets the requirements for RMI/IDL value types defined in Section + * 1.2.4, "RMI/IDL Value Types," on page 1-4. + */ + if (!isValueType(type)) + return false; + + return true; + } + + /** + * 1.2.4 RMI/IDL Value Types An RMI/IDL value type represents a class whose + * values can be moved between systems. So rather than transmitting a + * reference between systems, the actual state of the object is transmitted + * between systems. This requires that the receiving system have an + * analogous class that can be used to hold the received value. Value types + * may be passed as arguments or results of remote methods, or as fields + * within other objects that are passed remotely. + */ + public static boolean isValueType(Class type) { + /* + * The class must implement the java.io.Serializable interface, either + * directly or indirectly, and must be serializable at run-time. It may + * serialize references to other RMI/IDL types, including value types + * and remote interfaces. + */ + if (!Serializable.class.isAssignableFrom(type)) + return false; + + /* + * A value type must not either directly or indirectly implement the + * java.rmi.Remote interface. (If this were allowed, then there would be + * potential confusion between value types and remote interface + * references.) + */ + if (Remote.class.isAssignableFrom(type)) + return false; + + /* + * It cannot be a CORBA object. + */ + if (org.omg.CORBA.Object.class.isAssignableFrom(type)) + return false; + + /* + * If the class is a non-static inner class, then its containing class + * must also be a conforming RMI/IDL value type. + */ + if ((type.getDeclaringClass() != null) && (!isStatic(type))) + if (!isValueType(type.getDeclaringClass())) + return false; + + return true; + } + + public static boolean isAbstractValueType(Class type) { + if (!type.isInterface()) + return false; + + if (org.omg.CORBA.Object.class.isAssignableFrom(type)) + return false; + + boolean cannotBeRemote = false; + boolean cannotBeAbstractInterface = false; + + if (java.rmi.Remote.class.isAssignableFrom(type)) { + cannotBeAbstractInterface = true; + } else { + cannotBeRemote = true; + } + + Method[] methods = type.getMethods(); + for (int i = 0; i < methods.length; i++) { + if (!throwsRemoteException(methods[i])) { + cannotBeAbstractInterface = true; + cannotBeRemote = true; + break; + } + + Class[] exTypes = methods[i].getExceptionTypes(); + for (int j = 0; j < exTypes.length; j++) { + if (!isExceptionType(exTypes[j])) { + cannotBeRemote = true; + break; + } + } + } + + if (!cannotBeRemote) { + Field[] fields = type.getFields(); + for (int k = 0; k < fields.length; k++) { + if (fields[k].getType().isPrimitive()) + continue; + if (fields[k].getType().equals(java.lang.String.class)) + continue; + cannotBeRemote = true; + break; + } + } + return cannotBeRemote && cannotBeAbstractInterface; + } + + /** + * 1.2.2 Primitive Types All the standard Java primitive types are supported + * as part of RMI/IDL. These are: void, boolean, byte, char, short, int, + * long, float, double + * + * @param type + * @return + */ + public static boolean isPrimitiveType(Class type) { + return (type != null && type.isPrimitive()); + } + + /** + * 1.2.7 CORBA Object Reference Types A conforming CORBA object reference + * type is either + *
    + *
  • the Java interface org.omg.CORBA.Object, or + *
  • a Java interface that extends org.omg.CORBA.Object directly or + * indirectly and conforms to the rules specified in the Java Language + * Mapping (i.e., could have been generated by applying the mapping to an + * OMG IDL definition). + *
+ */ + public static boolean isCORBAObjectType(Class type) { + if (type == org.omg.CORBA.Object.class) + return true; + if (type.isInterface() && org.omg.CORBA.Object.class.isAssignableFrom(type)) + return true; + return false; + } + + /** + * 1.2.8 IDL Entity Types A Java class is a conforming IDL entity type if it + * extends org.omg.CORBA.portable.IDLEntity and conforms to the rules + * specified in the Java Language Mapping (i.e., could have been generated + * by applying the mapping to an OMG IDL definition) and is not an OMG IDL + * user exception. + */ + public static boolean isEntityType(Class type) { + if (!org.omg.CORBA.portable.IDLEntity.class.isAssignableFrom(type)) + return false; + if (isExceptionType(type)) + return false; + return true; + } + + /** + * 1.2.5 RMI/IDL Arrays Arrays of any conforming RMI/IDL type are also + * conforming RMI/IDL types. So int[] and String[][][] are conforming + * RMI/IDL types. Similarly if Wombat is a conforming RMI/IDL interface + * type, then Wombat[] is a conforming RMI/IDL type. + */ + public static boolean isIDLArray(Class type) { + if (!type.isArray()) + return false; + Class componentType = type.getComponentType(); + return isIDLType(componentType); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/OperationType.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/OperationType.java new file mode 100644 index 0000000000..f10a66d72d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/OperationType.java @@ -0,0 +1,106 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.ejb.java2idl; + +import java.lang.reflect.Method; +import java.rmi.Remote; +import java.rmi.RemoteException; +import java.util.ArrayList; + +/** + * IDL Operation. + */ +public class OperationType extends IDLType { + + /** + * The Method that this OperationType is mapping. + */ + private Method method; + /** + * The mapped exceptions of this operation. + */ + private ExceptionType[] mappedExceptions; + /** + * The parameters of this operation. + */ + private ParameterType[] parameters; + + OperationType(Method method) { + super(method.getName()); + this.method = method; + // Check if valid return type, IF it is a remote interface. + Class retCls = method.getReturnType(); + if (retCls.isInterface() && Remote.class.isAssignableFrom(retCls)) + IDLUtil.isValidRMIIIOP(retCls); + // Analyze exceptions + Class[] ex = method.getExceptionTypes(); + boolean gotRemoteException = false; + ArrayList a = new ArrayList(); + for (int i = 0; i < ex.length; ++i) { + if (ex[i].isAssignableFrom(java.rmi.RemoteException.class)) + gotRemoteException = true; + if (Exception.class.isAssignableFrom(ex[i]) && !RuntimeException.class.isAssignableFrom(ex[i]) + && !RemoteException.class.isAssignableFrom(ex[i])) + a.add(ExceptionType.getExceptionType(ex[i])); // map this + } + if (!gotRemoteException && Remote.class.isAssignableFrom(method.getDeclaringClass())) + throw new IDLViolationException( + "All interface methods must throw java.rmi.RemoteException, " + "or a superclass of java.rmi.RemoteException, but method " + + getJavaName() + + " of interface " + + method.getDeclaringClass().getName() + + " does not.", "1.2.3"); + mappedExceptions = new ExceptionType[a.size()]; + mappedExceptions = (ExceptionType[])a.toArray(mappedExceptions); + // Analyze parameters + Class[] params = method.getParameterTypes(); + parameters = new ParameterType[params.length]; + for (int i = 0; i < params.length; ++i) { + parameters[i] = new ParameterType("param" + (i + 1), params[i]); + } + } + + /** + * Return my Java return type. + */ + public Class getReturnType() { + return method.getReturnType(); + } + + /** + * Return my mapped Method. + */ + public Method getMethod() { + return method; + } + + /** + * Return my mapped exceptions. + */ + public ExceptionType[] getMappedExceptions() { + return (ExceptionType[])mappedExceptions.clone(); + } + + /** + * Return my parameters. + */ + public ParameterType[] getParameters() { + return (ParameterType[])parameters.clone(); + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/ParameterType.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/ParameterType.java new file mode 100644 index 0000000000..09d48ad169 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/ParameterType.java @@ -0,0 +1,63 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.ejb.java2idl; + +import org.omg.CORBA.ParameterMode; + +/** + * IDL Parameter + */ +public class ParameterType extends IDLType { + + /** + * Java type of parameter. + */ + private Class javaClass; + /** + * IDL type name of parameter type. + */ + private String typeIDLName; + + ParameterType(String javaName, Class cls) { + super(javaName); + this.javaClass = cls; + this.typeIDLName = IDLUtil.getTypeIDLName(cls); + } + + /** + * Return the attribute mode. + */ + public ParameterMode getMode() { + return ParameterMode.PARAM_IN; + } + + /** + * Return the Java type. + */ + public Class getJavaClass() { + return javaClass; + } + + /** + * Return the IDL type name of the parameter type. + */ + public String getTypeIDLName() { + return typeIDLName; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/PrimitiveType.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/PrimitiveType.java new file mode 100644 index 0000000000..c48188112e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/PrimitiveType.java @@ -0,0 +1,66 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.ejb.java2idl; + +import java.util.HashMap; +import java.util.Map; + +/** + * Type class for primitive types. + */ +public class PrimitiveType extends ClassType { + + public final static PrimitiveType voidType = new PrimitiveType(void.class, "void", "void"); + public final static PrimitiveType booleanType = new PrimitiveType(boolean.class, "boolean", "boolean"); + public final static PrimitiveType charType = new PrimitiveType(char.class, "wchar", "char"); + public final static PrimitiveType byteType = new PrimitiveType(byte.class, "octet", "byte"); + public final static PrimitiveType shortType = new PrimitiveType(short.class, "short", "short"); + public final static PrimitiveType intType = new PrimitiveType(int.class, "long", "int"); + public final static PrimitiveType longType = new PrimitiveType(long.class, "long_long", "long"); + public final static PrimitiveType floatType = new PrimitiveType(float.class, "float", "float"); + public final static PrimitiveType doubleType = new PrimitiveType(double.class, "double", "double"); + + private final static Map types = new HashMap(); + static { + types.put(void.class, voidType); + types.put(boolean.class, booleanType); + types.put(byte.class, byteType); + types.put(char.class, charType); + types.put(short.class, shortType); + types.put(int.class, intType); + types.put(long.class, longType); + types.put(float.class, floatType); + types.put(double.class, doubleType); + } + + private PrimitiveType(Class cls, String idlName, String javaName) { + super(cls, idlName, javaName); + } + + /** + * Get a singleton instance representing one of the peimitive types. + */ + public final static PrimitiveType getPrimitiveType(Class cls) { + PrimitiveType type = (PrimitiveType)types.get(cls); + if (type == null) + throw new IllegalArgumentException(cls + " is not a primitive type"); + return type; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/ValueMemberType.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/ValueMemberType.java new file mode 100644 index 0000000000..3e152301a7 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/ValueMemberType.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.ejb.java2idl; + +/** + * Value member type. + */ +public class ValueMemberType extends IDLType { + + /** + * Java type. + */ + private Class javaClass; + /** + * Flags that this member is public. + */ + private boolean isPublic; + + ValueMemberType(String javaName, Class cls, boolean isPublic) { + super(javaName); + this.javaClass = cls; + this.isPublic = isPublic; + } + + /** + * Return my Java type. + */ + public Class getJavaClass() { + return javaClass; + } + + /** + * Returns true iff this member has private visibility. + */ + public boolean isPublic() { + return isPublic; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/ValueType.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/ValueType.java new file mode 100644 index 0000000000..3d2c8935cf --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/java2idl/ValueType.java @@ -0,0 +1,271 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.ejb.java2idl; + +import java.io.Externalizable; +import java.io.ObjectStreamField; +import java.io.Serializable; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.rmi.Remote; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.SortedSet; +import java.util.TreeSet; + +import org.osoa.sca.ServiceRuntimeException; + +/** + * Value Type. + */ +public class ValueType extends ContainerType { + + private static WorkCache cache = new WorkCache(ValueType.class); + + /** + * Type of our superclass, of null if our superclass is java.lang.Object. + */ + ValueType superType; + /** + * Flags that this is an abstract value. + */ + private boolean abstractValue = false; + /** + * Flags that this implements java.io.Externalizable. + */ + private boolean externalizable = false; + /** + * Flags that this has a writeObject() method. + */ + private boolean hasWriteObjectMethod = false; + /** + * The serialPersistentFields of the value, or null + * if the value does not have this field. + */ + private ObjectStreamField[] serialPersistentFields; + /** + * The value members of this value class. + */ + private ValueMemberType[] members; + + public static ValueType getValueType(Class cls) { + return (ValueType)cache.getType(cls); + } + + protected ValueType(Class cls) { + super(cls); + } + + protected void parse() { + super.parse(); + if (javaClass == String.class) + throw new IllegalArgumentException("Cannot parse java.lang.String here: It is a " + "special case."); // 1.3.5.11 + if (javaClass == Class.class) + throw new IllegalArgumentException("Cannot parse java.lang.Class here: It is a " + "special case."); // 1.3.5.10 + if (Remote.class.isAssignableFrom(javaClass)) + throw new IDLViolationException("Value type " + javaClass.getName() + " cannot implement java.rmi.Remote.", + "1.2.4"); + if (javaClass.getName().indexOf('$') != -1) + throw new ServiceRuntimeException(javaClass.getName() + " is not supported (proxy or inner classes)."); + externalizable = Externalizable.class.isAssignableFrom(javaClass); + if (!externalizable) { + // Look for serialPersistentFields field. + Field spf = null; + try { + spf = javaClass.getField("serialPersistentFields"); + } catch (NoSuchFieldException ex) { + // ignore + } + if (spf != null) { // Right modifiers? + int mods = spf.getModifiers(); + if (!Modifier.isFinal(mods) || !Modifier.isStatic(mods) || !Modifier.isPrivate(mods)) + spf = null; // wrong modifiers + } + if (spf != null) { // Right type? + Class type = spf.getType(); + if (type.isArray()) { + type = type.getComponentType(); + if (type != ObjectStreamField.class) + spf = null; // Array of wrong type + } else + spf = null; // Wrong type: Not an array + } + if (spf != null) { + // We have the serialPersistentFields field + // Get this constant + try { + serialPersistentFields = (ObjectStreamField[])spf.get(null); + } catch (IllegalAccessException ex) { + throw new RuntimeException("Unexpected IllegalException: " + ex.toString()); + } + // Mark this in the fields array + for (int i = 0; i < fields.length; ++i) { + if (fields[i] == spf) { + f_flags[i] |= F_SPFFIELD; + break; + } + } + } + // Look for a writeObject Method + Method wo = null; + try { + wo = javaClass.getMethod("writeObject", new Class[] {java.io.OutputStream[].class}); + } catch (NoSuchMethodException ex) { + // ignore + } + if (wo != null) { // Right return type? + if (wo.getReturnType() != Void.TYPE) + wo = null; // Wrong return type + } + if (wo != null) { // Right modifiers? + int mods = spf.getModifiers(); + if (!Modifier.isPrivate(mods)) + wo = null; // wrong modifiers + } + if (wo != null) { // Right arguments? + Class[] paramTypes = wo.getParameterTypes(); + if (paramTypes.length != 1) + wo = null; // Bad number of parameters + else if (paramTypes[0] != java.io.OutputStream.class) + wo = null; // Bad parameter type + } + if (wo != null) { + // We have the writeObject() method. + hasWriteObjectMethod = true; + // Mark this in the methods array + for (int i = 0; i < methods.length; ++i) { + if (methods[i] == wo) { + m_flags[i] |= M_WRITEOBJECT; + break; + } + } + } + } + // Map all fields not flagged constant or serialPersistentField. + SortedSet m = new TreeSet(new ValueMemberComparator()); + for (int i = 0; i < fields.length; ++i) { + if (f_flags[i] != 0) + continue; // flagged + int mods = fields[i].getModifiers(); + if (Modifier.isStatic(mods) || Modifier.isTransient(mods)) + continue; // don't map this + ValueMemberType vma = + new ValueMemberType(fields[i].getName(), fields[i].getType(), Modifier.isPublic(mods)); + m.add(vma); + } + members = new ValueMemberType[m.size()]; + members = (ValueMemberType[])m.toArray(members); + // Get superclass analysis + Class superClass = javaClass.getSuperclass(); + if (superClass == java.lang.Object.class) + superClass = null; + if (superClass == null) + superType = null; + else { + superType = getValueType(superClass); + } + if (!Serializable.class.isAssignableFrom(javaClass)) + abstractValue = true; + fixupCaseNames(); + } + + /** + * Returns the superclass analysis, or null if this inherits from + * java.lang.Object. + */ + public ValueType getSuperType() { + return superType; + } + + /** + * Returns true if this value is abstract. + */ + public boolean isAbstractValue() { + return abstractValue; + } + + /** + * Returns true if this value is custom. + */ + public boolean isCustom() { + return externalizable || hasWriteObjectMethod; + } + + /** + * Returns true if this value implements java.io.Externalizable. + */ + public boolean isExternalizable() { + return externalizable; + } + + /** + * Return the value members of this value class. + */ + public ValueMemberType[] getMembers() { + return (ValueMemberType[])members.clone(); + } + + /** + * Analyse attributes. This will fill in the attributes + * array. Here we override the implementation in ContainerType and create an + * empty array, because for valuetypes we don't want to parse IDL attributes + * or operations (as in "rmic -idl -noValueMethods"). + */ + protected void parseAttributes() { + attributes = new AttributeType[0]; + } + + /** + * Return a list of all the entries contained here. + * + * @param entries The list of entries contained here. Entries in this list + * are subclasses of AbstractType. + */ + protected ArrayList getContainedEntries() { + ArrayList ret = new ArrayList(constants.length + attributes.length + members.length); + for (int i = 0; i < constants.length; ++i) + ret.add(constants[i]); + for (int i = 0; i < attributes.length; ++i) + ret.add(attributes[i]); + for (int i = 0; i < members.length; ++i) + ret.add(members[i]); + return ret; + } + + /** + * A Comparator for the field ordering specified at the end + * of section 1.3.5.6. + */ + private static class ValueMemberComparator implements Comparator { + public int compare(Object o1, Object o2) { + if (o1 == o2) + return 0; + ValueMemberType m1 = (ValueMemberType)o1; + ValueMemberType m2 = (ValueMemberType)o2; + boolean p1 = m1.getJavaClass().isPrimitive(); + boolean p2 = m2.getJavaClass().isPrimitive(); + if (p1 && !p2) + return -1; + if (!p1 && p2) + return 1; + return m1.getJavaName().compareTo(m2.getJavaName()); + } + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/util/EJBHandler.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/util/EJBHandler.java new file mode 100644 index 0000000000..8d0d309aef --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/util/EJBHandler.java @@ -0,0 +1,420 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.ejb.util; + +import java.io.Externalizable; +import java.io.Serializable; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.rmi.RemoteException; +import java.rmi.UnexpectedException; +import java.security.AccessController; +import java.security.PrivilegedAction; +import java.util.HashMap; +import java.util.Map; + +import javax.ejb.EJBObject; +import javax.rmi.CORBA.Util; + +import org.apache.tuscany.sca.binding.ejb.java2idl.ExceptionType; +import org.apache.tuscany.sca.binding.ejb.java2idl.Java2IDLUtil; +import org.omg.CORBA.ORB; +import org.omg.CORBA.SystemException; +import org.omg.CORBA.portable.ApplicationException; +import org.omg.CORBA.portable.ObjectImpl; +import org.omg.CORBA.portable.RemarshalException; +import org.omg.CORBA.portable.ServantObject; +import org.omg.CORBA_2_3.portable.InputStream; +import org.omg.CORBA_2_3.portable.OutputStream; +import org.osoa.sca.ServiceRuntimeException; + +/** + * EJBMessageHandler + */ +public class EJBHandler { + private Object ejbStub; + + private InterfaceInfo interfaceInfo; + private Class ejbInterface; + + public EJBHandler(NamingEndpoint namingEndpoint, Class ejbInterface) { + this(namingEndpoint, InterfaceInfo.getInstance(ejbInterface)); + this.ejbInterface = ejbInterface; + } + + // locates the stub + public EJBHandler(NamingEndpoint namingEndpoint, InterfaceInfo ejbInterface) { + try { + this.ejbStub = EJBStubHelper.lookup(namingEndpoint); + this.interfaceInfo = ejbInterface; + } catch (Exception e) { + Throwable b = e.getCause(); + b.printStackTrace(); + throw new ServiceRuntimeException(e); + } + } + + private final static Map primitiveClasses = new HashMap(); + static { + primitiveClasses.put("boolean", boolean.class); + primitiveClasses.put("byte", byte.class); + primitiveClasses.put("char", char.class); + primitiveClasses.put("short", short.class); + primitiveClasses.put("int", int.class); + primitiveClasses.put("long", long.class); + primitiveClasses.put("float", float.class); + primitiveClasses.put("double", double.class); + primitiveClasses.put("void", void.class); + } + + private static Class loadClass(final String name) { + Class type = (Class)primitiveClasses.get(name); + if (type != null) + return type; + return (Class)AccessController.doPrivileged(new PrivilegedAction() { + public Class run() { + try { + ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); + return Class.forName(name, true, classLoader); + } catch (ClassNotFoundException e) { + return null; + } + } + }); + } + + // invokes EJB method + public Object invoke(String methodName, Object[] args) { + Object response = null; + try { + if (ejbStub instanceof ObjectImpl) { + ObjectImpl objectImpl = (ObjectImpl)ejbStub; + // TODO: If the Java 2 security is turned on, then + // the ORB will try to create proxy + // from the interfaces defined on the stub + if (System.getSecurityManager() == null && objectImpl._is_local()) { + /* + * CORBA.Stub is what the object from JNDI will be for a + * remote EJB in the same JVM as the client, but with no + * stub classes available on the client + */ + response = invokeLocalCORBACall(objectImpl, methodName, args); + } else { + /* + * _EJBObject_Stub is what the object from JNDI will be for + * a remote EJB with no stub classes available on the client + */ + response = invokeRemoteCORBACall(objectImpl, methodName, args); + } + } else { + /* + * A generated ejb stub or it must be an EJB in the same ear as + * the client or an AppServer with a single classloader, so + * reflection can be used directly on the JNDI + */ + JavaReflectionAdapter reflectionAdapter = + JavaReflectionAdapter.createJavaReflectionAdapter(ejbStub.getClass()); + try { + Method method = reflectionAdapter.getMethod(methodName); + response = method.invoke(ejbStub, args); + } catch (InvocationTargetException e) { + Throwable t = e.getTargetException(); + // FIXME need to throw really a business exception. + // ServiceBusinessException? + // Tuscany core doesn't have ServiceBusinessException + throw new ServiceRuntimeException(t); + } + } + + return response; + } catch (Exception e) { + // FIXME this be business exception? Tuscany core doesn't have + // ServiceBusinessException + throw new ServiceRuntimeException(e); + + } catch (Throwable e) { + throw new ServiceRuntimeException(e); + } + } + + /** + * Get the IDL operation name for a java method + * + * @param methodName java method name + * @return The IDL operation name + */ + private String getOperation(String methodName) { + if (interfaceInfo == null) + return methodName; + MethodInfo methodInfo = interfaceInfo.getMethod(methodName); + if (methodInfo != null) + return methodInfo.getIDLName(); + else + return null; + } + + /* + * Derive the EJB interface name from the Stub When loading a stub class + * corresponding to an interface or class ., the + * class .__Stub shall be used if it exists; + * otherwise, the class org.omg.stub..__Stub shall + * be used. + */ + private static String getInterface(String stubName) { + int index = stubName.lastIndexOf('.'); + String packageName = null; + String typeName = stubName; + if (index != -1) { + packageName = stubName.substring(0, index); + if (packageName.startsWith("org.omg.stub.")) { + packageName = packageName.substring("org.omg.stub.".length()); + } + typeName = stubName.substring(index + 1); + } + if (typeName.startsWith("_") && typeName.endsWith("_Stub")) { + typeName = typeName.substring(1, typeName.length() - "_Stub".length()); + } + if (packageName != null) + return packageName + "." + typeName; + else + return typeName; + } + + /** + * Invoke a method on the local CORBA object + * + * @param stub + * @param methodName + * @param args + * @return + * @throws RemoteException + * @throws ServiceBusinessException + */ + protected Object invokeLocalCORBACall(final ObjectImpl stub, String methodName, Object[] args) + throws RemoteException { + + final String operation = getOperation(methodName); + + Class type = loadClass(getInterface(stub.getClass().getName())); + if (type == null) + type = (ejbInterface != null) ? ejbInterface : EJBObject.class; + + ServantObject so = stub._servant_preinvoke(operation, type); + if (so == null) { + // The Servant is not local any more + return invokeRemoteCORBACall(stub, methodName, args); + } + Object[] newArgs = null; + ORB orb = stub._orb(); + try { + if (args != null) + newArgs = Util.copyObjects(args, orb); + JavaReflectionAdapter reflectionAdapter = + JavaReflectionAdapter.createJavaReflectionAdapter(so.servant.getClass()); + Method method = reflectionAdapter.getMethod(methodName); + Object obj = reflectionAdapter.invoke(method, so.servant, newArgs); + Object result = Util.copyObject(obj, orb); + return result; + + } catch (InvocationTargetException e) { + Throwable exCopy = (Throwable)Util.copyObject(e.getTargetException(), orb); + MethodInfo methodInfo = interfaceInfo.getMethod(methodName); + String[] exceptionTypes = methodInfo.getExceptionTypes(); + for (int i = 0; i < exceptionTypes.length; i++) { + Class exceptionType = loadClass(exceptionTypes[i]); + if (exceptionType.isAssignableFrom(exCopy.getClass())) + throw new ServiceRuntimeException(exCopy); // FIXME should + // be business + // exception? + } + throw Util.wrapException(exCopy); + } catch (Throwable e) { + // Other exceptions thrown from "invoke" + throw new ServiceRuntimeException(e); + } finally { + stub._servant_postinvoke(so); + } + } + + /** + * Invoke a method on a remote CORBA object + * + * @param stub The remote stub + * @param methodName The name of the method + * @param args Argument list + * @return + * @throws RemoteException + * @throws ServiceBusinessException + */ + protected Object invokeRemoteCORBACall(ObjectImpl stub, String methodName, Object[] args) throws RemoteException { + + try { + String operation = getOperation(methodName); + + MethodInfo methodInfo = interfaceInfo.getMethod(methodName); + if (methodInfo == null) { + throw new ServiceRuntimeException("Invalid Method " + methodName); + } + String[] types = methodInfo.getParameterTypes(); + if (args != null) { + if (types.length != args.length) + throw new ServiceRuntimeException( + "The argument list doesn't match the method signature of " + methodName); + } + + Class[] parameterTypes = new Class[types.length]; + for (int i = 0; i < types.length; i++) { + parameterTypes[i] = loadClass(types[i]); + } + Class returnType = loadClass(methodInfo.getReturnType()); + + InputStream in = null; + try { + OutputStream out = (OutputStream)stub._request(operation, true); + + for (int i = 0; i < types.length; i++) { + // Object arg = (args.length < i) ? null : args[i]; + writeValue(out, args[i], parameterTypes[i]); + } + if (returnType == void.class) { + // void return + stub._invoke(out); + return null; + } else { + // read the return value + in = (InputStream)stub._invoke(out); + Object response = readValue(in, returnType); + return response; + } + + } catch (ApplicationException ex) { + in = (InputStream)ex.getInputStream(); + String id = in.read_string(); + // Check if the id matches to any declared exceptions for the + // method + String[] exceptionTypes = methodInfo.getExceptionTypes(); + for (int i = 0; i < exceptionTypes.length; i++) { + Class exceptionType = loadClass(exceptionTypes[i]); + String exceptionId = ExceptionType.getExceptionType(exceptionType).getExceptionRepositoryId(); + if (id.equals(exceptionId)) { + Throwable t = (Throwable)in.read_value(exceptionType); + throw new ServiceRuntimeException(t); // FIXME should + // be + // ServcieBusinessException? + // no support by + // Tuscany core + // for + // ServcieBusinessException. + } + } + throw new UnexpectedException(id); + } catch (RemarshalException ex) { + return invokeRemoteCORBACall(stub, methodName, args); + } finally { + stub._releaseReply(in); + } + } catch (SystemException ex) { + throw Util.mapSystemException(ex); + } + } + + /** + * @param out + * @param value + * @param type + */ + protected void writeValue(OutputStream out, Object value, Class type) { + if (type == null) + out.write_value((Serializable)value); + else if (type == Object.class || type == Serializable.class || type == Externalizable.class) { + // Any + Util.writeAny(out, value); + } else if (type == Integer.TYPE) { + // java int maps to CORBA long + out.write_long(((Integer)value).intValue()); + } else if (type == Short.TYPE) { + out.write_short(((Short)value).shortValue()); + } else if (type == Boolean.TYPE) { + out.write_boolean(((Boolean)value).booleanValue()); + } else if (type == Byte.TYPE) { + out.write_octet(((Byte)value).byteValue()); + } else if (type == Long.TYPE) { + out.write_longlong(((Long)value).longValue()); + } else if (type == Double.TYPE) { + out.write_double(((Double)value).doubleValue()); + } else if (type == Float.TYPE) { + out.write_float(((Float)value).floatValue()); + } else if (type == Character.TYPE) { + out.write_wchar(((Character)value).charValue()); + } else if (type.isArray()) { + out.write_value((Serializable)value, type); + } else if (Java2IDLUtil.isRemoteInterface(type)) { + // Remote interface + Util.writeRemoteObject(out, value); + } else if (Java2IDLUtil.isAbstractInterface(type)) { + // Non-remote Interface + Util.writeAbstractObject(out, value); + } else { + out.write_value((Serializable)value, type); + } + } + + /** + * @param in + * @param type + * @return + */ + protected Object readValue(InputStream in, Class type) { + Object value = null; + if (type == null) + value = in.read_value(); + else if (type == Object.class || type == Serializable.class || type == Externalizable.class) { + value = Util.readAny(in); + } else if (type == Integer.TYPE) { + value = new Integer(in.read_long()); + } else if (type == Short.TYPE) { + value = new Short(in.read_short()); + } else if (type == Boolean.TYPE) { + value = new Boolean(in.read_boolean()); + } else if (type == Byte.TYPE) { + value = new Byte(in.read_octet()); + } else if (type == Long.TYPE) { + value = new Long(in.read_longlong()); + } else if (type == Float.TYPE) { + value = new Float(in.read_float()); + } else if (type == Double.TYPE) { + value = new Double(in.read_double()); + } else if (type == Character.TYPE) { + value = new Character(in.read_wchar()); + } else if (type.isArray()) { + // [] + value = in.read_value(type); + } else if (Java2IDLUtil.isRemoteInterface(type)) { + // java.rmi.Remote + value = in.read_Object(type); + } else if (Java2IDLUtil.isAbstractInterface(type)) { + // Non-remote Interface + value = in.read_abstract_interface(type); + } else { + // java.io.Serializable + value = in.read_value(type); + } + return value; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/util/EJBLocator.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/util/EJBLocator.java new file mode 100644 index 0000000000..1369b92715 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/util/EJBLocator.java @@ -0,0 +1,511 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.ejb.util; + +import java.net.URL; +import java.security.AccessController; +import java.security.PrivilegedAction; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Properties; +import java.util.Set; + +import javax.naming.Context; +import javax.naming.InitialContext; +import javax.naming.InvalidNameException; +import javax.naming.NamingException; + +import org.omg.CORBA.ORB; +import org.omg.CORBA.ORBPackage.InvalidName; +import org.omg.CosNaming.NamingContextExt; +import org.omg.CosNaming.NamingContextExtHelper; + +/** + * CosNaming utility + */ +public class EJBLocator { + + /* + * Root Context Initial Reference Key ------------ + * ----------------------------------- Server Root NameServiceServerRoot + * Cell Persistent Root NameServiceCellPersistentRoot Cell Root + * NameServiceCellRoot, NameService Node Root NameServiceNodeRoot + */ + public static final String SERVER_ROOT = "NameServiceServerRoot"; + public static final String CELL_PERSISTENT_ROOT = "NameServiceCellPersistentRoot"; + public static final String CELL_ROOT = "NameServiceCellRoot"; + public static final String NODE_ROOT = "NameServiceNodeRoot"; + public static final String DEFAULT_ROOT = "NameService"; // Same as + // CELL_ROOT + + private static final Set ROOTS = new HashSet(Arrays.asList(new String[] {SERVER_ROOT, CELL_PERSISTENT_ROOT, + CELL_ROOT, DEFAULT_ROOT, NODE_ROOT})); + + public static final String DEFAULT_HOST = "127.0.0.1"; // Default host name + // or IP address for + // Websphere + public static final int DEFAULT_NAMING_PORT = 2809; // Default port + public static final String NAMING_SERVICE = "NameService"; // The name of + // the naming + // service + + // private static final String CHARS_TO_ESCAPE = "\\/."; + private static final String RFC2396 = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789;/:?@&=+$,-_.!~*'()"; + private static final String HEX = "0123456789ABCDEF"; + + private String hostName = DEFAULT_HOST; + private int port = DEFAULT_NAMING_PORT; + private String root = SERVER_ROOT; + + private ORB orb = null; + private ObjectLocator locator = null; + boolean managed = true; + + public EJBLocator(boolean managed) { + this.managed = managed; + if (!managed) { + String url = (String)AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + return System.getProperty(Context.PROVIDER_URL); + } + }); + processCorbaURL(url); + } + } + + private void processCorbaURL(String url) { + if (url != null && (url.startsWith("corbaname:iiop:") || url.startsWith("corbaloc:iiop:"))) { + /** + * corbaname:iiop::/#name corbaloc:iiop::/ + * For exmaple, + * "corbaname:iiop:localhost:2809/NameServiceServerRoot#ejb/MyEJBHome"; + * or "corbaloc:iiop:myhost:2809/NameServiceServerRoot" + */ + String[] parts = url.split("(:|/|#)"); + if (parts.length > 2 && parts[2].length() > 0) { + hostName = parts[2]; // The host name + int index = hostName.lastIndexOf('@'); // version@hostname + if (index != -1) + hostName = hostName.substring(index + 1); + } + if (parts.length > 3 && parts[3].length() > 0) + port = Integer.parseInt(parts[3]); // The port number + if (parts.length > 4 && parts[4].length() > 0) + root = parts[4]; // The root of naming + } + } + + public EJBLocator(String hostName, int port) { + this.hostName = (hostName == null) ? DEFAULT_HOST : hostName; + this.port = port > 0 ? port : DEFAULT_NAMING_PORT; + this.root = SERVER_ROOT; + } + + public EJBLocator(String hostName, int port, String root) { + this(hostName, port); + if (ROOTS.contains(root)) + this.root = root; + else + throw new IllegalArgumentException(root + " is not a legal root"); + } + + public EJBLocator(String corbaName, boolean managed) { + this.managed = managed; + if (corbaName.startsWith("corbaname:iiop:")) { + processCorbaURL(corbaName); + } else + throw new IllegalArgumentException(corbaName + " is not a legal corbaname"); + } + + /** + * The corbaloc and corbaname formats enable you to provide a URL to access + * CORBA objects. Use the corbaloc format for resolving to a particular + * CORBAservice without going through a naming service. Use the corbaname + * format to resolve a stringified name from a specific naming context. + */ + + /** + * Compose a corbaloc URI + * + * @param hostName + * @param port + * @param service + * @return + */ + private static String getCorbaloc(String hostName, int port, String service) { + if (service == null) + return "corbaloc:iiop:" + hostName + ":" + port; + else + return "corbaloc:iiop:" + hostName + ":" + port + "/" + service; + } + + private String getCorbaloc(String service) { + return getCorbaloc(hostName, port, service); + } + + /** + * corbaname Syntax The full corbaname BNF is: <corbaname> = + * "corbaname:"<corbaloc_obj>["#"<string_name>] + * <corbaloc_obj> = <obj_addr_list> ["/"<key_string>] + * <obj_addr_list> = as defined in a corbaloc URL <key_string> = + * as defined in a corbaloc URL <string_name>= stringified Name + * empty_string Where: + *
    + *
  • corbaloc_obj: portion of a corbaname URL that identifies the naming + * context. The syntax is identical to its use in a corbaloc URL. + *
  • obj_addr_list: as defined in a corbaloc URL + *
  • key_string: as defined in a corbaloc URL. + *
  • string_name: a stringified Name with URL escapes as defined below. + *
+ * + * @param hostName The host name or IP address of the naming server + * @param port The port number of the naming service + * @param root The root of the namespace + * @param name The JNDI name + */ + private static String getCorbaname(String hostName, int port, String root, String name) { + if (name == null) + return "corbaname:iiop:" + hostName + ":" + port + "/" + root; + else + return "corbaname:iiop:" + hostName + ":" + port + "/" + root + "#" + toCorbaname(name); + } + + String getCorbaname(String name) { + return getCorbaname(hostName, port, root, name); + } + + /** + * Connect to the ORB. + */ + + // FIXME. May need to change the IBM classes if this binding is contributed + // to Tuscany + public ORB connect() { + if (orb == null) { + Properties props = new Properties(); + /* This code is for IBM JVM + props.put("org.omg.CORBA.ORBClass", "com.ibm.CORBA.iiop.ORB"); + props.put("com.ibm.CORBA.ORBInitRef.NameService", getCorbaloc(NAMING_SERVICE)); + props.put("com.ibm.CORBA.ORBInitRef.NameServiceServerRoot", getCorbaloc("NameServiceServerRoot")); */ + orb = ORB.init((String[])null, props); + } + return orb; + } + + /** + * Replace substrings + * + * @param source The source string. + * @param match The string to search for within the source string. + * @param replace The replacement for any matching components. + * @return + */ + private static String replace(String source, String match, String replace) { + int index = source.indexOf(match, 0); + if (index >= 0) { + + // We have at least one match, so gotta do the + // work... + + StringBuffer result = new StringBuffer(source.length() + 16); + int matchLength = match.length(); + int startIndex = 0; + + while (index >= 0) { + result.append(source.substring(startIndex, index)); + result.append(replace); + startIndex = index + matchLength; + index = source.indexOf(match, startIndex); + } + + // Grab the last piece, if any... + if (startIndex < source.length()) { + result.append(source.substring(startIndex)); + } + + return result.toString(); + + } else { + // No matches, just return the source... + return source; + } + } + + /** + * Resovled the JNDI name from the initial CosNaming context + * + * @param jndiName + * @return resovled CORBA ojbect + * @throws NamingException + */ + private static org.omg.CORBA.Object resovleString(NamingContextExt initCtx, String jndiName) throws NamingException { + try { + String name = stringify(jndiName); + return initCtx.resolve_str(name); + } catch (Exception e) { + NamingException ne = new NamingException(e.getMessage()); + ne.setRootCause(e); + throw ne; + } + } + + private NamingContextExt getCosNamingContext(String namingRoot) throws NamingException { + /* + * Using an ORB reference to get an initial naming reference There are + * two basic ways to get an initial CosNaming context. Both ways involve + * an ORB method invocation. The first way is to invoke the + * resolve_initial_references method on the ORB with an initial + * reference key. For this call to work, the ORB must be initialized + * with an initial reference for that key. The other way is to invoke + * the string_to_object method on the ORB, passing in a CORBA object URL + * with the host and port of the bootstrap server. The following + * examples illustrate both approaches. + */ + + /* + * Invoking resolve_initial_references Once an ORB reference is + * obtained, invoke the resolve_initial_references method on the ORB to + * obtain a reference to the initial context. The following code example + * invokes resolve_initial_reference on an ORB reference + */ + try { + connect(); + org.omg.CORBA.Object rootCtx = orb.resolve_initial_references(namingRoot); + return NamingContextExtHelper.narrow(rootCtx); + } catch (InvalidName e) { + InvalidNameException ne = new InvalidNameException(e.getMessage()); + ne.setRootCause(e); + throw ne; + } + } + + /** + * Look up a CORBA object by its JNDI name + * + * @param jndiName + * @return + * @throws NamingException + */ + org.omg.CORBA.Object stringToObject(String jndiName) throws NamingException { + /* + * Using an existing ORB and invoking string_to_object with a CORBA + * object URL with multiple name server addresses to get an initial + * context CORBA object URLs can contain more than one bootstrap server + * address. Use this feature when attempting to obtain an initial + * context from a server cluster. You can specify the bootstrap server + * addresses for all servers in the cluster in the URL. The operation + * will succeed if at least one of the servers is running, eliminating a + * single point of failure. There is no guarantee of any particular + * order in which the address list will be processed. For example, the + * second bootstrap server address may be used to obtain the initial + * context even though the first bootstrap server in the list is + * available. An example of a corbaloc URL with multiple addresses + * follows. obj = + * orb.string_to_object("corbaloc::myhost1:9810,:myhost1:9811,:myhost2:9810/NameService"); + */ + String corbaName = null; + if (jndiName.startsWith("corbaloc:") || jndiName.startsWith("corbaname:")) { + // Keep the qualified URL + corbaName = jndiName; + } else { + // Create a corbaname URL + corbaName = getCorbaname(jndiName); + } + + connect(); + org.omg.CORBA.Object obj = orb.string_to_object(corbaName); + return obj; + } + + private boolean isJndiConfigured() { + if (managed) + return true; + Boolean provided = (Boolean)AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + String initCtxFactory = System.getProperty(Context.INITIAL_CONTEXT_FACTORY); + if (initCtxFactory == null) { + URL file = Thread.currentThread().getContextClassLoader().getResource("jndi.properties"); + if (file != null) + return Boolean.TRUE; + else + return Boolean.FALSE; + } else + return Boolean.TRUE; + } + }); + return provided.booleanValue(); + } + + /** + * The character escape rules for the stringified name portion of an + * corbaname are: US-ASCII alphanumeric characters are not escaped. + * Characters outside this range are escaped, except for the following: ; / : ? @ & = + $ , - _ . ! ~ * ' ( ) + * corbaname Escape Mechanism The percent '%' character is used as an + * escape. If a character that requires escaping is present in a name + * component it is encoded as two hexadecimal digits following a "%" + * character to represent the octet. (The first hexadecimal character + * represent the highorder nibble of the octet, the second hexadecimal + * character represents the low-order nibble.) If a '%' is not followed by + * two hex digits, the stringified name is syntactically invalid. + * @param s + * @return RFC2396-encoded stringified name + */ + static String encode2396(String s) { + if (s == null) + return null; + StringBuffer encoded = new StringBuffer(s); + for (int i = 0; i < encoded.length(); i++) { + char c = encoded.charAt(i); + if (RFC2396.indexOf(c) == -1) { + encoded.setCharAt(i, '%'); + char ac[] = Integer.toHexString(c).toCharArray(); + if (ac.length == 2) + encoded.insert(i + 1, ac); + else if (ac.length == 1) { + encoded.insert(i + 1, '0'); + encoded.insert(i + 2, ac[0]); + } else { + throw new IllegalArgumentException("Invalid character '" + c + "' in \"" + s + "\""); + } + i += 2; + } + } + return encoded.toString(); + } + + /** + * Decode an RFC2396-encoded string + * + * @param s + * @return Plain string + */ + static String decode2396(String s) { + if (s == null) + return null; + StringBuffer decoded = new StringBuffer(s); + for (int i = 0; i < decoded.length(); i++) { + char c = decoded.charAt(i); + if (c == '%') { + if (i + 2 >= decoded.length()) + throw new IllegalArgumentException("Incomplete key_string escape sequence"); + int j; + j = HEX.indexOf(decoded.charAt(i + 1)) * 16 + HEX.indexOf(decoded.charAt(i + 2)); + decoded.setCharAt(i, (char)j); + decoded.delete(i + 1, i + 3); + } else if (RFC2396.indexOf(c) == -1) + throw new IllegalArgumentException("Invalid key_string character '" + c + "'"); + } + return decoded.toString(); + } + + /** + * The backslash '\' character escapes the reserved meaning of '/', '.', and + * '\' in a stringified name. + * + * @param jndiName + * @return Escaped stringified name for CosNaming + */ + private static String stringify(String jndiName) { + // Esacpe . into \. since it's an INS naming delimeter + return replace(encode2396(jndiName), ".", "\\."); + } + + /** + * Escape the "." into "%5C%2E" + * + * @param jndiName + * @return corbaname treating "." as a literal + */ + private static String toCorbaname(String jndiName) { + // Esacpe . into %5C%2E (\.) since it's an INS naming delimeter + // For example, sca.sample.StockQuote ---> + // sca%5C%2Esample%5C%2EStockQuote/StockQuote + return replace(encode2396(jndiName), ".", "%5C%2E"); + } + + private ObjectLocator getObjectLocator() throws NamingException { + if (locator != null) + return locator; + /* + * For managed env, jndi is assumed to be configured by default For + * unmanaged environment, jndi could have configured through + * jndi.properties file + */ + if (isJndiConfigured()) { + locator = new JndiLocator(); + } else { // this is definitely JSE env without jndi configured. Use + // Corba. + locator = new CosNamingLocator(); + } + return locator; + } + + public Object locate(String jndiName) throws NamingException { + + Object result = getObjectLocator().locate(jndiName); + return result; + } + + private static interface ObjectLocator { + public Object locate(String name) throws NamingException; + } + + private class JndiLocator implements ObjectLocator { + private Context context; + + private JndiLocator() throws NamingException { + this.context = new InitialContext(); + } + + private JndiLocator(Context context) { + this.context = context; + } + + public Object locate(String name) throws NamingException { + try { + return context.lookup(name); + } catch (Exception e) { + e.printStackTrace(); + return null; + } + } + } + + private class CosNamingLocator implements ObjectLocator { + private NamingContextExt context = null; + + private CosNamingLocator() { + } + + private CosNamingLocator(NamingContextExt context) { + this.context = context; + } + + public Object locate(String name) throws NamingException { + if (context != null) + return resovleString(context, name); + else + return stringToObject(name); + } + } + + public void setHostEnv(boolean managed) { + this.managed = managed; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/util/EJBObjectFactory.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/util/EJBObjectFactory.java new file mode 100644 index 0000000000..1538c27716 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/util/EJBObjectFactory.java @@ -0,0 +1,188 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.ejb.util; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.rmi.RemoteException; +import java.rmi.UnexpectedException; + +import javax.ejb.CreateException; +import javax.ejb.EJBLocalHome; +import javax.naming.NamingException; +import javax.rmi.CORBA.Util; + +import org.omg.CORBA.SystemException; +import org.omg.CORBA.portable.ApplicationException; +import org.omg.CORBA.portable.ObjectImpl; +import org.omg.CORBA.portable.RemarshalException; +import org.osoa.sca.ServiceRuntimeException; + +public class EJBObjectFactory { + + private EJBObjectFactory() { + } + + /** + * Get either a generated of dynamic EJB stub using the specified JNDI + * properties. + *

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

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

+ */ + public static Object createStub(NamingEndpoint namingEndpoint) throws NamingException, RemoteException, + CreateException { + + EJBLocator locator = namingEndpoint.getLocator(); + Object homeObject = locator.locate(namingEndpoint.getJndiName()); + /* + * The type of the object returned from the lookup is as follows: If the + * generated stub exists on the classpath, it's an instance of that + * type, otherwise, "org.omg.stub.java.rmi._Remote_Stub" or + * "org.omg.stub.javax.ejb._EJBHome_Stub" + */ + Object stub = getEJBStub(homeObject); + // Cache dynamic stub only + return stub; + } + + /** + * @param homeObject + * @param ejbHomeClass + * @return + * @throws RemoteException + */ + protected static Object getEJBStub(Object homeObject) throws RemoteException, CreateException { + + Object stub = null; + if (homeObject instanceof EJBLocalHome) { + // Local EJB + stub = createEJBLocalObject(homeObject); + } else { + // Handle dynamic stub + if (homeObject instanceof ObjectImpl) { + ObjectImpl objectImpl = (ObjectImpl)homeObject; + stub = createEJBObject(objectImpl); + } /** + * Above checks will be satisfied if Bean is running on servers like Websphere. With this + * logic, client (SCA composite with EJB ref binding) doesn't need to include home class or + * client stubs. + * + * Below check is needed SCA composite with EJB ref binding is accessing openEJB implementation. + * For e.g if the bean is running on Geronimo. + */ + else if ((javax.rmi.PortableRemoteObject.narrow(homeObject, javax.ejb.EJBHome.class)) instanceof javax.ejb.EJBHome) { + stub = createEJBObjectFromHome(homeObject); + } else + throw new ServiceRuntimeException("Invalid stub type: " + homeObject.getClass()); + } + return stub; + } + + /** + * Create a pre-generated EJB stub + * + * @param homeObject + * @return + * @throws RemoteException + */ + protected static Object createEJBLocalObject(Object homeObject) throws RemoteException { + + Object stub = null; + try { + // Find the "create()" method + Method createMethod = homeObject.getClass().getMethod("create", null); + // Create an EJB object + stub = createMethod.invoke(homeObject, null); + } catch (NoSuchMethodException e) { + // "create()" method not found, it's still a dynamic stub + stub = null; + } catch (InvocationTargetException e) { + throw new RemoteException(e.getTargetException().toString()); + } catch (Exception e) { + throw new RemoteException(e.toString()); + } + return stub; + } + + /** + * Here homeObject is instance of EJBHome + * + * @param homeObject + * @return + * @throws RemoteException + */ + protected static Object createEJBObjectFromHome(Object homeObject) throws RemoteException { + + Object stub = null; + try { + // Find the "create()" method + Method createMethod = homeObject.getClass().getMethod("create", null); + // Create an EJB object + stub = createMethod.invoke(homeObject, null); + } catch (NoSuchMethodException e) { + // "create()" method not found, it's still a dynamic stub + stub = null; + } catch (InvocationTargetException e) { + throw new RemoteException(e.getTargetException().toString()); + } catch (Exception e) { + throw new RemoteException(e.toString()); + } + return stub; + } + + /** + * Create an EJBObject using RMI/IIOP APIs + * + * @param ejbHomeObject + * @return The EJBObject remote stub + * @throws CreateException + * @throws RemoteException + */ + protected static Object createEJBObject(ObjectImpl ejbHomeObject) throws CreateException, RemoteException { + + try { + org.omg.CORBA_2_3.portable.InputStream in = null; + try { + org.omg.CORBA.portable.OutputStream out = ejbHomeObject._request("create", true); + in = (org.omg.CORBA_2_3.portable.InputStream)ejbHomeObject._invoke(out); + return (Object)in.read_Object(Object.class); + } catch (ApplicationException ex) { + in = (org.omg.CORBA_2_3.portable.InputStream)ex.getInputStream(); + String id = in.read_string(); + if (id.equals("IDL:javax/ejb/CreateEx:1.0")) { + throw (CreateException)in.read_value(CreateException.class); + } + throw new UnexpectedException(id); + } catch (RemarshalException ex) { + return createEJBObject(ejbHomeObject); + } finally { + ejbHomeObject._releaseReply(in); + } + } catch (SystemException ex) { + throw Util.mapSystemException(ex); + } + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/util/EJBStubHelper.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/util/EJBStubHelper.java new file mode 100644 index 0000000000..ee05420cd7 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/util/EJBStubHelper.java @@ -0,0 +1,69 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.ejb.util; + +import java.rmi.RemoteException; + +import javax.ejb.CreateException; +import javax.naming.NamingException; + +import org.osoa.sca.ServiceRuntimeException; +import org.osoa.sca.ServiceUnavailableException; + +public class EJBStubHelper { + + private static Object stub; + private static ServiceRuntimeException exception; + + private EJBStubHelper() { + } + + /** + * @param owner + * @param jndiName + * @return + */ + + public static Object lookup(NamingEndpoint endpoint) { + return getStub(endpoint); + } + + public static Object getStub(NamingEndpoint namingEndpoint) { + try { + stub = EJBObjectFactory.createStub(namingEndpoint); + } catch (NamingException e) { + exception = new ServiceUnavailableException(e); + e.printStackTrace(); + throw (ServiceUnavailableException)exception; + } catch (CreateException e) { + exception = new ServiceUnavailableException(e); + throw (ServiceUnavailableException)exception; + } catch (RemoteException e) { + exception = new ServiceRuntimeException(e); + throw (ServiceRuntimeException)exception; + } + + if (exception == null) { + return stub; // Normal result + } else { + throw exception; // Throw the exception + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/util/InterfaceInfo.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/util/InterfaceInfo.java new file mode 100644 index 0000000000..19f4063a12 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/util/InterfaceInfo.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.ejb.util; + +import java.io.Serializable; +import java.lang.reflect.Method; +import java.security.AccessController; +import java.security.PrivilegedAction; +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.WeakHashMap; + +import org.apache.tuscany.sca.binding.ejb.java2idl.Java2IDL; +import org.apache.tuscany.sca.binding.ejb.java2idl.OperationType; + +// import commonj.sdo.DataObject; + +/** + * The signature for a java interface + */ +public class InterfaceInfo implements Serializable { + + private static final Map interfaces = Collections.synchronizedMap(new WeakHashMap()); + + private static final long serialVersionUID = 2314533906465094860L; + private String name; + + private Map methods = new HashMap(); + + public synchronized final static InterfaceInfo getInstance(final Class iface) { + InterfaceInfo info = (InterfaceInfo)interfaces.get(iface); + if (info == null) { + info = new InterfaceInfo(iface); + interfaces.put(iface, info); + } + return info; + } + + public InterfaceInfo(final Class iface) { + super(); + if (iface == null) + throw new IllegalArgumentException("The interface cannot be null"); + this.name = iface.getName(); + // SECURITY + /* + * Permission: accessDeclaredMembers : Access denied + * (java.lang.RuntimePermission accessDeclaredMembers) + */ + Map idlNames = (Map)AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + return Java2IDL.getIDLMapping(iface); + } + }); + Iterator i = idlNames.entrySet().iterator(); + while (i.hasNext()) { + Map.Entry entry = (Map.Entry)i.next(); + Method method = (Method)entry.getKey(); + OperationType operationType = (OperationType)entry.getValue(); + MethodInfo methodInfo = new MethodInfo(method); + methodInfo.setIDLName(operationType.getIDLName()); + methods.put(method.getName(), methodInfo); + } + } + + /* + * public InterfaceInfo(String portType, String wsdlOperationName) { + * super(); this.name = portType; // operation() + * throws RemoteException MethodInfo method = new + * MethodInfo(wsdlOperationName, DataObject.class.getName(), new + * String[]{DataObject.class.getName()}, new + * String[]{RemoteException.class.getName()}); methods.put(method.getName(), + * method); } + */ + + /** + * @return + */ + public Map getMethods() { + return methods; + } + + /** + * @return + */ + public MethodInfo getMethod(String name) { + return (MethodInfo)methods.get(name); + } + + /** + * @return + */ + public String getName() { + return name; + } + + public String toString() { + StringBuffer sb = new StringBuffer(); + sb.append("interface ").append(name).append("{ \n"); + Iterator i = methods.values().iterator(); + while (i.hasNext()) { + MethodInfo methodInfo = (MethodInfo)i.next(); + sb.append("\t").append(methodInfo).append("\n"); + } + sb.append("};\n"); + return sb.toString(); + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/util/JavaReflectionAdapter.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/util/JavaReflectionAdapter.java new file mode 100644 index 0000000000..db762aeb13 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/util/JavaReflectionAdapter.java @@ -0,0 +1,155 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.ejb.util; + +import java.beans.PropertyDescriptor; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.security.AccessController; +import java.security.PrivilegedAction; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.WeakHashMap; + +import org.osoa.sca.ServiceRuntimeException; + +/** + * An adapter for java classes, indexes the methods by name and provides an + * invoke method that takes a method name. + */ +public class JavaReflectionAdapter { + + private static Map adapters = Collections.synchronizedMap(new WeakHashMap()); + + private Class clazz; + private Map methodMap = new HashMap(); + + /** + * Create a java reflection adapter + * + * @param clazz + */ + public synchronized static JavaReflectionAdapter createJavaReflectionAdapter(Class clazz) { + JavaReflectionAdapter adapter = (JavaReflectionAdapter)adapters.get(clazz); + if (adapter == null) { + adapter = new JavaReflectionAdapter(clazz); + adapters.put(clazz, adapter); + } + return adapter; + } + + /** + * Constructor + * + * @param clazz + */ + private JavaReflectionAdapter(final Class clazz) { + this.clazz = clazz; + + // Index the methods on the implementation class + Method[] methods = (Method[])AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + return clazz.getMethods(); + } + }); + for (int i = 0, n = methods.length; i < n; i++) { + methodMap.put(methods[i].getName(), methods[i]); + } + } + + /** + * Returns a map containing the methods on the class, keyed by name + * + * @return + */ + public Map getMethods() { + return methodMap; + } + + /** + * Return the specified method + * + * @param methodName + * @return + * @throws NoSuchMethodException + */ + public Method getMethod(String methodName) throws NoSuchMethodException { + + Method method = (Method)methodMap.get(methodName); + if (method == null) + throw new NoSuchMethodException(methodName); + return method; + } + + private final static Map DEFAULT_PRIMITIVE_VALUES = new HashMap(); + static { + DEFAULT_PRIMITIVE_VALUES.put(boolean.class, Boolean.FALSE); + DEFAULT_PRIMITIVE_VALUES.put(byte.class, new Byte((byte)0)); + DEFAULT_PRIMITIVE_VALUES.put(char.class, new Character((char)0)); + DEFAULT_PRIMITIVE_VALUES.put(short.class, new Short((short)0)); + DEFAULT_PRIMITIVE_VALUES.put(int.class, new Integer(0)); + DEFAULT_PRIMITIVE_VALUES.put(long.class, new Long(0)); + DEFAULT_PRIMITIVE_VALUES.put(float.class, new Float(0.0)); + DEFAULT_PRIMITIVE_VALUES.put(double.class, new Double(0.0)); + } + + /** + * Invoke a method using Java reflection. + * + * @param method + * @param object + * @param args + * @return + * @throws InvocationTargetException + * @throws IllegalAccessException + */ + public Object invoke(Method method, Object object, Object[] args) throws InvocationTargetException, + IllegalAccessException { + Class[] parameterTypes = method.getParameterTypes(); + for (int i = 0; i < parameterTypes.length; i++) { + Class parameterType = parameterTypes[i]; + if (args[i] == null && parameterType.isPrimitive()) { + args[i] = DEFAULT_PRIMITIVE_VALUES.get(parameterType); + } + } + return method.invoke(object, args); + } + + /** + * Set the java bean property + * + * @param bean + * @param propertyName + * @param value + * @return + */ + public boolean setProperty(Object bean, String propertyName, Object value) { + try { + PropertyDescriptor propertyDescriptor = new PropertyDescriptor(propertyName, bean.getClass()); + Method writeMethod = propertyDescriptor.getWriteMethod(); + writeMethod.invoke(bean, new Object[] {value}); + return true; + } catch (InvocationTargetException e) { + throw new ServiceRuntimeException(e.getTargetException()); + } catch (Exception e) { + return false; + } + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/util/MethodInfo.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/util/MethodInfo.java new file mode 100644 index 0000000000..ac3ace2d6c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/util/MethodInfo.java @@ -0,0 +1,176 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.ejb.util; + +import java.io.Serializable; +import java.lang.reflect.Method; +import java.util.HashMap; +import java.util.Map; + +/** + * MetaData for a java method + */ +public class MethodInfo implements Serializable { + + /** Automatically generated javadoc for: serialVersionUID */ + private static final long serialVersionUID = -5557260979514687514L; + private String name; + private String returnType; + private String[] parameterTypes; + private String[] exceptionTypes; + + private String IDLName; + + /** + * Type Signature Java Type -------------- --------- Z boolean B byte C char + * S short I int J long F float D double L fully-qualified-class ; + * fully-qualified-class [ type type[] ( arg-types ) ret-type method type + */ + private final static Map signatures = new HashMap(); + static { + signatures.put("Z", boolean.class); + signatures.put("B", byte.class); + signatures.put("C", char.class); + signatures.put("S", short.class); + signatures.put("I", int.class); + signatures.put("J", long.class); + signatures.put("F", float.class); + signatures.put("D", double.class); + signatures.put("V", void.class); + } + + public MethodInfo(Method method) { + this.name = method.getName(); + // this.declaringClass = method.getDeclaringClass().getName(); + this.returnType = method.getReturnType().getName(); + Class[] types = method.getParameterTypes(); + this.parameterTypes = new String[types.length]; + for (int i = 0; i < types.length; i++) { + this.parameterTypes[i] = types[i].getName(); + } + types = method.getExceptionTypes(); + this.exceptionTypes = new String[types.length]; + for (int i = 0; i < types.length; i++) { + this.exceptionTypes[i] = types[i].getName(); + } + IDLName = this.name; + } + + protected MethodInfo(String name, String returnType, String[] parameterTypes, String[] exceptionTypes) { + this.name = name; + this.returnType = returnType; + this.parameterTypes = parameterTypes; + this.exceptionTypes = exceptionTypes; + this.IDLName = name; + } + + /** + * Parse the class name from the internal signature Sample signatures: int + * ---> I; int[] ---> [I Object ---> java/lang/Object Object[] ---> + * [Ljava/lang/Object; + * + * @param value + * @return + */ + private static String getName(String signature) { + String name = signature; + // Remove leading ARRAY ([) signatures + int index = name.lastIndexOf('['); + if (index != -1) + name = name.substring(index + 1); + + // Remove L<...>; + if (name.charAt(0) == 'L' && name.charAt(name.length() - 1) == ';') + name = name.substring(1, name.length() - 1); + + // Primitive types + Class primitiveClass = (Class)signatures.get(name); + if (primitiveClass != null) { + name = primitiveClass.getName(); + } + + for (int i = 0; i < index + 1; i++) { + name = name + "[]"; + } + return name; + } + + /** + * @return + */ + public String getName() { + return name; + } + + /** + * @return + */ + public String[] getParameterTypes() { + return parameterTypes; + } + + /** + * @return + */ + public String getReturnType() { + return returnType; + } + + /** + * @return + */ + public String[] getExceptionTypes() { + return exceptionTypes; + } + + public String toString() { + StringBuffer sb = new StringBuffer(); + sb.append(getName(returnType)).append(" ").append(name).append("("); + for (int j = 0; j < parameterTypes.length; j++) { + sb.append(getName(parameterTypes[j])).append(" ").append("arg" + j); + if (j < (parameterTypes.length - 1)) + sb.append(", "); + } + sb.append(")"); + if (exceptionTypes.length > 0) { + sb.append(" throws "); + for (int k = 0; k < exceptionTypes.length; k++) { + sb.append(exceptionTypes[k]); + if (k < (exceptionTypes.length - 1)) + sb.append(", "); + } + } + sb.append(";"); + return sb.toString(); + } + + /** + * @return Returns the iDLName. + */ + public String getIDLName() { + return IDLName; + } + + /** + * @param name The iDLName to set. + */ + public void setIDLName(String name) { + IDLName = name; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/util/NamingEndpoint.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/util/NamingEndpoint.java new file mode 100644 index 0000000000..5d4b91d0f9 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/java/org/apache/tuscany/sca/binding/ejb/util/NamingEndpoint.java @@ -0,0 +1,118 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.ejb.util; + +import java.security.AccessController; +import java.security.PrivilegedAction; + +public class NamingEndpoint { + private String jndiName; + private EJBLocator locator; + private boolean managed = true; + + public NamingEndpoint(String hostName, int port, String jndiName) { + this.jndiName = jndiName; + this.locator = new EJBLocator(hostName, port); + } + + public NamingEndpoint(String name) { + + /** + * by default it's a managed environment means SCA composite with ref binding is running on + * an AppServer. If running on J2SE, pass -Dmanaged=false for the VM + */ + String managedEnv = (String)AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + return System.getProperty("managed"); + } + }); + + if (managedEnv != null) + managed = new Boolean(managedEnv); + + if ((!managed) && name.startsWith("corbaname:iiop:")) { + /** + * if (name.startsWith("corbaname:iiop:")) { corbaname:iiop::/#name + * For exmaple, + * "corbaname:iiop:localhost:2809/NameServiceServerRoot#ejb/MyEJBHome"; + */ + + String[] parts = split(name, '#'); + if (parts.length != 2) + throw new IllegalArgumentException("Invalid corbaname: " + name); + + this.jndiName = parts[1]; // The logical jndi name + this.locator = new EJBLocator(parts[0], managed); + + } else { + this.jndiName = name; + this.locator = new EJBLocator(managed); + } + + } + + private static String[] split(String str, char ch) { + int index = str.lastIndexOf(ch); + if (index == -1) { + return new String[] {str, ""}; + } else { + return new String[] {str.substring(0, index), str.substring(index + 1)}; + } + } + + /** + * @return Returns the jndiName. + */ + public String getJndiName() { + return jndiName; + } + + public EJBLocator getLocator() { + return locator; + } + + public String getCorbaname() { + return locator.getCorbaname(jndiName); + } + + /** + * @see java.lang.Object#equals(java.lang.Object) + */ + public boolean equals(Object obj) { + if (obj instanceof NamingEndpoint) { + NamingEndpoint endpoint = (NamingEndpoint)obj; + return jndiName.equals(endpoint.jndiName); + } + return false; + } + + /** + * @see java.lang.Object#hashCode() + */ + public int hashCode() { + return jndiName.hashCode(); + } + + /** + * @see java.lang.Object#toString() + */ + public String toString() { + return jndiName; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/resources/META-INF/services/org.apache.tuscany.sca.spi.BindingActivator b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/resources/META-INF/services/org.apache.tuscany.sca.spi.BindingActivator new file mode 100644 index 0000000000..1e69e1a07c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/main/resources/META-INF/services/org.apache.tuscany.sca.spi.BindingActivator @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# Implementation class for the ExtensionActivator +org.apache.tuscany.sca.binding.ejb.EJBBindingActivator + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/test/java/account/BankManagerFacade.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/test/java/account/BankManagerFacade.java new file mode 100644 index 0000000000..a8100d280b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/test/java/account/BankManagerFacade.java @@ -0,0 +1,33 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package account; + +import org.osoa.sca.annotations.Remotable; + +/** + * + * Compatible EJB interface + * + */ +@Remotable +public interface BankManagerFacade +{ + public java.lang.Double getAccountBalance( java.lang.String accountNo ); + public void changeAccountBalance( java.lang.String accountNo,java.lang.Double balance ); +} \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/test/java/account/Customer.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/test/java/account/Customer.java new file mode 100644 index 0000000000..2b5ed04f6a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/test/java/account/Customer.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 account; + +import org.osoa.sca.annotations.Remotable; +import org.osoa.sca.annotations.Service; + +@Remotable +@Service +public interface Customer { + + /** + * This method deposits the amount. method accesses external EJB to get the + * current balance and add the amount to existing balance. + * + * @param String amount to be deposited + * @return total amount in customer accound after deposit + */ + Double depositAmount(java.lang.String accountNo, Double amount); + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/test/java/account/CustomerImpl.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/test/java/account/CustomerImpl.java new file mode 100644 index 0000000000..0cbb6d088c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/test/java/account/CustomerImpl.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 account; + +import org.osoa.sca.ServiceRuntimeException; +import org.osoa.sca.annotations.Reference; +import org.osoa.sca.annotations.Service; + +@Service(Customer.class) +public class CustomerImpl implements Customer { + + private BankManagerFacade extEJBService = null; + + public BankManagerFacade getExtEJBService() { + return extEJBService; + } + + @Reference + public void setExtEJBService(BankManagerFacade extEJBService) { + this.extEJBService = extEJBService; + } + + // this method invokes external EJB through EJB reference binding + public Double depositAmount(java.lang.String accountNo, Double amount) { + + Double total = null; + + System.out.println("In component implementation. Invoking external EJB through EJB reference binding "); + + try { + Double balance = extEJBService.getAccountBalance(accountNo); //invoke external ejb through ejb reference binding + total = balance + amount; + } catch (Exception e) { + throw new ServiceRuntimeException(e); + } + return total; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/test/java/org/apache/geronimo/samples/bank/ejb/BankManagerFacade.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/test/java/org/apache/geronimo/samples/bank/ejb/BankManagerFacade.java new file mode 100644 index 0000000000..c393d08a25 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/test/java/org/apache/geronimo/samples/bank/ejb/BankManagerFacade.java @@ -0,0 +1,44 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/* + * Generated by XDoclet - Do not edit! + */ +package org.apache.geronimo.samples.bank.ejb; + +// copied from the Geronimo Bank sample: http://cwiki.apache.org/GMOxDOC11/ejb-sample-application.html#EJBsampleapplication-overview + +/** + * Remote interface for BankManagerFacadeBean. + * @xdoclet-generated at ${TODAY} + * @copyright The XDoclet Team + * @author XDoclet + * @version ${version} + */ +public interface BankManagerFacade + extends javax.ejb.EJBObject +{ + + public void changeAccountBalance( java.lang.String accountNo,java.lang.Double balance ) + throws java.rmi.RemoteException; + + public java.lang.Double getAccountBalance( java.lang.String accountNo ) + throws java.rmi.RemoteException; + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/test/java/org/apache/geronimo/samples/bank/ejb/BankManagerFacadeHome.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/test/java/org/apache/geronimo/samples/bank/ejb/BankManagerFacadeHome.java new file mode 100644 index 0000000000..f5e2f3b2e4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/test/java/org/apache/geronimo/samples/bank/ejb/BankManagerFacadeHome.java @@ -0,0 +1,44 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/* + * Generated by XDoclet - Do not edit! + */ + +// copied from the Geronimo Bank sample: http://cwiki.apache.org/GMOxDOC11/ejb-sample-application.html#EJBsampleapplication-overview + +package org.apache.geronimo.samples.bank.ejb; + +/** + * Home interface for BankManagerFacadeBean. + * @xdoclet-generated at ${TODAY} + * @copyright The XDoclet Team + * @author XDoclet + * @version ${version} + */ +public interface BankManagerFacadeHome + extends javax.ejb.EJBHome +{ + public static final String COMP_NAME="java:comp/env/ejb/BankManagerFacadeBean"; + public static final String JNDI_NAME="org.apache.geronimo.samples.bank.ejb.BankManagerFacadeBean"; + + public org.apache.geronimo.samples.bank.ejb.BankManagerFacade create() + throws javax.ejb.CreateException,java.rmi.RemoteException; + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/test/java/org/apache/tuscany/sca/binding/ejb/tests/EJBReferenceTestCase.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/test/java/org/apache/tuscany/sca/binding/ejb/tests/EJBReferenceTestCase.java new file mode 100644 index 0000000000..d60468d23c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/test/java/org/apache/tuscany/sca/binding/ejb/tests/EJBReferenceTestCase.java @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.ejb.tests; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.host.embedded.SCADomain; + +import account.Customer; + +/** + * Invokes the component which calls the reference using the EJB binding + */ +public class EJBReferenceTestCase extends TestCase { + + private SCADomain scaDomain; + + protected void setUp() throws Exception { + System.setProperty("managed", "false"); + System.setProperty("java.naming.factory.initial", "org.openejb.client.RemoteInitialContextFactory"); + System.setProperty("java.naming.provider.url", "localhost:4321"); + scaDomain = SCADomain.newInstance("account/account.composite"); + +// new Thread(new SocketTracer(4321, 4201)).start(); + new Thread(new MockServer(4321)).start(); + } + + protected void tearDown() throws Exception { + scaDomain.close(); + } + + public void testCalculator() throws Exception { + Customer customer = scaDomain.getService(Customer.class, "CustomerComponent"); + // This is one of the customer numbers in bank application running on Geronimo + String accountNo = "1234567890"; + Double balance = customer.depositAmount(accountNo, new Double(100)); + System.out.println("Balance amount for account " + accountNo + " is $" + balance); + assertEquals(1105.35, balance); + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/test/java/org/apache/tuscany/sca/binding/ejb/tests/MockServer.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/test/java/org/apache/tuscany/sca/binding/ejb/tests/MockServer.java new file mode 100644 index 0000000000..e81865fb6b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/test/java/org/apache/tuscany/sca/binding/ejb/tests/MockServer.java @@ -0,0 +1,75 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.ejb.tests; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.ServerSocket; +import java.net.Socket; + +public class MockServer implements Runnable { + + private int listen; + + private int[] r1 = new int[] {79, 69, 74, 80, 47, 50, 46, 48, 172, 237, 0, 5, 119, 1, 1, 116, 0, 5, 71, 85, 69, 83, 84}; + private int[] r2 = new int[] {79, 69, 74, 80, 47, 50, 46, 48, 172, 237, 0, 5, 119, 1, 13, 118, 114, 0, 58, 111, 114, 103, 46, 97, 112, 97, 99, 104, 101, 46, 103, 101, 114, 111, 110, 105, 109, 111, 46, 115, 97, 109, 112, 108, 101, 115, 46, 98, 97, 110, 107, 46, 101, 106, 98, 46, 66, 97, 110, 107, 77, 97, 110, 97, 103, 101, 114, 70, 97, 99, 97, 100, 101, 72, 111, 109, 101, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 120, 112, 118, 114, 0, 54, 111, 114, 103, 46, 97, 112, 97, 99, 104, 101, 46, 103, 101, 114, 111, 110, 105, 109, 111, 46, 115, 97, 109, 112, 108, 101, 115, 46, 98, 97, 110, 107, 46, 101, 106, 98, 46, 66, 97, 110, 107, 77, 97, 110, 97, 103, 101, 114, 70, 97, 99, 97, 100, 101, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 120, 112, 112, 112, 119, 185, 1, 0, 180, 111, 114, 103, 46, 97, 112, 97, 99, 104, 101, 46, 103, 101, 114, 111, 110, 105, 109, 111, 46, 115, 97, 109, 112, 108, 101, 115, 47, 66, 97, 110, 107, 47, 49, 46, 49, 46, 49, 47, 99, 97, 114, 63, 69, 74, 66, 77, 111, 100, 117, 108, 101, 61, 66, 97, 110, 107, 69, 74, 66, 46, 106, 97, 114, 44, 74, 50, 69, 69, 65, 112, 112, 108, 105, 99, 97, 116, 105, 111, 110, 61, 111, 114, 103, 46, 97, 112, 97, 99, 104, 101, 46, 103, 101, 114, 111, 110, 105, 109, 111, 46, 115, 97, 109, 112, 108, 101, 115, 47, 66, 97, 110, 107, 47, 49, 46, 49, 46, 49, 47, 99, 97, 114, 44, 106, 50, 101, 101, 84, 121, 112, 101, 61, 83, 116, 97, 116, 101, 108, 101, 115, 115, 83, 101, 115, 115, 105, 111, 110, 66, 101, 97, 110, 44, 110, 97, 109, 101, 61, 66, 97, 110, 107, 77, 97, 110, 97, 103, 101, 114, 70, 97, 99, 97, 100, 101, 66, 101, 97, 110, 0, 1}; + private int[] r3 = new int[] {79, 69, 74, 80, 47, 50, 46, 48, 172, 237, 0, 5, 119, 1, 4, 112}; + private int[] r4 = new int[] {79, 69, 74, 80, 47, 50, 46, 48, 172, 237, 0, 5, 119, 1, 4, 115, 114, 0, 16, 106, 97, 118, 97, 46, 108, 97, 110, 103, 46, 68, 111, 117, 98, 108, 101, 128, 179, 194, 74, 41, 107, 251, 4, 2, 0, 1, 68, 0, 5, 118, 97, 108, 117, 101, 120, 114, 0, 16, 106, 97, 118, 97, 46, 108, 97, 110, 103, 46, 78, 117, 109, 98, 101, 114, 134, 172, 149, 29, 11, 148, 224, 139, 2, 0, 0, 120, 112, 64, 143, 106, 204, 204, 204, 204, 205}; + + public MockServer(int listen) { + this.listen = listen; + } + + public void run() { + try { + ServerSocket ss = new ServerSocket(listen); + + doExchange(ss.accept(), 15, r1); + doExchange(ss.accept(), 80, r2); + doExchange(ss.accept(), 109, r3); + doExchange(ss.accept(), 163, r4); + + } catch (Exception e) { + e.printStackTrace(); + } + } + + private void doExchange(Socket sin, int readCount, int[] write) throws IOException, InterruptedException { + InputStream is = sin.getInputStream(); + OutputStream os = sin.getOutputStream(); + readBytes(is, readCount); + writeBytes(os, write); + sin.close(); + } + + private void readBytes(InputStream is, int x) throws IOException, InterruptedException { + for (int i = 0; i < x; i++) { + is.read(); + } + } + + private void writeBytes(OutputStream os, int[] bs) throws IOException, InterruptedException { + for (int i = 0; i < bs.length; i++) { + os.write(bs[i]); + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/test/java/org/apache/tuscany/sca/binding/ejb/tests/SocketTracer.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/test/java/org/apache/tuscany/sca/binding/ejb/tests/SocketTracer.java new file mode 100644 index 0000000000..3dd153eeef --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/test/java/org/apache/tuscany/sca/binding/ejb/tests/SocketTracer.java @@ -0,0 +1,113 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.ejb.tests; + +import java.io.InputStream; +import java.io.OutputStream; +import java.net.ServerSocket; +import java.net.Socket; + +/** + * Displays the bytes flowing across a Socket connection. + * Used to get the read count and reply data for the MockServer + */ +public class SocketTracer implements Runnable { + + private int listen; + private int send; + + SocketTracer(int listen, int send) { + this.listen = listen; + this.send = send; + } + + public void run() { + try { + ServerSocket ss = new ServerSocket(listen); + while (true) { + Socket sin = ss.accept(); + + Socket sout = new Socket("localhost", send); + + Thread st = new Thread(new Send(sin, sout)); + st.start(); + } + + } catch (Exception e) { + e.printStackTrace(); + } + } + +} + +class Send implements Runnable { + + Socket sin; + Socket sout; + + Send(Socket sin, Socket sout) { + this.sin = sin; + this.sout = sout; + } + + public void run() { + try { + + Reply rr = new Reply(sout.getInputStream(), sin.getOutputStream()); + Thread rt = new Thread(rr); + rt.start(); + + OutputStream outout = sout.getOutputStream(); + + InputStream is = sin.getInputStream(); + int i = 0; + while ((i = is.read()) != -1) { + System.out.println("out: " + i); + outout.write(i); + } + } catch (Exception e) { + e.printStackTrace(); + } + } +} + +class Reply implements Runnable { + + InputStream is; + OutputStream outout; + + Reply(InputStream is, OutputStream outout) { + this.is = is; + this.outout = outout; + } + + public void run() { + try { + int i = 0; + while ((i = is.read()) != -1) { + System.out.println("reply: " + i); + outout.write(i); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/test/resources/account/account.composite b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/test/resources/account/account.composite new file mode 100644 index 0000000000..38aece6a94 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ejb/src/test/resources/account/account.composite @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/DISCLAIMER b/sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/DISCLAIMER new file mode 100644 index 0000000000..d68a410903 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/DISCLAIMER @@ -0,0 +1,8 @@ +Apache Tuscany is an effort undergoing incubation at The Apache Software +Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is +required of all newly accepted projects until a further review indicates that +the infrastructure, communications, and decision making process have stabilized +in a manner consistent with other successful ASF projects. While incubation +status is not necessarily a reflection of the completeness or stability of the +code, it does indicate that the project has yet to be fully endorsed by the ASF. + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/LICENSE b/sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/LICENSE new file mode 100644 index 0000000000..6e529a25c4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/NOTICE b/sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/NOTICE new file mode 100644 index 0000000000..eb1926d971 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2007 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/pom.xml b/sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/pom.xml new file mode 100644 index 0000000000..f12abb8afd --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/pom.xml @@ -0,0 +1,93 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 0.91-incubating-SNAPSHOT + ../pom.xml + + + tuscany-binding-feed + Apache Tuscany Atom+RSS Feed Binding + + + + rome + rome + 0.9 + compile + + + + org.apache.tuscany.sca + tuscany-assembly + 0.91-incubating-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-interface-java + 0.91-incubating-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-core-spi + 0.91-incubating-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-host-http + 0.91-incubating-SNAPSHOT + + + + javax.servlet + servlet-api + 2.4 + provided + + + + org.apache.tuscany.sca + tuscany-http-tomcat + 0.91-incubating-SNAPSHOT + test + + + + org.apache.tuscany.sca + tuscany-host-embedded + 0.91-incubating-SNAPSHOT + test + + + + junit + junit + 4.2 + test + + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/DefaultFeedBindingFactory.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/DefaultFeedBindingFactory.java new file mode 100644 index 0000000000..a4e2861aba --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/DefaultFeedBindingFactory.java @@ -0,0 +1,32 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.feed; + +import org.apache.tuscany.sca.binding.feed.impl.FeedBindingImpl; + +/** + * A factory for the Feed binding model. + */ +public class DefaultFeedBindingFactory implements FeedBindingFactory { + + public FeedBinding createFeedBinding() { + return new FeedBindingImpl(); + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/Feed.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/Feed.java new file mode 100644 index 0000000000..3a0763bd93 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/Feed.java @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.feed; + +import org.osoa.sca.annotations.Remotable; + +import com.sun.syndication.feed.synd.SyndFeed; + +/** + * The business interface used on services and references that provide and + * consume feeds. + * + * @version $Rev$ $Date$ + */ +@Remotable +public interface Feed { + + /** + * Get an RSS or Atom feed. + * + * @param uri the uri of the feed + * @return the RSS or Atom feed + */ + SyndFeed get(String uri); +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/FeedBinding.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/FeedBinding.java new file mode 100644 index 0000000000..bec56404cd --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/FeedBinding.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 org.apache.tuscany.sca.assembly.Binding; + +/** + * A model for the Feed binding. + */ +public interface FeedBinding extends Binding { + + /** + * Returns the feed type. + * @return the feed type + */ + String getFeedType(); + + /** + * Sets the feed type. + * @param value the feed type + */ + void setFeedType(String value); + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/FeedBindingFactory.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/FeedBindingFactory.java new file mode 100644 index 0000000000..e98aefe2c9 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/FeedBindingFactory.java @@ -0,0 +1,33 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.feed; + +/** + * A factory for the Feed binding model. + */ +public interface FeedBindingFactory { + + /** + * Creates a new Feed binding. + * + * @return a new Feed binding + */ + FeedBinding createFeedBinding(); +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/impl/FeedBindingImpl.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/impl/FeedBindingImpl.java new file mode 100644 index 0000000000..5e0dea223c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/impl/FeedBindingImpl.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.impl; + +import java.util.Collections; +import java.util.List; + +import org.apache.tuscany.sca.binding.feed.FeedBinding; +import org.apache.tuscany.sca.policy.Intent; +import org.apache.tuscany.sca.policy.PolicySet; + +/** + * Implementation of the Feed binding model. + */ +public class FeedBindingImpl implements FeedBinding { + + private String name; + private String uri; + private String feedType; + + public String getName() { + return name; + } + + public String getURI() { + return uri; + } + + public void setName(String name) { + this.name = name; + } + + public void setURI(String uri) { + this.uri = uri; + } + + public List getPolicySets() { + // The sample binding does not support policies + return Collections.emptyList(); + } + + public List getRequiredIntents() { + // The binding does not support policies + return Collections.emptyList(); + } + + public List getExtensions() { + // The binding does not support extensions + return Collections.emptyList(); + } + + public boolean isUnresolved() { + return false; + } + + public void setUnresolved(boolean unresolved) { + // The binding is always resolved + } + + public String getFeedType() { + return feedType; + } + + public void setFeedType(String value) { + feedType = value; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/module/FeedModuleActivator.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/module/FeedModuleActivator.java new file mode 100644 index 0000000000..e91f184339 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/module/FeedModuleActivator.java @@ -0,0 +1,64 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.feed.module; + +import org.apache.tuscany.sca.binding.feed.DefaultFeedBindingFactory; +import org.apache.tuscany.sca.binding.feed.FeedBindingFactory; +import org.apache.tuscany.sca.binding.feed.provider.FeedBindingProviderFactory; +import org.apache.tuscany.sca.binding.feed.xml.AtomBindingProcessor; +import org.apache.tuscany.sca.binding.feed.xml.RssBindingProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.ModuleActivator; +import org.apache.tuscany.sca.http.ServletHost; +import org.apache.tuscany.sca.provider.ProviderFactoryExtensionPoint; + +/** + * A module activator for the Feed binding extension. + */ +public class FeedModuleActivator implements ModuleActivator { + + public Object[] getExtensionPoints() { + // No extensionPoints being contributed here + return null; + } + + public void start(ExtensionPointRegistry registry) { + + // Create the Feed model factory + FeedBindingFactory factory = new DefaultFeedBindingFactory(); + + // Add the AtomBindingProcessor and RSSBindingProcessor extensions + StAXArtifactProcessorExtensionPoint processors = + registry.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); + AtomBindingProcessor atomBindingProcessor = new AtomBindingProcessor(factory); + processors.addArtifactProcessor(atomBindingProcessor); + RssBindingProcessor rssBindingProcessor = new RssBindingProcessor(factory); + processors.addArtifactProcessor(rssBindingProcessor); + + // Add the Feed binding provider factory extension + ProviderFactoryExtensionPoint providerFactories = registry.getExtensionPoint(ProviderFactoryExtensionPoint.class); + ServletHost servletHost = registry.getExtensionPoint(ServletHost.class); + providerFactories.addProviderFactory(new FeedBindingProviderFactory(servletHost)); + } + + public void stop(ExtensionPointRegistry registry) { + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/FeedBindingInvoker.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/FeedBindingInvoker.java new file mode 100644 index 0000000000..63bbe7a9fd --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/FeedBindingInvoker.java @@ -0,0 +1,79 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.feed.provider; + +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URL; + +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; + +import com.sun.syndication.feed.synd.SyndFeed; +import com.sun.syndication.io.FeedException; +import com.sun.syndication.io.SyndFeedInput; +import com.sun.syndication.io.XmlReader; + +/** + * Invoker for the Feed binding. + */ +public class FeedBindingInvoker implements Invoker { + + private String uri; + + public FeedBindingInvoker(String uri, String feedType) { + this.uri = uri; + } + + public Message invoke(Message msg) { + try { + URL feedURL; + Object[] args = msg.getBody(); + if (args[0] != null) { + URI arg = URI.create((String)args[0]); + if (arg.isAbsolute()) { + feedURL = arg.toURL(); + } else { + feedURL = new URL(uri + "/" + arg.toString()); + } + } else { + feedURL = new URL(uri); + } + + // Read the configured feed into a Feed object + SyndFeedInput input = new SyndFeedInput(); + SyndFeed feed = input.build(new XmlReader(feedURL)); + msg.setBody(feed); + + System.out.println(">>> FeedBindingInvoker (" + feed.getFeedType() + ") " + uri); + + } catch (MalformedURLException e) { + msg.setFaultBody(e); + } catch (IllegalArgumentException e) { + msg.setFaultBody(e); + } catch (FeedException e) { + msg.setFaultBody(e); + } catch (IOException e) { + msg.setFaultBody(e); + } + return msg; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/FeedBindingListener.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/FeedBindingListener.java new file mode 100644 index 0000000000..0ceb1f9064 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/FeedBindingListener.java @@ -0,0 +1,89 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.feed.provider; + +import java.io.IOException; +import java.io.OutputStream; +import java.io.PrintWriter; + +import javax.servlet.ServletConfig; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.tuscany.sca.binding.feed.Feed; + +import com.sun.syndication.feed.synd.SyndFeed; +import com.sun.syndication.io.FeedException; +import com.sun.syndication.io.SyndFeedOutput; + +/** + * A Feed binding listener, implemented as a servlet and register in a + * servlet host provided by the SCA hosting runtime. + */ +public class FeedBindingListener extends HttpServlet { + private static final long serialVersionUID = 1L; + + String serviceName; + Class serviceInterface; + Object serviceInstance; + String feedType; + + public FeedBindingListener(String serviceName, Class serviceInterface, Object serviceInstance, String feedType) { + this.serviceName = serviceName; + this.serviceInterface = serviceInterface; + this.serviceInstance = serviceInstance; + this.feedType = feedType; + } + + @Override + public void init(ServletConfig config) { + } + + @Override + public void service(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { + + // 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; + + System.out.println(">>> FeedEndPointServlet (" + requestFeedType + ") " + request.getRequestURI()); + + // Assuming that the service provided by this binding implements the Feed + // service interface, get the Feed from the service + String uri = request.getRequestURL().toString(); + SyndFeed syndFeed = ((Feed)serviceInstance).get(uri); + syndFeed.setFeedType(requestFeedType); + + // Write the Feed to the servlet output + OutputStream output = response.getOutputStream(); + SyndFeedOutput syndOutput = new SyndFeedOutput(); + try { + syndOutput.output(syndFeed, new PrintWriter(output)); + } catch (FeedException e) { + throw new ServletException(e); + } + + output.flush(); + output.close(); + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/FeedBindingProviderFactory.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/FeedBindingProviderFactory.java new file mode 100644 index 0000000000..9e855b7b2f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/FeedBindingProviderFactory.java @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.feed.provider; + +import org.apache.tuscany.sca.binding.feed.FeedBinding; +import org.apache.tuscany.sca.http.ServletHost; +import org.apache.tuscany.sca.provider.BindingProviderFactory; +import org.apache.tuscany.sca.provider.ReferenceBindingProvider; +import org.apache.tuscany.sca.provider.ServiceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + +/** + * Implementation of the Feed binding provider factory. + */ +public class FeedBindingProviderFactory implements BindingProviderFactory { + + ServletHost servletHost; + + public FeedBindingProviderFactory(ServletHost servletHost) { + this.servletHost = servletHost; + } + + public ReferenceBindingProvider createReferenceBindingProvider(RuntimeComponent component, + RuntimeComponentReference reference, + FeedBinding binding) { + return new FeedReferenceBindingProvider(component, reference, binding); + } + + public ServiceBindingProvider createServiceBindingProvider(RuntimeComponent component, + RuntimeComponentService service, + FeedBinding binding) { + return new FeedServiceBindingProvider(component, service, binding, servletHost); + } + + public Class getModelType() { + return FeedBinding.class; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/FeedReferenceBindingProvider.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/FeedReferenceBindingProvider.java new file mode 100644 index 0000000000..2e14d49e52 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/FeedReferenceBindingProvider.java @@ -0,0 +1,63 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.feed.provider; + +import org.apache.tuscany.sca.binding.feed.FeedBinding; +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 Feed binding provider. + */ +public class FeedReferenceBindingProvider implements ReferenceBindingProvider { + + private RuntimeComponentReference reference; + private FeedBinding binding; + + public FeedReferenceBindingProvider(RuntimeComponent component, + RuntimeComponentReference reference, + FeedBinding binding) { + this.reference = reference; + this.binding = binding; + } + + public Invoker createInvoker(Operation operation, boolean isCallback) { + if (isCallback) { + throw new UnsupportedOperationException(); + } else { + return new FeedBindingInvoker(binding.getURI(), binding.getFeedType()); + } + } + + public InterfaceContract getBindingInterfaceContract() { + return reference.getInterfaceContract(); + } + + public void start() { + } + + public void stop() { + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/FeedServiceBindingProvider.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/FeedServiceBindingProvider.java new file mode 100644 index 0000000000..64b4807998 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/provider/FeedServiceBindingProvider.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.feed.provider; + +import org.apache.tuscany.sca.binding.feed.FeedBinding; +import org.apache.tuscany.sca.http.ServletHost; +import org.apache.tuscany.sca.interfacedef.Interface; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.java.JavaInterface; +import org.apache.tuscany.sca.provider.ServiceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + +/** + * Implementation of the Feed binding provider. + */ +public class FeedServiceBindingProvider implements ServiceBindingProvider { + + private RuntimeComponent component; + private RuntimeComponentService service; + private FeedBinding binding; + private ServletHost servletHost; + private String uri; + + public FeedServiceBindingProvider(RuntimeComponent component, + RuntimeComponentService service, + FeedBinding binding, + ServletHost servletHost) { + this.component = component; + this.service = service; + this.binding = binding; + this.servletHost = servletHost; + uri = binding.getURI(); + if (uri == null) { + uri = "/" + component.getName(); + } + } + + public InterfaceContract getBindingInterfaceContract() { + return service.getInterfaceContract(); + } + + public void start() { + Class aClass = getTargetJavaClass(service.getInterfaceContract().getInterface()); + Object instance = component.createSelfReference(aClass).getService(); + + FeedBindingListener servlet = + new FeedBindingListener(binding.getName(), aClass, instance, binding.getFeedType()); + + servletHost.addServletMapping(uri, servlet); + } + + public void stop() { + servletHost.removeServletMapping(uri); + } + + private Class getTargetJavaClass(Interface targetInterface) { + return ((JavaInterface)targetInterface).getJavaClass(); + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/xml/AtomBindingProcessor.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/xml/AtomBindingProcessor.java new file mode 100644 index 0000000000..800acba9ed --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/xml/AtomBindingProcessor.java @@ -0,0 +1,79 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.feed.xml; + +import static org.osoa.sca.Constants.SCA_NS; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.binding.feed.FeedBinding; +import org.apache.tuscany.sca.binding.feed.FeedBindingFactory; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.contribution.service.ContributionResolveException; +import org.apache.tuscany.sca.contribution.service.ContributionWriteException; + +/** + * A processor for elements. + */ +public class AtomBindingProcessor implements StAXArtifactProcessor { + + private final static QName BINDING_ATOM = new QName(SCA_NS, "binding.atom"); + + private final FeedBindingFactory factory; + + /** + * Constructs a new binding processor. + * @param factory + */ + public AtomBindingProcessor(FeedBindingFactory factory) { + this.factory = factory; + } + + public QName getArtifactType() { + return BINDING_ATOM; + } + + public Class getModelType() { + return FeedBinding.class; + } + + public FeedBinding read(XMLStreamReader reader) throws ContributionReadException { + + // Read a element + String uri = reader.getAttributeValue(null, "uri"); + FeedBinding binding = factory.createFeedBinding(); + binding.setFeedType("atom_1.0"); + if (uri != null) { + binding.setURI(uri.trim()); + } + return binding; + } + + public void write(FeedBinding binding, XMLStreamWriter writer) throws ContributionWriteException { + } + + public void resolve(FeedBinding binding, ModelResolver resolver) throws ContributionResolveException { + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/xml/RssBindingProcessor.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/xml/RssBindingProcessor.java new file mode 100644 index 0000000000..abdfcf0bff --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/src/main/java/org/apache/tuscany/sca/binding/feed/xml/RssBindingProcessor.java @@ -0,0 +1,79 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.feed.xml; + +import static org.osoa.sca.Constants.SCA_NS; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.binding.feed.FeedBinding; +import org.apache.tuscany.sca.binding.feed.FeedBindingFactory; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.contribution.service.ContributionResolveException; +import org.apache.tuscany.sca.contribution.service.ContributionWriteException; + +/** + * A processor for elements. + */ +public class RssBindingProcessor implements StAXArtifactProcessor { + + private final static QName BINDING_RSS = new QName(SCA_NS, "binding.rss"); + + private final FeedBindingFactory factory; + + /** + * Constructs a new binding processor. + * @param factory + */ + public RssBindingProcessor(FeedBindingFactory factory) { + this.factory = factory; + } + + public QName getArtifactType() { + return BINDING_RSS; + } + + public Class getModelType() { + return FeedBinding.class; + } + + public FeedBinding read(XMLStreamReader reader) throws ContributionReadException { + + // Read the element + String uri = reader.getAttributeValue(null, "uri"); + FeedBinding binding = factory.createFeedBinding(); + binding.setFeedType("rss_2.0"); + if (uri != null) { + binding.setURI(uri.trim()); + } + return binding; + } + + public void write(FeedBinding binding, XMLStreamWriter writer) throws ContributionWriteException { + } + + public void resolve(FeedBinding binding, ModelResolver resolver) throws ContributionResolveException { + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator b/sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator new file mode 100644 index 0000000000..49386b6275 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-feed/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# Implementation class for the ExtensionActivator +org.apache.tuscany.sca.binding.feed.module.FeedModuleActivator diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-jsonrpc/DISCLAIMER b/sca-java-1.x/branches/sca-java-0.91/modules/binding-jsonrpc/DISCLAIMER new file mode 100644 index 0000000000..d68a410903 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-jsonrpc/DISCLAIMER @@ -0,0 +1,8 @@ +Apache Tuscany is an effort undergoing incubation at The Apache Software +Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is +required of all newly accepted projects until a further review indicates that +the infrastructure, communications, and decision making process have stabilized +in a manner consistent with other successful ASF projects. While incubation +status is not necessarily a reflection of the completeness or stability of the +code, it does indicate that the project has yet to be fully endorsed by the ASF. + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-jsonrpc/LICENSE b/sca-java-1.x/branches/sca-java-0.91/modules/binding-jsonrpc/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-jsonrpc/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-jsonrpc/NOTICE b/sca-java-1.x/branches/sca-java-0.91/modules/binding-jsonrpc/NOTICE new file mode 100644 index 0000000000..94481d6cfa --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-jsonrpc/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2007 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-jsonrpc/pom.xml b/sca-java-1.x/branches/sca-java-0.91/modules/binding-jsonrpc/pom.xml new file mode 100644 index 0000000000..f790f53f44 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-jsonrpc/pom.xml @@ -0,0 +1,103 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 0.91-incubating-SNAPSHOT + ../pom.xml + + + tuscany-binding-jsonrpc + Apache Tuscany JSON-RPC Binding + + + + com.metaparadigm + json-rpc + 1.0 + compile + + + + net.sf.json-lib + json-lib + 0.8 + test + + + + + org.apache.tuscany.sca + tuscany-extension-helper + 0.91-incubating-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-implementation-java-runtime + 0.91-incubating-SNAPSHOT + runtime + + + + org.apache.tuscany.sca + tuscany-interface-java + 0.91-incubating-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-host-http + 0.91-incubating-SNAPSHOT + + + + javax.servlet + servlet-api + 2.4 + provided + + + + org.apache.tuscany.sca + tuscany-http-jetty + 0.91-incubating-SNAPSHOT + test + + + + junit + junit + 4.2 + test + + + + httpunit + httpunit + 1.6.1 + test + + + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCBinding.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCBinding.java new file mode 100644 index 0000000000..823803e35d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCBinding.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.jsonrpc; + +import org.apache.tuscany.sca.spi.utils.AbstractBinding; + +/** + * A model for the JSONRPC binding. + */ +public class JSONRPCBinding { + + // empty as right now the json-rpc binding has no attributes + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCBindingActivator.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCBindingActivator.java new file mode 100644 index 0000000000..fc4e050f37 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCBindingActivator.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.jsonrpc; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.http.ServletHost; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; +import org.apache.tuscany.sca.spi.BindingActivator; +import org.apache.tuscany.sca.spi.ComponentLifecycle; +import org.apache.tuscany.sca.spi.InvokerFactory; +import org.osoa.sca.ServiceRuntimeException; + +public class JSONRPCBindingActivator implements BindingActivator { + + protected ServletHost servletHost; + + public JSONRPCBindingActivator(ServletHost servletHost) { + this.servletHost = servletHost; + } + + public Class getBindingClass() { + return JSONRPCBinding.class; + } + + public InvokerFactory createInvokerFactory(RuntimeComponent rc, RuntimeComponentReference rcr, Binding b, JSONRPCBinding binding) { + throw new ServiceRuntimeException("SCA reference support not yet implemented"); + } + + public ComponentLifecycle createService(RuntimeComponent rc, RuntimeComponentService rcs, Binding b, JSONRPCBinding binding) { + return new JSONRPCService(rc, rcs, b, binding, servletHost); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCService.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCService.java new file mode 100644 index 0000000000..a7a705d5e5 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCService.java @@ -0,0 +1,118 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.jsonrpc; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.http.ServletHost; +import org.apache.tuscany.sca.interfacedef.Interface; +import org.apache.tuscany.sca.interfacedef.java.JavaInterface; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; +import org.apache.tuscany.sca.spi.ComponentLifecycle; + +/** + * Implementation of the JSONRPC binding provider. + * + * There are multiple servlets used to support the JSON-RPC binidng. + * One servlet to handle requests for the scaDomain script and seperate + * servlets for each SCA which uses . + */ +public class JSONRPCService implements ComponentLifecycle { + + private RuntimeComponent component; + private RuntimeComponentService service; + private JSONRPCBinding jsonBinding; + private ServletHost servletHost; + private Binding binding; + + public static final String SERVICE_PREFIX = "/SCADomain/"; + + // path to the scaDomain.js script + // Note: this is the same as the Ajax binding to keep the client code + // the same for clients using either the ajax or jsonrpc binding + public static final String SCA_DOMAIN_SCRIPT = SERVICE_PREFIX + "scaDomain.js"; + + + public JSONRPCService(RuntimeComponent component, + RuntimeComponentService service, + Binding b, + JSONRPCBinding binding, + ServletHost servletHost) { + this.component = component; + this.service = service; + this.binding = b; + this.jsonBinding = binding; + this.servletHost = servletHost; + } + + public void start() { + + // Create and register a servlet for this service + Class serviceInterface = getTargetJavaClass(service.getInterfaceContract().getInterface()); + Object instance = component.createSelfReference(serviceInterface).getService(); + JSONRPCServiceServlet serviceServlet = new JSONRPCServiceServlet(binding.getName(), serviceInterface, instance); + if (binding.getURI() != null) { + servletHost.addServletMapping(binding.getURI(), serviceServlet); + } else { + servletHost.addServletMapping(SERVICE_PREFIX + binding.getName(), serviceServlet); + } + + // get the ScaDomainScriptServlet, if it doesn't yet exist create one + // this uses removeServletMapping / addServletMapping as theres no getServletMapping facility + ScaDomainScriptServlet scaDomainServlet = (ScaDomainScriptServlet) servletHost.removeServletMapping(SCA_DOMAIN_SCRIPT); + if (scaDomainServlet == null) { + scaDomainServlet = new ScaDomainScriptServlet(); + } + servletHost.addServletMapping(SCA_DOMAIN_SCRIPT, scaDomainServlet); + + // Add this service to the scadomain script servlet + scaDomainServlet.addService(binding.getName()); + + } + + public void stop() { + + // Unregister from the service servlet mapping + if (binding.getURI() != null) { + servletHost.removeServletMapping(binding.getURI()); + } else { + servletHost.removeServletMapping(SERVICE_PREFIX + binding.getName()); + } + + // Unregister the service from the scaDomain script servlet + // don't unregister the scaDomain script servlet if it still has other service names + ScaDomainScriptServlet scaDomainServlet = (ScaDomainScriptServlet) servletHost.removeServletMapping(SCA_DOMAIN_SCRIPT); + if (scaDomainServlet != null) { + scaDomainServlet.removeService(binding.getName()); + // put it back if there are still other services registered with the servlet + if (scaDomainServlet.getServiceNames().size() > 0) { + servletHost.addServletMapping(SCA_DOMAIN_SCRIPT, scaDomainServlet); + } + } + } + + protected Class getTargetJavaClass(Interface targetInterface) { + // TODO: right now assume that the target is always a Java + // Implementation. Need to figure out how to generate Java + // Interface in cases where the target is not a Java Implementation + return ((JavaInterface)targetInterface).getJavaClass(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCServiceServlet.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCServiceServlet.java new file mode 100644 index 0000000000..b9eb71e259 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCServiceServlet.java @@ -0,0 +1,160 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.jsonrpc; + +import java.io.BufferedReader; +import java.io.CharArrayWriter; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.io.UnsupportedEncodingException; +import java.text.ParseException; + +import javax.servlet.ServletConfig; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; + +import org.json.JSONObject; + +import com.metaparadigm.jsonrpc.JSONRPCBridge; +import com.metaparadigm.jsonrpc.JSONRPCResult; +import com.metaparadigm.jsonrpc.JSONRPCServlet; + +/** + * Servlet that handles JSON-RPC requests invoking SCA services. + * + * There is an instance of this servlet for each + */ +public class JSONRPCServiceServlet extends JSONRPCServlet { + private static final long serialVersionUID = 1L; + + transient String serviceName; + transient Object serviceInstance; + transient Class serviceInterface; + + public JSONRPCServiceServlet(String serviceName, Class serviceInterface, Object serviceInstance) { + this.serviceName = serviceName; + this.serviceInterface = serviceInterface; + this.serviceInstance = serviceInstance; + } + + /** + * Override to do nothing as the JSONRPCServlet is setup by the + * service method in this class. + */ + @Override + public void init(ServletConfig config) { + } + + @Override + public void service(HttpServletRequest request, HttpServletResponse response) throws IOException { + + if (request.getParameter("smd") != null) { + handleSMDRequest(request, response); + } else { + try { + handleServiceRequest(request, response); + } finally { + HttpSession session = request.getSession(); + if (session != null) { + session.removeAttribute("JSONRPCBridge"); + } + } + } + } + + private void handleServiceRequest(HttpServletRequest request, HttpServletResponse response) throws IOException { + /* + * Create a new bridge for every request to aviod all the problems with + * JSON-RPC-Java storing the bridge in the session + */ + HttpSession session = request.getSession(); + + JSONRPCBridge jsonrpcBridge = new JSONRPCBridge(); + jsonrpcBridge.registerObject(serviceName, serviceInstance, serviceInterface); + session.setAttribute("JSONRPCBridge", jsonrpcBridge); + + // Encode using UTF-8, although We are actually ASCII clean as + // all unicode data is JSON escaped using backslash u. This is + // less data efficient for foreign character sets but it is + // needed to support naughty browsers such as Konqueror and Safari + // which do not honour the charset set in the response + response.setContentType("text/plain;charset=utf-8"); + OutputStream out = response.getOutputStream(); + + // Decode using the charset in the request if it exists otherwise + // use UTF-8 as this is what all browser implementations use. + // The JSON-RPC-Java JavaScript client is ASCII clean so it + // although here we can correctly handle data from other clients + // that do not escape non ASCII data + String charset = request.getCharacterEncoding(); + if (charset == null) { + charset = "UTF-8"; + } + BufferedReader in = new BufferedReader(new InputStreamReader(request.getInputStream(), charset)); + + // Read the request + CharArrayWriter data = new CharArrayWriter(); + char buf[] = new char[4096]; + int ret; + while ((ret = in.read(buf, 0, 4096)) != -1) { + data.write(buf, 0, ret); + } + + JSONObject jsonReq = null; + JSONRPCResult jsonResp = null; + try { + jsonReq = new JSONObject(data.toString()); + } catch (ParseException e) { + throw new RuntimeException("Unable to parse request", e); + } + + String method = jsonReq.getString("method"); + if ((method != null) && (method.indexOf('.') < 0)) { + jsonReq.putOpt("method", serviceName + "." + method); + } + + // invoke the request + jsonResp = jsonrpcBridge.call(new Object[] {request}, jsonReq); + + byte[] bout = jsonResp.toString().getBytes("UTF-8"); + + out.write(bout); + out.flush(); + out.close(); + } + + /** + * handles requests for the SMD descriptor for a service + */ + protected void handleSMDRequest(HttpServletRequest request, HttpServletResponse response) throws IOException, UnsupportedEncodingException { + String serviceUrl = request.getRequestURL().toString(); + String smd = JavaToSmd.interfaceToSmd(serviceInterface, serviceUrl); + + response.setContentType("text/plain;charset=utf-8"); + OutputStream out = response.getOutputStream(); + byte[] bout = smd.getBytes("UTF-8"); + + out.write(bout); + out.flush(); + out.close(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/JavaToSmd.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/JavaToSmd.java new file mode 100644 index 0000000000..196d973a76 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/JavaToSmd.java @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + package org.apache.tuscany.sca.binding.jsonrpc; + +import java.lang.reflect.Method; + +/** + * Utility class to create a Simple Method Description (SMD) descriptor + * from a Java class. See http://dojo.jot.com/SMD. + * + * TODO: Change to work from the Tuscany Interface instead of a Java class + */ +public class JavaToSmd { + + public static String interfaceToSmd(Class klazz, String serviceUrl) { + String name = klazz.getSimpleName(); + Method methods[] = klazz.getMethods(); + + StringBuffer smdSb = new StringBuffer(); + smdSb.append("{\"SMDVersion\":\".1\",\"objectName\":\"" + name + "\",\"serviceType\":\"JSON-RPC\",\"serviceURL\":\""+ serviceUrl + "\",\"methods\":["); + for (int i = 0; i < methods.length; i++) { + if (i != 0) smdSb.append(","); + Class params[] = methods[i].getParameterTypes(); + smdSb.append("{\"name\":\""+methods[i].getName() + "\",\"parameters\":["); + for (int j = 0; j < params.length; j++) { + if (j != 0) smdSb.append(","); + // right now Dojo doesn't look at the type value, so we'll default it to STRING + // also, since we can't introspect the method paramater names we'll just create an incrementing parameter name + smdSb.append("{\"name\":\"param" + j + "\",\"type\":\"STRING\"}"); + } + smdSb.append("]}"); + } + smdSb.append("]}"); + + return smdSb.toString(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/ScaDomainScriptServlet.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/ScaDomainScriptServlet.java new file mode 100644 index 0000000000..bf1b03faa1 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-jsonrpc/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/ScaDomainScriptServlet.java @@ -0,0 +1,113 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.jsonrpc; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.util.ArrayList; +import java.util.List; + +import javax.servlet.ServletOutputStream; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import static org.apache.tuscany.sca.binding.jsonrpc.JSONRPCService.SERVICE_PREFIX; + +/** + * Servlet to handle requests for the scaDomain.js script. + * + * This script wrappers the JSON-RPC-Java jsonrpc.js script + * adding in at the bottom the JavaScript to create and initialize + * the variables representing the SCA services. + */ +public class ScaDomainScriptServlet extends HttpServlet { + private static final long serialVersionUID = 1L; + + protected transient List serviceNames; + + public ScaDomainScriptServlet() { + serviceNames = new ArrayList(); + } + + public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { + + ServletOutputStream os = response.getOutputStream(); + + os.println(); + os.println("/* Apache Tuscany scaDomain.js Header */"); + os.println(); + + writeJSONRPCJavaScript(os); + writeScaDomainCode(os, request.getServletPath()); + } + + /** + * Creates a JavaScript variable within the scaDomain script for each SCA service and + * initializes its value with the JSON-RPC client to invoke the serverside service. + */ + protected void writeScaDomainCode(ServletOutputStream out, String path) throws IOException { + out.println(); + out.println("/* Apache Tuscany scaDomain.js Footer */"); + out.println(); + out.println("function scaDomain() {}"); + + // remove the leading slash '/' character + path = path.substring(1); + + for (String serviceName : serviceNames) { + out.println(); + + // A slight hack to make the service function available with a variable named 'serviceName' + // to do that the JSONRpcClient is added to the scaDomain and then the service function is got from that + out.println("scaDomain." + serviceName + " = new JSONRpcClient(\"" + path + SERVICE_PREFIX + serviceName +"\");"); + out.println(serviceName + " = scaDomain." + serviceName + "." + serviceName + ";"); + } + + out.println(); + out.println("/** End of Apache Tuscany scaDomain.js */"); + out.println(); + } + + /** + * Reads the jsonrpc.js script from the classpath and adds its contents to the output stream. + */ + protected void writeJSONRPCJavaScript(ServletOutputStream os) throws IOException { + URL url = getClass().getResource("jsonrpc.js"); + InputStream is = url.openStream(); + int i; + while ((i = is.read()) != -1) { + os.write(i); + } + } + + public void addService(String serviceName) { + serviceNames.add(serviceName); + } + + public void removeService(String serviceName) { + serviceNames.remove(serviceName); + } + + public List getServiceNames() { + return serviceNames; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-jsonrpc/src/main/resources/META-INF/services/org.apache.tuscany.sca.spi.BindingActivator b/sca-java-1.x/branches/sca-java-0.91/modules/binding-jsonrpc/src/main/resources/META-INF/services/org.apache.tuscany.sca.spi.BindingActivator new file mode 100644 index 0000000000..e35e70dacc --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-jsonrpc/src/main/resources/META-INF/services/org.apache.tuscany.sca.spi.BindingActivator @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# Implementation class for the ExtensionActivator +org.apache.tuscany.sca.binding.jsonrpc.JSONRPCBindingActivator diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-jsonrpc/src/main/resources/org/apache/tuscany/sca/binding/jsonrpc/jsonrpc.js b/sca-java-1.x/branches/sca-java-0.91/modules/binding-jsonrpc/src/main/resources/org/apache/tuscany/sca/binding/jsonrpc/jsonrpc.js new file mode 100644 index 0000000000..d837bab91c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-jsonrpc/src/main/resources/org/apache/tuscany/sca/binding/jsonrpc/jsonrpc.js @@ -0,0 +1,493 @@ +/* + * JSON-RPC JavaScript client + * + * $Id: jsonrpc.js,v 1.36.2.3 2006/03/08 15:09:37 mclark Exp $ + * + * Copyright (c) 2003-2004 Jan-Klaas Kollhof + * Copyright (c) 2005 Michael Clark, Metaparadigm Pte Ltd + * + * This code is based on Jan-Klaas' JavaScript o lait library (jsolait). + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +/* + * Modifications for Apache Tuscany: + * - JSONRpcClient_createMethod changed so callback is last arg + */ + +/* escape a character */ + +escapeJSONChar = +function escapeJSONChar(c) +{ + if(c == "\"" || c == "\\") return "\\" + c; + else if (c == "\b") return "\\b"; + else if (c == "\f") return "\\f"; + else if (c == "\n") return "\\n"; + else if (c == "\r") return "\\r"; + else if (c == "\t") return "\\t"; + var hex = c.charCodeAt(0).toString(16); + if(hex.length == 1) return "\\u000" + hex; + else if(hex.length == 2) return "\\u00" + hex; + else if(hex.length == 3) return "\\u0" + hex; + else return "\\u" + hex; +}; + + +/* encode a string into JSON format */ + +escapeJSONString = +function escapeJSONString(s) +{ + /* The following should suffice but Safari's regex is b0rken + (doesn't support callback substitutions) + return "\"" + s.replace(/([^\u0020-\u007f]|[\\\"])/g, + escapeJSONChar) + "\""; + */ + + /* Rather inefficient way to do it */ + var parts = s.split(""); + for(var i=0; i < parts.length; i++) { + var c =parts[i]; + if(c == '"' || + c == '\\' || + c.charCodeAt(0) < 32 || + c.charCodeAt(0) >= 128) + parts[i] = escapeJSONChar(parts[i]); + } + return "\"" + parts.join("") + "\""; +}; + + +/* Marshall objects to JSON format */ + +toJSON = function toJSON(o) +{ + if(o == null) { + return "null"; + } else if(o.constructor == String) { + return escapeJSONString(o); + } else if(o.constructor == Number) { + return o.toString(); + } else if(o.constructor == Boolean) { + return o.toString(); + } else if(o.constructor == Date) { + return '{javaClass: "java.util.Date", time: ' + o.valueOf() +'}'; + } else if(o.constructor == Array) { + var v = []; + for(var i = 0; i < o.length; i++) v.push(toJSON(o[i])); + return "[" + v.join(", ") + "]"; + } else { + var v = []; + for(attr in o) { + if(o[attr] == null) v.push("\"" + attr + "\": null"); + else if(typeof o[attr] == "function"); /* skip */ + else v.push(escapeJSONString(attr) + ": " + toJSON(o[attr])); + } + return "{" + v.join(", ") + "}"; + } +}; + + +/* JSONRpcClient constructor */ + +JSONRpcClient = +function JSONRpcClient_ctor(serverURL, user, pass, objectID) +{ + this.serverURL = serverURL; + this.user = user; + this.pass = pass; + this.objectID = objectID; + + /* Add standard methods */ + if(this.objectID) { + this._addMethods(["listMethods"]); + var req = this._makeRequest("listMethods", []); + } else { + this._addMethods(["system.listMethods"]); + var req = this._makeRequest("system.listMethods", []); + } + var m = this._sendRequest(req); + this._addMethods(m); +}; + + +/* JSONRpcCLient.Exception */ + +JSONRpcClient.Exception = +function JSONRpcClient_Exception_ctor(code, message, javaStack) +{ + this.code = code; + var name; + if(javaStack) { + this.javaStack = javaStack; + var m = javaStack.match(/^([^:]*)/); + if(m) name = m[0]; + } + if(name) this.name = name; + else this.name = "JSONRpcClientException"; + this.message = message; +}; + +JSONRpcClient.Exception.CODE_REMOTE_EXCEPTION = 490; +JSONRpcClient.Exception.CODE_ERR_CLIENT = 550; +JSONRpcClient.Exception.CODE_ERR_PARSE = 590; +JSONRpcClient.Exception.CODE_ERR_NOMETHOD = 591; +JSONRpcClient.Exception.CODE_ERR_UNMARSHALL = 592; +JSONRpcClient.Exception.CODE_ERR_MARSHALL = 593; + +JSONRpcClient.Exception.prototype = new Error(); + +JSONRpcClient.Exception.prototype.toString = +function JSONRpcClient_Exception_toString(code, msg) +{ + return this.name + ": " + this.message; +}; + + +/* Default top level exception handler */ + +JSONRpcClient.default_ex_handler = +function JSONRpcClient_default_ex_handler(e) { alert(e); }; + + +/* Client settable variables */ + +JSONRpcClient.toplevel_ex_handler = JSONRpcClient.default_ex_handler; +JSONRpcClient.profile_async = false; +JSONRpcClient.max_req_active = 1; +JSONRpcClient.requestId = 1; + + +/* JSONRpcClient implementation */ + +JSONRpcClient.prototype._createMethod = +function JSONRpcClient_createMethod(methodName) +{ + var fn=function() + { + var args = []; + var callback = null; + for(var i=0;i 0) { + var res = JSONRpcClient.async_responses.shift(); + if(res.canceled) continue; + if(res.profile) res.profile.dispatch = new Date(); + try { + res.cb(res.result, res.ex, res.profile); + } catch(e) { + JSONRpcClient.toplevel_ex_handler(e); + } + } + + while(JSONRpcClient.async_requests.length > 0 && + JSONRpcClient.num_req_active < JSONRpcClient.max_req_active) { + var req = JSONRpcClient.async_requests.shift(); + if(req.canceled) continue; + req.client._sendRequest.call(req.client, req); + } +}; + +JSONRpcClient.kick_async = +function JSONRpcClient_kick_async() +{ + if(JSONRpcClient.async_timeout == null) + JSONRpcClient.async_timeout = + setTimeout(JSONRpcClient._async_handler, 0); +}; + +JSONRpcClient.cancelRequest = +function JSONRpcClient_cancelRequest(requestId) +{ + /* If it is in flight then mark it as canceled in the inflight map + and the XMLHttpRequest callback will discard the reply. */ + if(JSONRpcClient.async_inflight[requestId]) { + JSONRpcClient.async_inflight[requestId].canceled = true; + return true; + } + + /* If its not in flight yet then we can just mark it as canceled in + the the request queue and it will get discarded before being sent. */ + for(var i in JSONRpcClient.async_requests) { + if(JSONRpcClient.async_requests[i].requestId == requestId) { + JSONRpcClient.async_requests[i].canceled = true; + return true; + } + } + + /* It may have returned from the network and be waiting for its callback + to be dispatched, so mark it as canceled in the response queue + and the response will get discarded before calling the callback. */ + for(var i in JSONRpcClient.async_responses) { + if(JSONRpcClient.async_responses[i].requestId == requestId) { + JSONRpcClient.async_responses[i].canceled = true; + return true; + } + } + + return false; +}; + +JSONRpcClient.prototype._makeRequest = +function JSONRpcClient_makeRequest(methodName, args, cb) +{ + var req = {}; + req.client = this; + req.requestId = JSONRpcClient.requestId++; + + var obj = {}; + obj.id = req.requestId; + if (this.objectID) + obj.method = ".obj#" + this.objectID + "." + methodName; + else + obj.method = methodName; + obj.params = args; + + if (cb) req.cb = cb; + if (JSONRpcClient.profile_async) + req.profile = { "submit": new Date() }; + req.data = toJSON(obj); + + return req; +}; + +JSONRpcClient.prototype._sendRequest = +function JSONRpcClient_sendRequest(req) +{ + if(req.profile) req.profile.start = new Date(); + + /* Get free http object from the pool */ + var http = JSONRpcClient.poolGetHTTPRequest(); + JSONRpcClient.num_req_active++; + + /* Send the request */ + if (typeof(this.user) == "undefined") { + http.open("POST", this.serverURL, (req.cb != null)); + } else { + http.open("POST", this.serverURL, (req.cb != null), this.user, this.pass); + } + + /* setRequestHeader is missing in Opera 8 Beta */ + try { http.setRequestHeader("Content-type", "text/plain"); } catch(e) {} + + /* Construct call back if we have one */ + if(req.cb) { + var self = this; + http.onreadystatechange = function() { + if(http.readyState == 4) { + http.onreadystatechange = function () {}; + var res = { "cb": req.cb, "result": null, "ex": null}; + if (req.profile) { + res.profile = req.profile; + res.profile.end = new Date(); + } + try { res.result = self._handleResponse(http); } + catch(e) { res.ex = e; } + if(!JSONRpcClient.async_inflight[req.requestId].canceled) + JSONRpcClient.async_responses.push(res); + delete JSONRpcClient.async_inflight[req.requestId]; + JSONRpcClient.kick_async(); + } + }; + } else { + http.onreadystatechange = function() {}; + } + + JSONRpcClient.async_inflight[req.requestId] = req; + + try { + http.send(req.data); + } catch(e) { + JSONRpcClient.poolReturnHTTPRequest(http); + JSONRpcClient.num_req_active--; + throw new JSONRpcClient.Exception + (JSONRpcClient.Exception.CODE_ERR_CLIENT, "Connection failed"); + } + + if(!req.cb) return this._handleResponse(http); +}; + +JSONRpcClient.prototype._handleResponse = +function JSONRpcClient_handleResponse(http) +{ + /* Get the charset */ + if(!this.charset) { + this.charset = JSONRpcClient._getCharsetFromHeaders(http); + } + + /* Get request results */ + var status, statusText, data; + try { + status = http.status; + statusText = http.statusText; + data = http.responseText; + } catch(e) { + JSONRpcClient.poolReturnHTTPRequest(http); + JSONRpcClient.num_req_active--; + JSONRpcClient.kick_async(); + throw new JSONRpcClient.Exception + (JSONRpcClient.Exception.CODE_ERR_CLIENT, "Connection failed"); + } + + /* Return http object to the pool; */ + JSONRpcClient.poolReturnHTTPRequest(http); + JSONRpcClient.num_req_active--; + + /* Unmarshall the response */ + if(status != 200) { + throw new JSONRpcClient.Exception(status, statusText); + } + var obj; + try { + eval("obj = " + data); + } catch(e) { + throw new JSONRpcClient.Exception(550, "error parsing result"); + } + if(obj.error) + throw new JSONRpcClient.Exception(obj.error.code, obj.error.msg, + obj.error.trace); + var res = obj.result; + + /* Handle CallableProxy */ + if(res && res.objectID && res.JSONRPCType == "CallableReference") + return new JSONRpcClient(this.serverURL, this.user, + this.pass, res.objectID); + + return res; +}; + + +/* XMLHttpRequest wrapper code */ + +/* XMLHttpRequest pool globals */ +JSONRpcClient.http_spare = []; +JSONRpcClient.http_max_spare = 8; + +JSONRpcClient.poolGetHTTPRequest = +function JSONRpcClient_pool_getHTTPRequest() +{ + if(JSONRpcClient.http_spare.length > 0) { + return JSONRpcClient.http_spare.pop(); + } + return JSONRpcClient.getHTTPRequest(); +}; + +JSONRpcClient.poolReturnHTTPRequest = +function JSONRpcClient_poolReturnHTTPRequest(http) +{ + if(JSONRpcClient.http_spare.length >= JSONRpcClient.http_max_spare) + delete http; + else + JSONRpcClient.http_spare.push(http); +}; + +JSONRpcClient.msxmlNames = [ "MSXML2.XMLHTTP.5.0", + "MSXML2.XMLHTTP.4.0", + "MSXML2.XMLHTTP.3.0", + "MSXML2.XMLHTTP", + "Microsoft.XMLHTTP" ]; + +JSONRpcClient.getHTTPRequest = +function JSONRpcClient_getHTTPRequest() +{ + /* Mozilla XMLHttpRequest */ + try { + JSONRpcClient.httpObjectName = "XMLHttpRequest"; + return new XMLHttpRequest(); + } catch(e) {} + + /* Microsoft MSXML ActiveX */ + for (var i=0;i < JSONRpcClient.msxmlNames.length; i++) { + try { + JSONRpcClient.httpObjectName = JSONRpcClient.msxmlNames[i]; + return new ActiveXObject(JSONRpcClient.msxmlNames[i]); + } catch (e) {} + } + + /* None found */ + JSONRpcClient.httpObjectName = null; + throw new JSONRpcClient.Exception(0, "Can't create XMLHttpRequest object"); +}; + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-jsonrpc/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/Echo.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-jsonrpc/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/Echo.java new file mode 100644 index 0000000000..584228abde --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-jsonrpc/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/Echo.java @@ -0,0 +1,29 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.jsonrpc; + +/** + * Interface of our sample JSONRPC service. + * + * @version $Rev$ $Date$ + */ +public interface Echo { + + String echo(String msg); +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-jsonrpc/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/EchoComponentImpl.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-jsonrpc/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/EchoComponentImpl.java new file mode 100644 index 0000000000..e63cafd6a6 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-jsonrpc/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/EchoComponentImpl.java @@ -0,0 +1,34 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.jsonrpc; + + + +/** + * A simple client component that uses a reference with an JSONRPC binding. + * + * @version $Rev$ $Date$ + */ +public class EchoComponentImpl implements Echo { + + public String echo(String msg) { + System.out.println("Echo: "+ msg); + return "echo: " + msg; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-jsonrpc/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCServiceTestCase.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-jsonrpc/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCServiceTestCase.java new file mode 100644 index 0000000000..eaa90d4afa --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-jsonrpc/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCServiceTestCase.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.jsonrpc; + +import java.io.ByteArrayInputStream; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.host.embedded.SCADomain; +import org.json.JSONObject; + +import com.meterware.httpunit.PostMethodWebRequest; +import com.meterware.httpunit.WebConversation; +import com.meterware.httpunit.WebRequest; +import com.meterware.httpunit.WebResponse; + +/** + * @version $Rev: 536083 $ $Date: 2007-05-08 02:18:29 -0400 (Tue, 08 May 2007) $ + */ +public class JSONRPCServiceTestCase extends TestCase { + + private static final String SERVICE_PATH = "/EchoService"; + + private static final String SERVICE_URL = "http://localhost:8085/SCADomain" + SERVICE_PATH; + + private SCADomain domain; + + protected void setUp() throws Exception { + domain = SCADomain.newInstance("JSONRPCBinding.composite"); + } + + protected void tearDown() throws Exception { + domain.close(); + } + + public void testJSONRPCBinding() throws Exception { + JSONObject jsonRequest = new JSONObject("{ \"method\": \"echo\", \"params\": [\"Hello JSON-RPC\"], \"id\": 1}"); + + WebConversation wc = new WebConversation(); + WebRequest request = new PostMethodWebRequest( SERVICE_URL, new ByteArrayInputStream(jsonRequest.toString().getBytes("UTF-8")),"application/json"); + WebResponse response = wc.getResource(request); + + assertEquals(200, response.getResponseCode()); + JSONObject jsonResp = new JSONObject(response.getText()); + assertEquals("echo: Hello JSON-RPC", jsonResp.getString("result")); + } + + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-jsonrpc/src/test/resources/JSONRPCBinding.composite b/sca-java-1.x/branches/sca-java-0.91/modules/binding-jsonrpc/src/test/resources/JSONRPCBinding.composite new file mode 100644 index 0000000000..64a712fd16 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-jsonrpc/src/test/resources/JSONRPCBinding.composite @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-rmi/.ruleset b/sca-java-1.x/branches/sca-java-0.91/modules/binding-rmi/.ruleset new file mode 100644 index 0000000000..3886f07f2d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-rmi/.ruleset @@ -0,0 +1,190 @@ + + + + PMD Plugin preferences rule set + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-rmi/DISCLAIMER b/sca-java-1.x/branches/sca-java-0.91/modules/binding-rmi/DISCLAIMER new file mode 100644 index 0000000000..d68a410903 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-rmi/DISCLAIMER @@ -0,0 +1,8 @@ +Apache Tuscany is an effort undergoing incubation at The Apache Software +Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is +required of all newly accepted projects until a further review indicates that +the infrastructure, communications, and decision making process have stabilized +in a manner consistent with other successful ASF projects. While incubation +status is not necessarily a reflection of the completeness or stability of the +code, it does indicate that the project has yet to be fully endorsed by the ASF. + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-rmi/LICENSE b/sca-java-1.x/branches/sca-java-0.91/modules/binding-rmi/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-rmi/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-rmi/NOTICE b/sca-java-1.x/branches/sca-java-0.91/modules/binding-rmi/NOTICE new file mode 100644 index 0000000000..94481d6cfa --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-rmi/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2007 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-rmi/pom.xml b/sca-java-1.x/branches/sca-java-0.91/modules/binding-rmi/pom.xml new file mode 100755 index 0000000000..b86bbfdbea --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-rmi/pom.xml @@ -0,0 +1,59 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 0.91-incubating-SNAPSHOT + ../pom.xml + + tuscany-binding-rmi + Apache Tuscany Java RMI Binding + + + + + org.apache.tuscany.sca + tuscany-extension-helper + 0.91-incubating-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-host-rmi + 0.91-incubating-SNAPSHOT + + + + cglib + cglib-nodep + 2.1_3 + + + + org.apache.tuscany.sca + tuscany-implementation-java-runtime + 0.91-incubating-SNAPSHOT + test + + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/RMIBinding.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/RMIBinding.java new file mode 100644 index 0000000000..f1ff455efe --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/RMIBinding.java @@ -0,0 +1,73 @@ +/** + * + * Copyright 2006 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.sca.binding.rmi; + +import org.apache.tuscany.sca.spi.utils.AbstractBinding; + +/** + * Represents a binding to an RMI service. + */ +public class RMIBinding extends AbstractBinding { + + private String host; + private String port; + private String serviceName; + + /** + * @return the host name of the RMI Service + */ + public String getHost() { + return host; + } + + /** + * @param rmiHostName the hostname of the RMI Service + */ + public void setHost(String rmiHostName) { + this.host = rmiHostName; + } + + /** + * @return the port number for the RMI Service + */ + public String getPort() { + return port; + } + + /** + * @param rmiPort the port number for the RMI Service + */ + public void setPort(String rmiPort) { + this.port = rmiPort; + } + + /** + * @return returns the RMI Service Name + */ + public String getServiceName() { + return serviceName; + } + + /** + * Sets the service name for the RMI Server + * + * @param rmiServiceName the name of the RMI service + */ + public void setServiceName(String rmiServiceName) { + this.serviceName = rmiServiceName; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/RMIBindingActivator.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/RMIBindingActivator.java new file mode 100644 index 0000000000..f1d2337d53 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/RMIBindingActivator.java @@ -0,0 +1,51 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.rmi; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.rmi.RMIHost; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; +import org.apache.tuscany.sca.spi.BindingActivator; +import org.apache.tuscany.sca.spi.ComponentLifecycle; +import org.apache.tuscany.sca.spi.InvokerFactory; + +public class RMIBindingActivator implements BindingActivator { + + private RMIHost rmiHost; + + public RMIBindingActivator(RMIHost rmiHost) { + this.rmiHost = rmiHost; + } + + public Class getBindingClass() { + return RMIBinding.class; + } + + public InvokerFactory createInvokerFactory(RuntimeComponent rc, RuntimeComponentReference rcr, Binding b, RMIBinding binding) { + return new RMIReferenceInvokerFactory(rc, rcr, binding, rmiHost); + } + + public ComponentLifecycle createService(RuntimeComponent rc, RuntimeComponentService rcs, Binding b, RMIBinding binding) { + return new RMIService(rc, rcs, binding, rmiHost); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/RMIReferenceInvoker.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/RMIReferenceInvoker.java new file mode 100644 index 0000000000..08d4ed6d37 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/RMIReferenceInvoker.java @@ -0,0 +1,74 @@ +/** + * * Copyright 2006 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.tuscany.sca.binding.rmi; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.rmi.Remote; + +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.rmi.RMIHost; + +public class RMIReferenceInvoker implements Invoker { + + private RMIHost rmiHost; + private String host; + private String port; + private String svcName; + private Method remoteMethod; + private Remote proxy; + + public RMIReferenceInvoker(RMIHost rmiHost, String host, String port, String svcName, Method remoteMethod) { + this.rmiHost = rmiHost; + this.remoteMethod = remoteMethod; + this.host = host; + this.port = port; + this.svcName = svcName; + } + + public Message invoke(Message msg) { + try { + + Object[] args = msg.getBody(); + Object resp = invokeTarget(args); + msg.setBody(resp); + + } catch (InvocationTargetException e) { + msg.setFaultBody(e.getCause()); + } catch (Throwable e) { + msg.setFaultBody(e); + } + + return msg; + } + + public Object invokeTarget(final Object payload) throws InvocationTargetException, SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException { + if (proxy == null) { + proxy = rmiHost.findService(host, port, svcName); + // proxy = Naming.lookup(serviceURI); + } + + remoteMethod = proxy.getClass().getMethod(remoteMethod.getName(), remoteMethod.getParameterTypes()); + + if (payload != null && !payload.getClass().isArray()) { + return remoteMethod.invoke(proxy, payload); + } else { + return remoteMethod.invoke(proxy, (Object[])payload); + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/RMIReferenceInvokerFactory.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/RMIReferenceInvokerFactory.java new file mode 100644 index 0000000000..e9d6c17e5f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/RMIReferenceInvokerFactory.java @@ -0,0 +1,59 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.rmi; + +import java.lang.reflect.Method; + +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.java.JavaInterface; +import org.apache.tuscany.sca.interfacedef.java.impl.JavaInterfaceUtil; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.rmi.RMIHost; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.apache.tuscany.sca.spi.InvokerFactory; +import org.osoa.sca.ServiceRuntimeException; + +public class RMIReferenceInvokerFactory implements InvokerFactory { + + RuntimeComponentReference reference; + RMIHost rmiHost; + RMIBinding binding; + + public RMIReferenceInvokerFactory(RuntimeComponent rc, RuntimeComponentReference rcr, RMIBinding binding, RMIHost rmiHost) { + this.reference = rcr; + this.rmiHost = rmiHost; + this.binding = binding; + } + + public Invoker createInvoker(Operation operation) { + try { + + Class iface = ((JavaInterface)reference.getInterfaceContract().getInterface()).getJavaClass(); + Method remoteMethod = JavaInterfaceUtil.findMethod(iface, operation); + + return new RMIReferenceInvoker(rmiHost, binding.getHost(), binding.getPort(), binding.getServiceName(), remoteMethod); + + } catch (NoSuchMethodException e) { + throw new ServiceRuntimeException(operation.toString(), e); + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/RMIService.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/RMIService.java new file mode 100644 index 0000000000..5e760a48d0 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-rmi/src/main/java/org/apache/tuscany/sca/binding/rmi/RMIService.java @@ -0,0 +1,178 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.rmi; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.rmi.Remote; +import java.rmi.server.UnicastRemoteObject; + +import net.sf.cglib.asm.ClassWriter; +import net.sf.cglib.asm.Constants; +import net.sf.cglib.asm.Type; +import net.sf.cglib.proxy.Enhancer; +import net.sf.cglib.proxy.MethodInterceptor; +import net.sf.cglib.proxy.MethodProxy; + +import org.apache.tuscany.sca.core.invocation.MessageImpl; +import org.apache.tuscany.sca.core.invocation.ThreadMessageContext; +import org.apache.tuscany.sca.interfacedef.Interface; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.java.JavaInterface; +import org.apache.tuscany.sca.interfacedef.java.impl.JavaInterfaceUtil; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.rmi.RMIHost; +import org.apache.tuscany.sca.rmi.RMIHostException; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; +import org.apache.tuscany.sca.spi.ComponentLifecycle; +import org.osoa.sca.ServiceRuntimeException; + +public class RMIService implements ComponentLifecycle { + + RuntimeComponent component; + RuntimeComponentService service; + private RMIBinding binding; + RMIHost rmiHost; + + public RMIService(RuntimeComponent rc, RuntimeComponentService rcs, RMIBinding binding, RMIHost rmiHost) { + this.component = rc; + this.service = rcs; + this.binding = binding; + this.rmiHost = rmiHost; + } + + public void start() { + // URI uri = URI.create(component.getURI() + "/" + binding.getName()); + // binding.setURI(uri.toString()); + + Interface serviceInterface = service.getInterfaceContract().getInterface(); + + Remote rmiProxy = createRmiService(serviceInterface); + + try { + + rmiHost.registerService(binding.getServiceName(), getPort(binding.getPort()), rmiProxy); + + } catch (RMIHostException e) { + throw new ServiceRuntimeException(e); + } + } + + public void stop() { + } + + protected int getPort(String port) { + int portNumber = RMIHost.RMI_DEFAULT_PORT; + if (port != null && port.length() > 0) { + portNumber = Integer.decode(port); + } + return portNumber; + } + + protected Remote createRmiService(final Interface serviceInterface) { + Enhancer enhancer = new Enhancer(); + enhancer.setSuperclass(UnicastRemoteObject.class); + enhancer.setCallback(new MethodInterceptor() { + public Object intercept(Object arg0, Method method, Object[] args, MethodProxy arg3) throws Throwable { + return invokeTarget(JavaInterfaceUtil.findOperation(method, serviceInterface.getOperations()), args); + } + }); + Class targetJavaInterface = getTargetJavaClass(serviceInterface); + if (!Remote.class.isAssignableFrom(targetJavaInterface)) { + RMIServiceClassLoader classloader = new RMIServiceClassLoader(getClass().getClassLoader()); + final byte[] byteCode = generateRemoteInterface(targetJavaInterface); + targetJavaInterface = classloader.defineClass(byteCode); + enhancer.setClassLoader(classloader); + } + enhancer.setInterfaces(new Class[] {targetJavaInterface}); + return (Remote)enhancer.create(); + } + + protected Object invokeTarget(Operation op, Object[] args) throws InvocationTargetException { + + Message requestMsg = new MessageImpl(); + ThreadMessageContext.setMessageContext(requestMsg); + requestMsg.setBody(args); + + Message responseMsg = service.getInvoker(binding, op).invoke(requestMsg); + + if (responseMsg.isFault()) { + throw new InvocationTargetException((Throwable)responseMsg.getBody()); + } + return responseMsg.getBody(); + } + + + /** + * if the interface of the component whose serviceBindings must be exposed as RMI Service, does not + * implement java.rmi.Remote, then generate such an interface. This method will stop with just + * generating the bytecode. Defining the class from the byte code must be the responsibility of the + * caller of this method, since it requires a classloader to be created to define and load this interface. + */ + protected byte[] generateRemoteInterface(Class serviceInterface) { + String interfazeName = serviceInterface.getCanonicalName(); + ClassWriter cw = new ClassWriter(false); + + String simpleName = serviceInterface.getSimpleName(); + cw.visit(Constants.V1_5, Constants.ACC_PUBLIC + Constants.ACC_ABSTRACT + Constants.ACC_INTERFACE, interfazeName + .replace('.', '/'), "java/lang/Object", new String[] {"java/rmi/Remote"}, simpleName + ".java"); + + StringBuffer argsAndReturn = null; + Method[] methods = serviceInterface.getMethods(); + for (Method method : methods) { + argsAndReturn = new StringBuffer("("); + Class[] paramTypes = method.getParameterTypes(); + Class returnType = method.getReturnType(); + + for (Class paramType : paramTypes) { + argsAndReturn.append(Type.getType(paramType)); + } + argsAndReturn.append(")"); + argsAndReturn.append(Type.getType(returnType)); + + cw.visitMethod(Constants.ACC_PUBLIC + Constants.ACC_ABSTRACT, + method.getName(), + argsAndReturn.toString(), + new String[] {"java/rmi/RemoteException"}, + null); + } + cw.visitEnd(); + return cw.toByteArray(); + } + + protected Class getTargetJavaClass(Interface targetInterface) { + // TODO: right now assume that the target is always a Java + // Implementation. Need to figure out + // how to generate Java Interface in cases where the target is not a + // Java Implementation + return ((JavaInterface)targetInterface).getJavaClass(); + } + + protected class RMIServiceClassLoader extends ClassLoader { + public RMIServiceClassLoader(ClassLoader parent) { + super(parent); + } + + public Class defineClass(byte[] byteArray) { + return defineClass(null, byteArray, 0, byteArray.length); + } + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-rmi/src/main/resources/META-INF/services/org.apache.tuscany.sca.spi.BindingActivator b/sca-java-1.x/branches/sca-java-0.91/modules/binding-rmi/src/main/resources/META-INF/services/org.apache.tuscany.sca.spi.BindingActivator new file mode 100644 index 0000000000..582f321be9 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-rmi/src/main/resources/META-INF/services/org.apache.tuscany.sca.spi.BindingActivator @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# Implementation class for the ExtensionActivator +org.apache.tuscany.sca.binding.rmi.RMIBindingActivator diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-rmi/src/test/java/helloworld/HelloWorldImpl.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-rmi/src/test/java/helloworld/HelloWorldImpl.java new file mode 100644 index 0000000000..acb81a00f6 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-rmi/src/test/java/helloworld/HelloWorldImpl.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package helloworld; + +import org.osoa.sca.annotations.Service; + + +/** + * This class implements the HelloWorld service. + */ +@Service(HelloWorldService.class) +public class HelloWorldImpl implements HelloWorldService { + + public String sayHello(String name) { + return "Hello from the RMI Service to - " + name; + } + + public String sayHi(String name, String greeter) { + return "Hi from " + greeter + " in RMI Service to - " + name; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-rmi/src/test/java/helloworld/HelloWorldRmiImpl.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-rmi/src/test/java/helloworld/HelloWorldRmiImpl.java new file mode 100644 index 0000000000..73aedc3b6c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-rmi/src/test/java/helloworld/HelloWorldRmiImpl.java @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package helloworld; + +import org.osoa.sca.annotations.Reference; +import org.osoa.sca.annotations.Service; + +/** + * This class implements the HelloWorld service. + */ +@Service(HelloWorldRmiService.class) +public class HelloWorldRmiImpl implements HelloWorldRmiService { + private HelloWorldService extService; + + public HelloWorldService getExtService() { + return extService; + } + + @Reference + public void setExtService(HelloWorldService extService) { + this.extService = extService; + } + + public String sayRmiHello(String name) { + return extService.sayHello(name) + " thro the RMI Reference"; + } + + public String sayRmiHi(String name, String greeter) { + return extService.sayHi(name, greeter) + " thro the RMI Reference"; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-rmi/src/test/java/helloworld/HelloWorldRmiService.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-rmi/src/test/java/helloworld/HelloWorldRmiService.java new file mode 100644 index 0000000000..f636c8f7d8 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-rmi/src/test/java/helloworld/HelloWorldRmiService.java @@ -0,0 +1,29 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package helloworld; + +/** + * This is the business interface of the HelloWorld greetings service. + */ +public interface HelloWorldRmiService { + + String sayRmiHello(String name); + String sayRmiHi(String name, String greeter); + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-rmi/src/test/java/helloworld/HelloWorldService.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-rmi/src/test/java/helloworld/HelloWorldService.java new file mode 100644 index 0000000000..d5dc509f3e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-rmi/src/test/java/helloworld/HelloWorldService.java @@ -0,0 +1,29 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package helloworld; + +/** + * This is the business interface of the HelloWorld greetings service. + */ +public interface HelloWorldService { + + String sayHello(String name); + String sayHi(String name, String greeter); + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-rmi/src/test/java/org/apache/tuscany/sca/binding/rmi/BindingTestCase.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-rmi/src/test/java/org/apache/tuscany/sca/binding/rmi/BindingTestCase.java new file mode 100644 index 0000000000..e626293c6e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-rmi/src/test/java/org/apache/tuscany/sca/binding/rmi/BindingTestCase.java @@ -0,0 +1,63 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.rmi; + +import helloworld.HelloWorldRmiService; +import junit.framework.Assert; + +import org.apache.tuscany.sca.host.embedded.SCADomain; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +public class BindingTestCase { + private static HelloWorldRmiService helloWorldRmiService; + private static SCADomain domain; + + @Test + public void testRmiService() { + System.out.println(helloWorldRmiService.sayRmiHello("Tuscany World!")); + Assert.assertEquals("Hello from the RMI Service to - Tuscany World! thro the RMI Reference", + helloWorldRmiService.sayRmiHello("Tuscany World!")); + + System.out.println(helloWorldRmiService.sayRmiHi("Tuscany World!", "Apache World")); + + Assert.assertEquals("Hi from Apache World in RMI Service to - Tuscany World! thro the RMI Reference", + helloWorldRmiService.sayRmiHi("Tuscany World!", "Apache World")); + } + + + + @BeforeClass + public static void init() throws Exception { +try { + domain = SCADomain.newInstance("RMIBindingTest.composite"); + helloWorldRmiService = + domain.getService(HelloWorldRmiService.class, "HelloWorldRmiServiceComponent"); +} catch (Exception e) { + e.printStackTrace(); +} + } + + @AfterClass + public static void destroy() throws Exception { + domain.close(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-rmi/src/test/resources/HelloWorldImpl.componentType b/sca-java-1.x/branches/sca-java-0.91/modules/binding-rmi/src/test/resources/HelloWorldImpl.componentType new file mode 100644 index 0000000000..224a68f88d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-rmi/src/test/resources/HelloWorldImpl.componentType @@ -0,0 +1,23 @@ + + + + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-rmi/src/test/resources/HelloWorldRmiImpl.componentType b/sca-java-1.x/branches/sca-java-0.91/modules/binding-rmi/src/test/resources/HelloWorldRmiImpl.componentType new file mode 100644 index 0000000000..a83e7e6d1d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-rmi/src/test/resources/HelloWorldRmiImpl.componentType @@ -0,0 +1,27 @@ + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-rmi/src/test/resources/RMIBindingTest.composite b/sca-java-1.x/branches/sca-java-0.91/modules/binding-rmi/src/test/resources/RMIBindingTest.composite new file mode 100644 index 0000000000..0eb6b1cfe2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-rmi/src/test/resources/RMIBindingTest.composite @@ -0,0 +1,43 @@ + + + + + + + + HelloWorldServiceComponent + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/DISCLAIMER b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/DISCLAIMER new file mode 100644 index 0000000000..d68a410903 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/DISCLAIMER @@ -0,0 +1,8 @@ +Apache Tuscany is an effort undergoing incubation at The Apache Software +Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is +required of all newly accepted projects until a further review indicates that +the infrastructure, communications, and decision making process have stabilized +in a manner consistent with other successful ASF projects. While incubation +status is not necessarily a reflection of the completeness or stability of the +code, it does indicate that the project has yet to be fully endorsed by the ASF. + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/LICENSE b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/NOTICE b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/NOTICE new file mode 100644 index 0000000000..94481d6cfa --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2007 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/pom.xml b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/pom.xml new file mode 100755 index 0000000000..db56f1a35b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/pom.xml @@ -0,0 +1,181 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 0.91-incubating-SNAPSHOT + ../pom.xml + + + tuscany-binding-ws-axis2 + Apache Tuscany Web Services Binding using Apache Axis2 + + + + apache.ws + Apache WebServices Repository + http://ws.zones.apache.org/repository/ + legacy + + + + + + org.apache.tuscany.sca + tuscany-core + 0.91-incubating-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-interface-wsdl-xml + 0.91-incubating-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-assembly-xml + 0.91-incubating-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-binding-ws-xml + 0.91-incubating-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-core-databinding + 0.91-incubating-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-databinding-axiom + 0.91-incubating-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-host-http + 0.91-incubating-SNAPSHOT + + + + org.apache.axis2 + axis2-kernel + 1.2 + + + org.codehaus.woodstox + wstx-asl + + + + + + org.apache.ws.commons.axiom + axiom-api + 1.2.4 + + + + org.apache.ws.commons.axiom + axiom-impl + 1.2.4 + + + + org.apache.woden + woden + 1.0-incubating-M7a + runtime + + + + commons-logging + commons-logging + 1.1 + + + + org.apache.neethi + neethi + 2.0.1 + + + + org.apache.ws.commons.schema + XmlSchema + 1.3.1 + + + + commons-httpclient + commons-httpclient + 3.0.1 + + + + javax.mail + mail + 1.4 + + + + backport-util-concurrent + backport-util-concurrent + 2.2 + runtime + + + + commons-codec + commons-codec + 1.3 + runtime + + + + org.apache.tuscany.sca + tuscany-http-jetty + 0.91-incubating-SNAPSHOT + test + + + + org.apache.tuscany.sca + tuscany-host-embedded + 0.91-incubating-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-implementation-java-runtime + 0.91-incubating-SNAPSHOT + test + + + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/main/assembly/axis2.xml b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/main/assembly/axis2.xml new file mode 100644 index 0000000000..52a61790ca --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/main/assembly/axis2.xml @@ -0,0 +1,306 @@ + + + + + + + false + false + false + false + + + + + + 30 + + + + true + + + + + + false + + admin + axis2 + + + + + + + + + + + + + + false + + + + + + + true + + + false + + + false + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 6060 + + + + + + + + + + + + + + + + + + + + + + + + 6060 + + + + + + + + + + + + + HTTP/1.1 + chunked + + + HTTP/1.1 + chunked + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/Axis2AsyncBindingInvoker.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/Axis2AsyncBindingInvoker.java new file mode 100644 index 0000000000..e2517e02d8 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/Axis2AsyncBindingInvoker.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.axis2; + +import java.lang.reflect.InvocationTargetException; +import java.util.concurrent.CountDownLatch; + +import javax.xml.namespace.QName; + +import org.apache.axiom.soap.SOAPFactory; +import org.apache.axis2.AxisFault; +import org.apache.axis2.client.OperationClient; +import org.apache.axis2.client.Options; +import org.apache.axis2.client.ServiceClient; + +public class Axis2AsyncBindingInvoker extends Axis2BindingInvoker { + + private Axis2ReferenceCallbackTargetInvoker callbackInvoker; + + public Axis2AsyncBindingInvoker(ServiceClient serviceClient, + QName wsdlOperationName, + Options options, + SOAPFactory soapFactory) { + super(serviceClient, wsdlOperationName, options, soapFactory); + } + + private Object invokeTarget(final Object payload, String conversationId) + throws InvocationTargetException { + try { + Object[] args = (Object[]) payload; + OperationClient operationClient = createOperationClient(args, conversationId); + Axis2ReferenceCallback callback = new Axis2ReferenceCallback(callbackInvoker); + operationClient.setCallback(callback); + + // FIXME Synchronize with callback thread to get return value + CountDownLatch doneSignal = new CountDownLatch(1); + callbackInvoker.setSignal(doneSignal); + + operationClient.execute(false); + + try { + doneSignal.await(); + } catch(InterruptedException e) { + e.printStackTrace(); + } + + // FIXME returning value from callback thread + Object response = callbackInvoker.getReturnPayload(); + return response; + } catch (AxisFault e) { + throw new InvocationTargetException(e); + } + } + + public void setCallbackTargetInvoker(Axis2ReferenceCallbackTargetInvoker callbackInvoker) { + this.callbackInvoker = callbackInvoker; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/Axis2BindingInvoker.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/Axis2BindingInvoker.java new file mode 100644 index 0000000000..fe33416f8b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/Axis2BindingInvoker.java @@ -0,0 +1,146 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.axis2; + +import java.lang.reflect.InvocationTargetException; + +import javax.xml.namespace.QName; + +import org.apache.axiom.om.OMElement; +import org.apache.axiom.soap.SOAPBody; +import org.apache.axiom.soap.SOAPEnvelope; +import org.apache.axiom.soap.SOAPFactory; +import org.apache.axiom.soap.SOAPHeader; +import org.apache.axis2.AxisFault; +import org.apache.axis2.addressing.AddressingConstants; +import org.apache.axis2.addressing.EndpointReference; +import org.apache.axis2.client.OperationClient; +import org.apache.axis2.client.Options; +import org.apache.axis2.client.ServiceClient; +import org.apache.axis2.context.MessageContext; +import org.apache.axis2.transport.http.HTTPConstants; +import org.apache.axis2.wsdl.WSDLConstants; +import org.apache.tuscany.sca.interfacedef.ConversationSequence; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.osoa.sca.Constants; + +/** + * Axis2BindingInvoker uses an Axis2 OperationClient to invoke a remote web service + */ +public class Axis2BindingInvoker implements Invoker { + + private ServiceClient serviceClient; + private QName wsdlOperationName; + private Options options; + private SOAPFactory soapFactory; + + public static final QName CONVERSATION_ID_REFPARM_QN = new QName(Constants.SCA_NS,"conversationID"); + + public Axis2BindingInvoker(ServiceClient serviceClient, QName wsdlOperationName, + Options options, SOAPFactory soapFactory) { + this.serviceClient = serviceClient; + this.wsdlOperationName = wsdlOperationName; + this.options = options; + this.soapFactory = soapFactory; + } + + public Message invoke(Message msg) { + try { + // getCallbackUris() has been removed from the Message interface + // LinkedList callbackRoutingChain = msg.getCallbackUris(); + // if (callbackRoutingChain != null) { + // workContext.setCallbackUris(callbackRoutingChain); + // } + Object resp = invokeTarget(msg.getBody(), msg.getConversationSequence(), msg.getConversationID()); + msg.setBody(resp); + } catch (InvocationTargetException e) { + msg.setFaultBody(e.getCause()); + } catch (Throwable e) { + msg.setFaultBody(e); + } + return msg; + } + + protected Object invokeTarget(final Object payload, final ConversationSequence sequence, String conversationId) throws InvocationTargetException { + try { + + Object[] args = (Object[]) payload; + OperationClient operationClient = createOperationClient(args, conversationId); + + // ensure connections are tracked so that they can be closed by the reference binding + MessageContext requestMC = operationClient.getMessageContext(WSDLConstants.MESSAGE_LABEL_OUT_VALUE); + requestMC.getOptions().setProperty(HTTPConstants.REUSE_HTTP_CLIENT, Boolean.TRUE); + requestMC.getOptions().setTimeOutInMilliSeconds(120000L); + + operationClient.execute(true); + + MessageContext responseMC = operationClient.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE); + + operationClient.complete(requestMC); + + return responseMC.getEnvelope().getBody().getFirstElement(); + + } catch (AxisFault e) { + throw new InvocationTargetException(e); + } + } + + @SuppressWarnings("deprecation") + protected OperationClient createOperationClient(Object[] args, String conversationId) throws AxisFault { + SOAPEnvelope env = soapFactory.getDefaultEnvelope(); + if (args != null && args.length > 0) { + SOAPBody body = env.getBody(); + for (Object bc : args) { + if (bc instanceof OMElement) { + body.addChild((OMElement) bc); + } else { + throw new IllegalArgumentException( + "Can't handle mixed payloads betweem OMElements and other types."); + } + } + } + MessageContext requestMC = new MessageContext(); + requestMC.setEnvelope(env); + + // Axis2 operationClients can not be shared so create a new one for each request + OperationClient operationClient = serviceClient.createClient(wsdlOperationName); + + if (conversationId != null && conversationId.length() != 0) { + EndpointReference fromEPR = new EndpointReference(AddressingConstants.Final.WSA_ANONYMOUS_URL); + fromEPR.addReferenceParameter(CONVERSATION_ID_REFPARM_QN, conversationId); + options.setFrom(fromEPR); + requestMC.setFrom(fromEPR); //who knows why two ways ? + + //For now do this the brute force method. Need to figure out how to do axis addressing .. configure mar in flow. + SOAPEnvelope sev = requestMC.getEnvelope(); + SOAPHeader sh = sev.getHeader(); + OMElement el = fromEPR.toOM(AddressingConstants.Final.WSA_NAMESPACE, + AddressingConstants.WSA_FROM, + AddressingConstants.WSA_DEFAULT_PREFIX); + sh.addChild(el); + } + + operationClient.setOptions(options); + operationClient.addMessageContext(requestMC); + + return operationClient; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/Axis2BindingProviderFactory.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/Axis2BindingProviderFactory.java new file mode 100644 index 0000000000..f6631d7e1f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/Axis2BindingProviderFactory.java @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.axis2; + +import org.apache.tuscany.sca.binding.ws.WebServiceBinding; +import org.apache.tuscany.sca.http.ServletHost; +import org.apache.tuscany.sca.invocation.MessageFactory; +import org.apache.tuscany.sca.provider.BindingProviderFactory; +import org.apache.tuscany.sca.provider.ReferenceBindingProvider; +import org.apache.tuscany.sca.provider.ServiceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + +/** + * Axis2BindingProviderFactory + * + * @version $Rev$ $Date$ + */ + +public class Axis2BindingProviderFactory implements BindingProviderFactory { + + private MessageFactory messageFactory; + private ServletHost servletHost; + + public Axis2BindingProviderFactory(ServletHost servletHost, MessageFactory messageFactory) { + this.servletHost = servletHost; + this.messageFactory = messageFactory; + } + + public ReferenceBindingProvider createReferenceBindingProvider(RuntimeComponent component, RuntimeComponentReference reference, WebServiceBinding binding) { + return new Axis2ReferenceBindingProvider(component, reference, binding, messageFactory); + } + + public ServiceBindingProvider createServiceBindingProvider(RuntimeComponent component, RuntimeComponentService service, WebServiceBinding binding) { + return new Axis2ServiceBindingProvider(component, service, binding, servletHost, messageFactory); + } + + public Class getModelType() { + return WebServiceBinding.class; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/Axis2CallbackInvocationHandler.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/Axis2CallbackInvocationHandler.java new file mode 100644 index 0000000000..91d0f05bde --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/Axis2CallbackInvocationHandler.java @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.axis2; + +import java.net.URI; +import java.util.LinkedList; + +import org.apache.tuscany.sca.core.invocation.AbstractInvocationHandler; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.MessageFactory; +import org.apache.tuscany.sca.runtime.RuntimeWire; + +public class Axis2CallbackInvocationHandler extends AbstractInvocationHandler { + + private RuntimeWire wire; + + public Axis2CallbackInvocationHandler(MessageFactory messageFactory, RuntimeWire wire) { + super(messageFactory, false); + this.wire = wire; + } + + public Object invoke(Operation operation, Object[] args, LinkedList callbackRoutingChain) throws Throwable { +// Object targetAddress = callbackRoutingChain.removeFirst(); +// if (targetAddress == null) { +// throw new AssertionError("Popped a null from address from stack"); +// } + +// //TODO optimize as this is slow in local invocations +// Map sourceCallbackInvocationChains = +// wire.getCallbackInvocationChains(); +// InvocationChain chain = sourceCallbackInvocationChains.get(operation); +// chain.g +// TargetInvoker invoker = chain.getTargetInvoker(); +// return invoke(chain, invoker, args, null, callbackRoutingChain, null); + throw new UnsupportedOperationException("not yet implemented"); + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/Axis2ModuleActivator.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/Axis2ModuleActivator.java new file mode 100644 index 0000000000..50e916c084 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/Axis2ModuleActivator.java @@ -0,0 +1,70 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.axis2; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.binding.ws.DefaultWebServiceBindingFactory; +import org.apache.tuscany.sca.binding.ws.WebServiceBindingFactory; +import org.apache.tuscany.sca.binding.ws.xml.WebServiceBindingProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.core.ModuleActivator; +import org.apache.tuscany.sca.http.ServletHost; +import org.apache.tuscany.sca.interfacedef.wsdl.DefaultWSDLFactory; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLFactory; +import org.apache.tuscany.sca.interfacedef.wsdl.introspect.DefaultWSDLInterfaceIntrospector; +import org.apache.tuscany.sca.interfacedef.wsdl.introspect.WSDLInterfaceIntrospector; +import org.apache.tuscany.sca.invocation.MessageFactory; +import org.apache.tuscany.sca.policy.PolicyFactory; +import org.apache.tuscany.sca.provider.ProviderFactoryExtensionPoint; + +public class Axis2ModuleActivator implements ModuleActivator { + + public void start(ExtensionPointRegistry registry) { + + ModelFactoryExtensionPoint factories = registry.getExtensionPoint(ModelFactoryExtensionPoint.class); + AssemblyFactory assemblyFactory = factories.getFactory(AssemblyFactory.class); + PolicyFactory policyFactory = factories.getFactory(PolicyFactory.class); + MessageFactory messageFactory = factories.getFactory(MessageFactory.class); + + WebServiceBindingFactory wsFactory = new DefaultWebServiceBindingFactory(); + WSDLFactory wsdlFactory = new DefaultWSDLFactory(); + + StAXArtifactProcessorExtensionPoint processors = registry.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); + WSDLInterfaceIntrospector introspector = new DefaultWSDLInterfaceIntrospector(wsdlFactory); + WebServiceBindingProcessor processor = + new WebServiceBindingProcessor(assemblyFactory, policyFactory, wsFactory, wsdlFactory, introspector); + processors.addArtifactProcessor(processor); + + ProviderFactoryExtensionPoint providerFactories = registry.getExtensionPoint(ProviderFactoryExtensionPoint.class); + ServletHost servletHost = registry.getExtensionPoint(ServletHost.class); + Axis2BindingProviderFactory providerFactory = new Axis2BindingProviderFactory(servletHost, messageFactory); + providerFactories.addProviderFactory(providerFactory); + } + + public void stop(ExtensionPointRegistry registry) { + } + + public Object[] getExtensionPoints() { + return null; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/Axis2OneWayBindingInvoker.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/Axis2OneWayBindingInvoker.java new file mode 100644 index 0000000000..fb95022c6b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/Axis2OneWayBindingInvoker.java @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.axis2; + +import java.lang.reflect.InvocationTargetException; + +import javax.xml.namespace.QName; + +import org.apache.axiom.soap.SOAPFactory; +import org.apache.axis2.AxisFault; +import org.apache.axis2.client.OperationClient; +import org.apache.axis2.client.Options; +import org.apache.axis2.client.ServiceClient; + +public class Axis2OneWayBindingInvoker extends Axis2BindingInvoker { + + public Axis2OneWayBindingInvoker(ServiceClient serviceClient, + QName wsdlOperationName, + Options options, + SOAPFactory soapFactory) { + + super(serviceClient, wsdlOperationName, options, soapFactory); + } + + protected Object invokeTarget(final Object payload, final short sequence, String conversationId) throws InvocationTargetException { + try { + Object[] args = (Object[]) payload; + + OperationClient operationClient = createOperationClient(args, conversationId); + operationClient.execute(false); + + // REVIEW it seems ok to return null + return null; + + } catch (AxisFault e) { + throw new InvocationTargetException(e); + } catch (Throwable t) { + throw new InvocationTargetException(t); + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/Axis2ReferenceBindingProvider.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/Axis2ReferenceBindingProvider.java new file mode 100644 index 0000000000..98994aa917 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/Axis2ReferenceBindingProvider.java @@ -0,0 +1,267 @@ +/** + * + * Copyright 2006 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.tuscany.sca.binding.axis2; + +import java.util.List; + +import javax.wsdl.Binding; +import javax.wsdl.BindingOperation; +import javax.wsdl.Definition; +import javax.wsdl.extensions.soap.SOAPAddress; +import javax.wsdl.extensions.soap.SOAPOperation; +import javax.xml.namespace.QName; + +import org.apache.axiom.om.OMAbstractFactory; +import org.apache.axiom.om.OMElement; +import org.apache.axiom.soap.SOAPFactory; +import org.apache.axis2.AxisFault; +import org.apache.axis2.addressing.EndpointReference; +import org.apache.axis2.client.Options; +import org.apache.axis2.client.ServiceClient; +import org.apache.axis2.context.ConfigurationContext; +import org.apache.axis2.description.AxisService; +import org.apache.axis2.transport.http.HTTPConstants; +import org.apache.commons.httpclient.HttpClient; +import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager; +import org.apache.tuscany.sca.binding.ws.WebServiceBinding; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.MessageFactory; +import org.apache.tuscany.sca.provider.ReferenceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.apache.tuscany.sca.runtime.RuntimeWire; + +public class Axis2ReferenceBindingProvider implements ReferenceBindingProvider { + + private MessageFactory messageFactory; + private RuntimeComponent component; + private RuntimeComponentReference reference; + private WebServiceBinding wsBinding; + private ConfigurationContext configContext; + private ServiceClient serviceClient; + + public Axis2ReferenceBindingProvider(RuntimeComponent component, + RuntimeComponentReference reference, + WebServiceBinding wsBinding, + MessageFactory messageFactory) { + + this.component = component; + this.reference = reference; + this.wsBinding = wsBinding; + this.messageFactory = messageFactory; + + try { + TuscanyAxisConfigurator tuscanyAxisConfigurator = new TuscanyAxisConfigurator(); + configContext = tuscanyAxisConfigurator.getConfigurationContext(); + } catch (AxisFault e) { + throw new RuntimeException(e); // TODO: better exception + } + initServiceClient(); + } + + // methods for ReferenceBindingActivator + + public void initServiceClient() { + InterfaceContract contract = wsBinding.getBindingInterfaceContract(); + if (contract == null) { + contract = reference.getInterfaceContract(); + wsBinding.setBindingInterfaceContract(contract); + } + + // Set to use the Axiom data binding + contract.getInterface().setDefaultDataBinding(OMElement.class.getName()); + + // ??? following line was in Axis2BindingBuilder before the SPI changes + // and code reorg + // + // URI targetURI = wsBinding.getURI() != null ? + // URI.create(wsBinding.getURI()) : URI.create("foo"); + // + // targetURI was passed to the ReferenceBindingExtension constructor and + // apparently was unused + // Do we still need a targetURI? + + // wsBinding.setURI(component.getURI() + "#" + reference.getName()); + + // create an Axis2 ServiceClient + serviceClient = createServiceClient(); + } + + public void start() { + } + + public void stop() { + + // close all connections that we have initiated, so that the jetty + // server + // can be restarted without seeing ConnectExceptions + HttpClient httpClient = (HttpClient)serviceClient.getServiceContext().getConfigurationContext() + .getProperty(HTTPConstants.CACHED_HTTP_CLIENT); + if (httpClient != null) + ((MultiThreadedHttpConnectionManager)httpClient.getHttpConnectionManager()).shutdown(); + } + + /** + * Create an Axis2 ServiceClient + */ + protected ServiceClient createServiceClient() { + try { + QName serviceQName = wsBinding.getServiceName(); + String portName = wsBinding.getPortName(); + Definition wsdlDefinition = wsBinding.getWSDLDefinition().getDefinition(); + AxisService axisService = AxisService.createClientSideAxisService(wsdlDefinition, + serviceQName, + portName, + new Options()); + + return new ServiceClient(configContext, axisService); + } catch (AxisFault e) { + throw new RuntimeException(e); // TODO: better exception + } + } + + // methods for ReferenceBindingProvider + + public InterfaceContract getBindingInterfaceContract() { + return wsBinding.getBindingInterfaceContract(); + } + + public Invoker createInvoker(Operation operation, boolean isCallback) { + + Axis2BindingInvoker invoker; + + InterfaceContract contract = wsBinding.getBindingInterfaceContract(); + if (contract == null) { + contract = reference.getInterfaceContract(); + wsBinding.setBindingInterfaceContract(contract); + } + + if (wsBinding.getBindingInterfaceContract().getCallbackInterface() == null) { + invoker = createOperationInvoker(serviceClient, operation, false, operation.isNonBlocking()); + } else { + // FIXME: SDODataBinding needs to pass in TypeHelper and classLoader + // as parameters. + + // FIXME: This makes the (BIG) assumption that there is only one + // callback method + // Relaxing this assumption, however, does not seem to be trivial, + // it may depend on knowledge + // of what actual callback method was invoked by the service at the + // other end + + RuntimeWire wire = reference.getRuntimeWire(wsBinding); + Operation callbackOperation = findCallbackOperation(wire); + Axis2CallbackInvocationHandler invocationHandler = new Axis2CallbackInvocationHandler(messageFactory, wire); + Axis2ReferenceCallbackTargetInvoker callbackInvoker = new Axis2ReferenceCallbackTargetInvoker( + callbackOperation, + wire, + invocationHandler); + + Axis2AsyncBindingInvoker asyncInvoker = (Axis2AsyncBindingInvoker)createOperationInvoker(serviceClient, + operation, + true, + false); + asyncInvoker.setCallbackTargetInvoker(callbackInvoker); + invoker = asyncInvoker; + } + + return invoker; + } + + private Operation findCallbackOperation(RuntimeWire wire) { + InterfaceContract contract = wire.getTarget().getInterfaceContract(); // TODO: + // which + // end? + List callbackOperations = contract.getCallbackInterface().getOperations(); + if (callbackOperations.size() != 1) { + throw new RuntimeException("Can only handle one callback operation"); + } + Operation callbackOperation = (Operation)callbackOperations.get(0); + return callbackOperation; + } + + /** + * Create and configure an Axis2BindingInvoker for each operation + */ + private Axis2BindingInvoker createOperationInvoker(ServiceClient serviceClient, + Operation operation, + boolean hasCallback, + boolean isOneWay) { + + Options options = new Options(); + options.setTo(getPortLocationEPR()); + options.setProperty(HTTPConstants.CHUNKED, Boolean.FALSE); + + String operationName = operation.getName(); + + String soapAction = getSOAPAction(operationName); + if (soapAction != null && soapAction.length() > 1) { + options.setAction(soapAction); + } + + options.setTimeOutInMilliSeconds(30 * 1000); // 30 seconds + + SOAPFactory soapFactory = OMAbstractFactory.getSOAP11Factory(); + QName wsdlOperationQName = new QName(operationName); + + Axis2BindingInvoker invoker; + if (hasCallback) { + invoker = new Axis2AsyncBindingInvoker(serviceClient, wsdlOperationQName, options, soapFactory); + } else if (isOneWay) { + invoker = new Axis2OneWayBindingInvoker(serviceClient, wsdlOperationQName, options, soapFactory); + } else { + invoker = new Axis2BindingInvoker(serviceClient, wsdlOperationQName, options, soapFactory); + } + + return invoker; + } + + protected EndpointReference getPortLocationEPR() { + String ep = wsBinding.getURI(); + if (ep == null && wsBinding.getPort() != null) { + List wsdlPortExtensions = wsBinding.getPort().getExtensibilityElements(); + for (final Object extension : wsdlPortExtensions) { + if (extension instanceof SOAPAddress) { + ep = ((SOAPAddress)extension).getLocationURI(); + break; + } + } + } + return new EndpointReference(ep); + } + + protected String getSOAPAction(String operationName) { + Binding binding = wsBinding.getBinding(); + if (binding != null) { + for (Object o : binding.getBindingOperations()) { + BindingOperation bop = (BindingOperation)o; + if (bop.getName().equalsIgnoreCase(operationName)) { + for (Object o2 : bop.getExtensibilityElements()) { + if (o2 instanceof SOAPOperation) { + return ((SOAPOperation)o2).getSoapActionURI(); + } + } + } + } + } + return null; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/Axis2ReferenceCallback.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/Axis2ReferenceCallback.java new file mode 100644 index 0000000000..cbc82f9c68 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/Axis2ReferenceCallback.java @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.axis2; + +import java.lang.reflect.InvocationTargetException; + +import org.apache.axiom.om.OMElement; +import org.apache.axis2.client.async.AsyncResult; +import org.apache.axis2.client.async.Callback; +import org.apache.axis2.context.MessageContext; + +public class Axis2ReferenceCallback extends Callback { + + private Axis2ReferenceCallbackTargetInvoker targetInvoker; + + public Axis2ReferenceCallback(Axis2ReferenceCallbackTargetInvoker targetInvoker) { + this.targetInvoker = targetInvoker; + } + + public void onComplete(AsyncResult result) { + MessageContext responseMC = result.getResponseMessageContext(); + OMElement responseOM = responseMC.getEnvelope().getBody().getFirstElement(); + try { + targetInvoker.invokeTarget(new Object[] {responseOM}, null); + } catch (InvocationTargetException e) { + // FIXME what is the appropriate exception here? + throw new RuntimeException(e); + } + } + + public void setComplete(boolean complete) { + super.setComplete(complete); + } + + public void onError(Exception e) { + throw new RuntimeException(e); + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/Axis2ReferenceCallbackTargetInvoker.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/Axis2ReferenceCallbackTargetInvoker.java new file mode 100644 index 0000000000..dce9bf8cf1 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/Axis2ReferenceCallbackTargetInvoker.java @@ -0,0 +1,108 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.axis2; + +import java.lang.reflect.InvocationTargetException; +import java.util.concurrent.CountDownLatch; + +import org.apache.tuscany.sca.interfacedef.ConversationSequence; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.runtime.RuntimeWire; + +public class Axis2ReferenceCallbackTargetInvoker { + + private Operation operation; + private RuntimeWire inboundWire; + private boolean cacheable; + Axis2CallbackInvocationHandler invocationHandler; + private CountDownLatch signal; + private Object returnPayload; + + public Axis2ReferenceCallbackTargetInvoker(Operation operation, + RuntimeWire inboundWire, + Axis2CallbackInvocationHandler invocationHandler) { + + this.operation = operation; + this.inboundWire = inboundWire; + this.invocationHandler = invocationHandler; + } + + public Object invokeTarget(final Object payload, final ConversationSequence sequence) throws InvocationTargetException { + Object[] args; + if (payload != null && !payload.getClass().isArray()) { + args = new Object[]{payload}; + returnPayload = payload; + } else { + args = (Object[]) payload; + returnPayload = args[0]; + } + // FIXME synchronize with forward thread to return value + signal.countDown(); + try { +// return invocationHandler.invoke(operation, args, callbackRoutingChain); + return null; // TODO ??? + } catch (Throwable t) { + t.printStackTrace(); + throw new InvocationTargetException(t); + } + } + + public Message invoke(Message msg) { + try { + Object resp = invokeTarget(msg.getBody(), null); + msg.setBody(resp); + } catch (InvocationTargetException e) { + msg.setFaultBody(e.getCause()); + } catch (Throwable e) { + msg.setFaultBody(e); + } + return msg; + } + + public boolean isCacheable() { + return cacheable; + } + + public void setCacheable(boolean cacheable) { + this.cacheable = cacheable; + } + + public boolean isOptimizable() { + return isCacheable(); // we only need to check if the scopes are correct + } + + public Axis2ReferenceCallbackTargetInvoker clone() throws CloneNotSupportedException { + Axis2ReferenceCallbackTargetInvoker invoker = (Axis2ReferenceCallbackTargetInvoker) super.clone(); + invoker.operation = this.operation; + invoker.inboundWire = this.inboundWire; + invoker.cacheable = this.cacheable; + invoker.invocationHandler = this.invocationHandler; + return invoker; + } + + public void setSignal(CountDownLatch signal) { + this.signal = signal; + } + + public Object getReturnPayload() { + return returnPayload; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/Axis2ServiceBindingProvider.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/Axis2ServiceBindingProvider.java new file mode 100644 index 0000000000..b5a8e6552b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/Axis2ServiceBindingProvider.java @@ -0,0 +1,418 @@ +/** + * + * Copyright 2006 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.tuscany.sca.binding.axis2; + +import java.lang.reflect.InvocationTargetException; +import java.net.URI; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.concurrent.CountDownLatch; + +import javax.wsdl.Definition; +import javax.wsdl.Port; +import javax.wsdl.extensions.soap.SOAPAddress; +import javax.xml.namespace.QName; + +import org.apache.axiom.om.OMElement; +import org.apache.axiom.soap.SOAPFactory; +import org.apache.axis2.AxisFault; +import org.apache.axis2.context.ConfigurationContext; +import org.apache.axis2.context.MessageContext; +import org.apache.axis2.description.AxisOperation; +import org.apache.axis2.description.AxisService; +import org.apache.axis2.description.Parameter; +import org.apache.axis2.description.WSDL11ToAxisServiceBuilder; +import org.apache.axis2.description.WSDL2Constants; +import org.apache.axis2.description.WSDLToAxisServiceBuilder; +import org.apache.axis2.engine.MessageReceiver; +import org.apache.axis2.wsdl.WSDLConstants; +import org.apache.tuscany.sca.binding.ws.WebServiceBinding; +import org.apache.tuscany.sca.core.invocation.ThreadMessageContext; +import org.apache.tuscany.sca.http.ServletHost; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.invocation.MessageFactory; +import org.apache.tuscany.sca.provider.ServiceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + +public class Axis2ServiceBindingProvider implements ServiceBindingProvider { + + private RuntimeComponent component; + private RuntimeComponentService service; + private WebServiceBinding wsBinding; + private ServletHost servletHost; + private ConfigurationContext configContext; + private MessageFactory messageFactory; + + // TODO: what to do about the base URI? + private static final String BASE_URI = "http://localhost:8080/"; + + public Axis2ServiceBindingProvider(RuntimeComponent component, + RuntimeComponentService service, + WebServiceBinding wsBinding, + ServletHost servletHost, + MessageFactory messageFactory) { + + this.component = component; + this.service = service; + this.wsBinding = wsBinding; + this.servletHost = servletHost; + this.messageFactory = messageFactory; + + try { + TuscanyAxisConfigurator tuscanyAxisConfigurator = new TuscanyAxisConfigurator(); + configContext = tuscanyAxisConfigurator.getConfigurationContext(); + } catch (AxisFault e) { + throw new RuntimeException(e); // TODO: better exception + } + } + + // methods for ServiceBindingActivator + + public void start() { + + // TODO: add back in from duplicate code in getBindingInterfaceContract + // to temporarily bypass NPE + InterfaceContract contract = wsBinding.getBindingInterfaceContract(); + if (contract == null) { + contract = service.getInterfaceContract(); + wsBinding.setBindingInterfaceContract(contract); + } + + // Set to use the Axiom data binding + contract.getInterface().setDefaultDataBinding(OMElement.class.getName()); + + String uri = computeActualURI(BASE_URI, component, service).normalize().toString(); + if (uri.endsWith("/")) { + uri = uri.substring(0, uri.length() - 1); + } + wsBinding.setURI(uri.toString()); + + // TODO: if specifies the wsdl service then should create a + // service for every port + + try { + configContext.getAxisConfiguration().addService(createAxisService()); + } catch (AxisFault e) { + throw new RuntimeException(e); + } + + Axis2ServiceServlet servlet = new Axis2ServiceServlet(); + servlet.init(configContext); + String servletURI = wsBinding.getURI(); + configContext.setContextRoot(servletURI); + servletHost.addServletMapping(servletURI, servlet); + } + + public void stop() { + servletHost.removeServletMapping(wsBinding.getURI()); + try { + configContext.getAxisConfiguration().removeService(wsBinding.getURI()); + } catch (AxisFault e) { + throw new RuntimeException(e); + } + } + + /** + * Compute the endpoint URI based on section 2.1.1 of the WS binding spec 1. + * The URIs in the endpoint(s) of the referenced WSDL, which may be relative + * 2. The URI specified by the wsa:Address element of the + * wsa:EndpointReference, which may be relative 3. The explicitly stated URI + * in the "uri" attribute of the binding.ws element, which may be relative, + * 4. The implicit URI as defined by in section 1.7 in the SCA Assembly spec + * If the has no wsdlElement but does have a uri attribute then + * the uri takes precidence over any implicitly used WSDL. + * + * @param parent + */ + protected URI computeActualURI(String baseURI, RuntimeComponent component, RuntimeComponentService service) { + + // TODO: support wsa:Address + + URI wsdlURI = null; + if (wsBinding.getServiceName() != null && wsBinding.getBindingName() == null) { + // explicitly points at a wsdl port, may be a relative + // URI + wsdlURI = getEndpoint(wsBinding.getPort()); + } + if (wsdlURI != null && wsdlURI.isAbsolute()) { + if (wsBinding.getURI() != null && (wsBinding.getServiceName() != null && wsBinding.getBindingName() == null)) { + throw new IllegalArgumentException("binding URI cannot be used with absolute WSDL endpoint URI"); + } + return URI.create(wsdlURI.toString()); + } + + // either there is no wsdl port endpoint URI or that URI is relative + + URI bindingURI = null; + if (wsBinding.getURI() != null) { + bindingURI = URI.create(wsBinding.getURI()); + } + if (bindingURI != null && bindingURI.isAbsolute()) { + // there is an absoulte uri specified on the binding: 1) { + // if the binding doesn't have a name use the name of the service + // (assumption, not in spec) + if (wsBinding.getName() != null) { + bindingURI = URI.create(wsBinding.getName()); + } else { + bindingURI = URI.create(service.getName()); + } + } + + // add any relative binding URI + if (bindingURI != null) { + actualURI += "/" + bindingURI; + } + + // add any relative WSDL port URI + if (wsdlURI != null) { + actualURI += "/" + wsdlURI.toString(); + } + + return URI.create(actualURI); + } + + /** + * Returns the endpoint of a given port. + */ + protected URI getEndpoint(Port wsdlPort) { + if (wsdlPort != null) { + List wsdlPortExtensions = wsdlPort.getExtensibilityElements(); + for (Object extension : wsdlPortExtensions) { + if (extension instanceof SOAPAddress) { + return URI.create(((SOAPAddress)extension).getLocationURI()); + } + } + } + return null; + } + + private AxisService createAxisService() throws AxisFault { + Definition definition = wsBinding.getWSDLDefinition().getDefinition(); + + // WSDLToAxisServiceBuilder only uses the service and port to find the + // wsdl4J Binding + // An SCA service with binding.ws does not require a service or port so + // we may not have these + // but + + WSDLToAxisServiceBuilder builder = new WSDL11ToAxisServiceBuilder(definition, wsBinding.getServiceName(), + wsBinding.getPortName()); + builder.setServerSide(true); + AxisService axisService = builder.populateService(); + + String path = URI.create(wsBinding.getURI()).getPath(); + axisService.setName(path); + axisService.setServiceDescription("Tuscany configured AxisService for service: " + wsBinding.getURI()); + + // Use the existing WSDL + Parameter wsdlParam = new Parameter(WSDLConstants.WSDL_4_J_DEFINITION, null); + wsdlParam.setValue(definition); + axisService.addParameter(wsdlParam); + Parameter userWSDL = new Parameter("useOriginalwsdl", "true"); + axisService.addParameter(userWSDL); + + for (Iterator i = axisService.getOperations(); i.hasNext();) { + AxisOperation axisOp = (AxisOperation)i.next(); + Operation op = getOperation(axisOp); + if (op != null) { + + if (op.isNonBlocking()) { + axisOp.setMessageExchangePattern(WSDL2Constants.MEP_URI_IN_ONLY); + } else { + axisOp.setMessageExchangePattern(WSDL2Constants.MEP_URI_IN_OUT); + } + + MessageReceiver msgrec = null; + if (wsBinding.getBindingInterfaceContract().getCallbackInterface() != null) { + msgrec = new Axis2ServiceInOutAsyncMessageReceiver(this, op); + } else if (op.isNonBlocking()) { + msgrec = new Axis2ServiceInMessageReceiver(this, op); + } else { + msgrec = new Axis2ServiceInOutSyncMessageReceiver(this, op); + } + axisOp.setMessageReceiver(msgrec); + } + } + + return axisService; + } + + protected Operation getOperation(AxisOperation axisOp) { + String operationName = axisOp.getName().getLocalPart(); + for (Operation op : wsBinding.getBindingInterfaceContract().getInterface().getOperations()) { + if (op.getName().equalsIgnoreCase(operationName)) { + return op; + } + } + return null; + } + + // methods for ServiceBindingProvider + + public InterfaceContract getBindingInterfaceContract() { + InterfaceContract contract = wsBinding.getBindingInterfaceContract(); + if (contract == null) { + contract = service.getInterfaceContract(); + wsBinding.setBindingInterfaceContract(contract); + } + + // Set to use the Axiom data binding + contract.getInterface().setDefaultDataBinding(OMElement.class.getName()); + return contract; + } + + // other methods that were previously in Axis2ServiceBinding + // TODO: are these still needed? + + private Map invCtxMap = new HashMap(); + + public Invoker createTargetInvoker(InterfaceContract contract, Operation operation) { + // if (!operation.isCallback()) { TODO: no isCallback methjod yet? + // throw new UnsupportedOperationException(); + // } else { + return new Axis2ServiceCallbackTargetInvoker(this); + // } + } + + public void addMapping(Object msgId, InvocationContext invCtx) { + this.invCtxMap.put(msgId, invCtx); + } + + public InvocationContext retrieveMapping(Object msgId) { + return this.invCtxMap.get(msgId); + } + + public void removeMapping(Object msgId) { + this.invCtxMap.remove(msgId); + } + + /** + * @param inMC + * @return + */ + protected static String getConversationID(MessageContext inMC) { + String conversationID = null; + Iterator i = inMC.getEnvelope().getHeader() + .getChildrenWithName(new QName("http://www.w3.org/2005/08/addressing", "From")); + for (; i.hasNext();) { + Object a = i.next(); + if (a instanceof OMElement) { + OMElement ao = (OMElement)a; + for (Iterator rpI = ao.getChildrenWithName(new QName("http://www.w3.org/2005/08/addressing", + "ReferenceParameters")); rpI.hasNext();) { + OMElement rpE = (OMElement)rpI.next(); + for (Iterator cidI = rpE.getChildrenWithName(Axis2BindingInvoker.CONVERSATION_ID_REFPARM_QN); cidI + .hasNext();) { + OMElement cidE = (OMElement)cidI.next(); + conversationID = cidE.getText(); + } + } + + } + + } + return conversationID; + } + + public Object invokeTarget(Operation op, Object[] args, Object messageId, String conversationID) + throws InvocationTargetException { + + Message requestMsg = messageFactory.createMessage(); + + if (messageId != null) { + requestMsg.setMessageID(messageId); + } + requestMsg.setBody(args); + + Message workContext = ThreadMessageContext.getMessageContext(); + + ThreadMessageContext.setMessageContext(requestMsg); + try { + if (isConversational() && conversationID != null) { + requestMsg.setConversationID(conversationID); + } else { + requestMsg.setConversationID(null); + } + + Message responseMsg = service.getInvoker(wsBinding, op).invoke(requestMsg); + + if (responseMsg.isFault()) { + throw new InvocationTargetException((Throwable)responseMsg.getBody()); + } + return responseMsg.getBody(); + + } finally { + ThreadMessageContext.setMessageContext(workContext); + } + } + + protected class InvocationContext { + public MessageContext inMessageContext; + + public Operation operation; + + public SOAPFactory soapFactory; + + public CountDownLatch doneSignal; + + public InvocationContext(MessageContext messageCtx, + Operation operation, + SOAPFactory soapFactory, + CountDownLatch doneSignal) { + this.inMessageContext = messageCtx; + this.operation = operation; + this.soapFactory = soapFactory; + this.doneSignal = doneSignal; + } + } + + public boolean isConversational() { + return wsBinding.getBindingInterfaceContract().getInterface().isConversational(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/Axis2ServiceCallbackTargetInvoker.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/Axis2ServiceCallbackTargetInvoker.java new file mode 100644 index 0000000000..29eb24bc61 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/Axis2ServiceCallbackTargetInvoker.java @@ -0,0 +1,105 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.axis2; + +import java.lang.reflect.InvocationTargetException; + +import org.apache.axiom.om.OMElement; +import org.apache.axiom.soap.SOAPEnvelope; +import org.apache.axis2.AxisFault; +import org.apache.axis2.Constants; +import org.apache.axis2.context.MessageContext; +import org.apache.axis2.engine.AxisEngine; +import org.apache.axis2.util.Utils; +import org.apache.tuscany.sca.binding.axis2.Axis2ServiceBindingProvider.InvocationContext; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; + +public class Axis2ServiceCallbackTargetInvoker implements Invoker { + + private Axis2ServiceBindingProvider service; + + protected static final OMElement RESPONSE = null; + + public Axis2ServiceCallbackTargetInvoker(Axis2ServiceBindingProvider service) { + this.service = service; + } + + private Object invokeTarget(final Object payload, Object correlationId) throws InvocationTargetException { + try { + // Use current correlation id as index to retrieve inv context + InvocationContext invCtx = service.retrieveMapping(correlationId); + + MessageContext outMC = Utils.createOutMessageContext(invCtx.inMessageContext); + outMC.getOperationContext().addMessageContext(outMC); + + OMElement responseOM; + if (payload != null && !payload.getClass().isArray()) { + responseOM = (OMElement) payload; + } else { + responseOM = (OMElement) ((Object[]) payload)[0]; + } + SOAPEnvelope soapEnvelope = invCtx.soapFactory.getDefaultEnvelope(); + soapEnvelope.getBody().addChild(responseOM); + outMC.setEnvelope(soapEnvelope); + outMC.getOperationContext().setProperty(Constants.RESPONSE_WRITTEN, Constants.VALUE_TRUE); + + AxisEngine engine = + new AxisEngine( + invCtx.inMessageContext.getOperationContext().getServiceContext().getConfigurationContext()); + engine.send(outMC); + + invCtx.doneSignal.countDown(); + + service.removeMapping(correlationId); + } catch (AxisFault e) { + throw new InvocationTargetException(e); + } catch (Throwable t) { + throw new InvocationTargetException(t); + } + + return RESPONSE; + } + + public Message invoke(Message msg) { + try { + Object correlationId = msg.getCorrelationID(); + if (correlationId == null) { + throw new RuntimeException("Missing correlation id"); + } + Object resp = invokeTarget(msg.getBody(), correlationId); + msg.setBody(resp); + } catch (InvocationTargetException e) { + msg.setFaultBody(e.getCause()); + } catch (Throwable e) { + msg.setFaultBody(e); + } + return msg; + } + + public Axis2ServiceCallbackTargetInvoker clone() throws CloneNotSupportedException { + try { + return (Axis2ServiceCallbackTargetInvoker) super.clone(); + } catch (CloneNotSupportedException e) { + // will not happen + return null; + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/Axis2ServiceInMessageReceiver.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/Axis2ServiceInMessageReceiver.java new file mode 100644 index 0000000000..85871c7924 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/Axis2ServiceInMessageReceiver.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.axis2; + +import org.apache.axiom.om.OMElement; +import org.apache.axis2.AxisFault; +import org.apache.axis2.context.MessageContext; +import org.apache.axis2.receivers.AbstractInMessageReceiver; +import org.apache.tuscany.sca.interfacedef.Operation; + +public class Axis2ServiceInMessageReceiver extends AbstractInMessageReceiver { + + protected Operation operation; + + private Axis2ServiceBindingProvider provider; + + public Axis2ServiceInMessageReceiver(Axis2ServiceBindingProvider provider, Operation operation) { + this.provider = provider; + this.operation = operation; + } + + public Axis2ServiceInMessageReceiver() { + + } + + @Override + public void invokeBusinessLogic(MessageContext inMC) throws AxisFault { + try { + OMElement requestOM = inMC.getEnvelope().getBody().getFirstElement(); + Object[] args = new Object[] {requestOM}; + String conversationID = provider.isConversational() ? Axis2ServiceBindingProvider.getConversationID(inMC) : null; + +// axis2Service.invokeTarget(operation, args, null, conversationID); + +// } catch (InvocationTargetException e) { +// Throwable t = e.getCause(); +// if (t instanceof Exception) { +// throw AxisFault.makeFault((Exception)t); +// } +// throw new InvocationRuntimeException(e); + } catch (Throwable t) { + if (t instanceof Exception) { + throw AxisFault.makeFault((Exception)t); + } + throw new RuntimeException(t); + } + + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/Axis2ServiceInOutAsyncMessageReceiver.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/Axis2ServiceInOutAsyncMessageReceiver.java new file mode 100644 index 0000000000..70d705c7b8 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/Axis2ServiceInOutAsyncMessageReceiver.java @@ -0,0 +1,128 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.axis2; + +import java.util.concurrent.CountDownLatch; + +import org.apache.axiom.om.OMElement; +import org.apache.axis2.AxisFault; +import org.apache.axis2.context.MessageContext; +import org.apache.axis2.receivers.AbstractMessageReceiver; +import org.apache.tuscany.sca.interfacedef.Operation; + +public class Axis2ServiceInOutAsyncMessageReceiver extends AbstractMessageReceiver { + + private Operation operation; + + private Axis2ServiceBindingProvider provider; + + public Axis2ServiceInOutAsyncMessageReceiver(Axis2ServiceBindingProvider provider, + Operation operation) { + this.provider = provider; + this.operation = operation; + } + + public Axis2ServiceInOutAsyncMessageReceiver() { + } + + public final void receive(final MessageContext messageCtx) { + try { + Object messageId = messageCtx.getMessageID(); + if (messageId == null) { + messageId = new MessageId(); + } + + // Now use message id as index to context to be used by callback + // target invoker + CountDownLatch doneSignal = new CountDownLatch(1); +// InvocationContext invCtx = +// service.new InvocationContext(messageCtx, operation, getSOAPFactory(messageCtx), doneSignal); +// service.addMapping(messageId, invCtx); + + invokeBusinessLogic(messageCtx, messageId); + + try { + doneSignal.await(); + } catch(InterruptedException e) { + e.printStackTrace(); + } + } catch (AxisFault e) { + // log.error(e); + } + } + + private void invokeBusinessLogic(MessageContext inMC, Object messageId) throws AxisFault { + try { + OMElement requestOM = inMC.getEnvelope().getBody().getFirstElement(); + Object[] args = new Object[] {requestOM}; + String conversationID = provider.isConversational() ? Axis2ServiceBindingProvider.getConversationID(inMC) : null; +// service.invokeTarget(operation, args, messageId, conversationID); +// } catch (InvocationTargetException e) { +// Throwable t = e.getCause(); +// if (t instanceof Exception) { +// throw AxisFault.makeFault((Exception)t); +// } +// throw new InvocationRuntimeException(e); + } catch (Exception e) { + throw AxisFault.makeFault(e); + } + + } + + /** + * A unique identifier for a message flowing on a wire, potentially end-to-end (ie, through more than one SCAObject to + * SCAObject hop). + * + * This used to be in the org.apache.tuscany.spi.wire package + */ + public class MessageId { + + private long timestamp; + + public MessageId() { + this.timestamp = System.currentTimeMillis(); + } + + public long getTimestamp() { + return timestamp; + } + + public String toString() { + return "MsgId[" + timestamp + "]"; + } + + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + + final MessageId messageId = (MessageId) o; + return timestamp == messageId.timestamp; + } + + public int hashCode() { + return (int) (timestamp ^ (timestamp >>> 32)); + } + + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/Axis2ServiceInOutSyncMessageReceiver.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/Axis2ServiceInOutSyncMessageReceiver.java new file mode 100644 index 0000000000..ea5bb9f2e6 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/Axis2ServiceInOutSyncMessageReceiver.java @@ -0,0 +1,75 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.axis2; + +import java.lang.reflect.InvocationTargetException; + +import org.apache.axiom.om.OMElement; +import org.apache.axiom.soap.SOAPEnvelope; +import org.apache.axis2.AxisFault; +import org.apache.axis2.Constants; +import org.apache.axis2.context.MessageContext; +import org.apache.axis2.receivers.AbstractInOutSyncMessageReceiver; +import org.apache.tuscany.sca.interfacedef.Operation; + +public class Axis2ServiceInOutSyncMessageReceiver extends AbstractInOutSyncMessageReceiver { + + protected Operation operation; + + private Axis2ServiceBindingProvider provider; + + public Axis2ServiceInOutSyncMessageReceiver() { + } + + public Axis2ServiceInOutSyncMessageReceiver(Axis2ServiceBindingProvider provider, Operation operation) { + this.provider = provider; + this.operation = operation; + } + + @Override + public void invokeBusinessLogic(MessageContext inMC, MessageContext outMC) throws AxisFault { + try { + OMElement requestOM = inMC.getEnvelope().getBody().getFirstElement(); + Object[] args = new Object[] {requestOM}; + + String conversationID = provider.isConversational() ? Axis2ServiceBindingProvider.getConversationID(inMC) : null; + + OMElement responseOM = (OMElement) provider.invokeTarget(operation, args, null, conversationID); + + SOAPEnvelope soapEnvelope = getSOAPFactory(inMC).getDefaultEnvelope(); + if(null != responseOM ){ + soapEnvelope.getBody().addChild(responseOM); + } + outMC.setEnvelope(soapEnvelope); + outMC.getOperationContext().setProperty(Constants.RESPONSE_WRITTEN, Constants.VALUE_TRUE); + + } catch (InvocationTargetException e) { + e.printStackTrace(); + Throwable t = e.getCause(); + if (t instanceof Exception) { + throw AxisFault.makeFault((Exception)t); + } + throw new RuntimeException(e); + } catch (Exception e) { + e.printStackTrace(); + throw AxisFault.makeFault(e); + } + + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/Axis2ServiceServlet.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/Axis2ServiceServlet.java new file mode 100644 index 0000000000..b313ff1b4e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/Axis2ServiceServlet.java @@ -0,0 +1,300 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.axis2; + +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.SocketException; +import java.net.URL; +import java.util.Collections; +import java.util.Enumeration; +import java.util.Set; +import java.util.Vector; + +import javax.servlet.RequestDispatcher; +import javax.servlet.Servlet; +import javax.servlet.ServletConfig; +import javax.servlet.ServletContext; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.axis2.AxisFault; +import org.apache.axis2.addressing.EndpointReference; +import org.apache.axis2.context.ConfigurationContext; +import org.apache.axis2.transport.http.AxisServlet; +import org.apache.axis2.transport.http.ListingAgent; +import org.apache.axis2.transport.http.server.HttpUtils; + +/** + * This overrides the servlet init of the AxisServlet so Tuscany can use + * a single Axis2 ConfigurationContext instance shared between AxisServlet + * instances for each SCA service with a ws binding. + * TODO: need to review if thats really what we want to be doing + */ +public class Axis2ServiceServlet extends AxisServlet { + + protected TuscanyListingAgent agent; + protected boolean inited; + + private static final long serialVersionUID = 1L; + private static final ServletConfig DUMMY_CONFIG = createDummyServletConfig(); + + public void init(ConfigurationContext configContext) { + this.configContext = configContext; + try { + super.init(DUMMY_CONFIG); + } catch (ServletException e) { + throw new RuntimeException(e); + } + agent = new TuscanyListingAgent(configContext); + } + + /** + * Override Axis2 servlet method to avoid loop when init + * is called after servletConfig already initialized by + * this classes init(ConfigurationContext) method. + */ + @Override + public void init() throws ServletException { + } + + /** + * We've setup the Servlet by passing in a ConfigurationContext on our init method + * override this method to just return that + */ + @Override + protected ConfigurationContext initConfigContext(ServletConfig config) throws ServletException { + return this.configContext; + } + + @Override + public ServletConfig getServletConfig() { + return DUMMY_CONFIG; + } + + @Override + public String getServletName() { + return "TuscanyAxis2Servlet"; + } + + /** + * The AxisServlet gets NPE during init without a ServletConfig so this is a mocked up one to prevent that. + */ + private static ServletConfig createDummyServletConfig() { + ServletConfig sc = new ServletConfig() { + + public String getServletName() { + return "TuscanyAxis2DummyServlet"; + } + + public ServletContext getServletContext() { + return new ServletContext() { + + public ServletContext getContext(String uripath) { + return null; + } + + public String getContextPath() { + return null; + } + + public int getMajorVersion() { + return 0; + } + + public int getMinorVersion() { + return 0; + } + + public String getMimeType(String file) { + return null; + } + + public Set getResourcePaths(String path) { + return Collections.emptySet(); + } + + public URL getResource(String path) throws MalformedURLException { + if("/".equals(path)) { + // HACK: To avoid NPE + return new URL("/axis2"); + } + return null; + } + + public InputStream getResourceAsStream(String path) { + return null; + } + + public RequestDispatcher getRequestDispatcher(String path) { + return null; + } + + public RequestDispatcher getNamedDispatcher(String arg0) { + return null; + } + + public Servlet getServlet(String arg0) throws ServletException { + return null; + } + + public Enumeration getServlets() { + return null; + } + + public Enumeration getServletNames() { + return null; + } + + public void log(String arg0) { + } + + public void log(Exception arg0, String arg1) { + } + + public void log(String arg0, Throwable arg1) { + } + + public String getRealPath(String arg0) { + return null; + } + + public String getServerInfo() { + return null; + } + + public String getInitParameter(String arg0) { + return null; + } + + public Enumeration getInitParameterNames() { + return null; + } + + public Object getAttribute(String arg0) { + return null; + } + + public Enumeration getAttributeNames() { + return null; + } + + public void setAttribute(String arg0, Object arg1) { + } + + public void removeAttribute(String arg0) { + } + + public String getServletContextName() { + return null; + } + }; + } + + public String getInitParameter(String arg0) { + return null; + } + + public Enumeration getInitParameterNames() { + return new Vector().elements(); + } + }; + return sc; + } + + @Override + protected void service(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + // HACK: Get the correct context root which is not available during init() call + if (!inited) { + synchronized (configContext) { + configContext.setContextRoot(request.getContextPath()); + inited = true; + } + } + + super.service(request, response); + } + + @Override + public void destroy() { + try { + super.destroy(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** + * Override the AxisServlet doGet to use the TuscanyListingAgent for ?wsdl + */ + @Override + protected void doGet(HttpServletRequest request, + HttpServletResponse response) throws ServletException, IOException { + + initContextRoot(request); + + String query = request.getQueryString(); + if ((query != null) && (query.indexOf("wsdl2") >= 0 || + query.indexOf("wsdl") >= 0 || query.indexOf("xsd") >= 0 || + query.indexOf("policy") >= 0)) { + agent.processListService(request, response); + } else { + super.doGet(request, response); + } + } + + /** + + /** + * Override the AxisServlet method so as to not add "/services" into the url + */ + @Override + public EndpointReference[] getEPRsForService(String serviceName, String ip) throws AxisFault { + //RUNNING_PORT + String port = (String) configContext.getProperty(ListingAgent.RUNNING_PORT); + if (port == null) { + port = "8080"; + } + if (ip == null) { + try { + ip = HttpUtils.getIpAddress(); + if (ip == null) { + ip = "localhost"; + } + } catch (SocketException e) { + throw new AxisFault(e); + } + } + + + StringBuilder eprString = new StringBuilder("http://"); + eprString.append(ip).append(":").append(port); + if (!serviceName.startsWith("/")) { + eprString.append('/'); + } + eprString.append(serviceName); + EndpointReference endpoint = new EndpointReference(eprString.toString()); + + return new EndpointReference[]{endpoint}; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/TuscanyAxisConfigurator.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/TuscanyAxisConfigurator.java new file mode 100755 index 0000000000..370ed6e0a4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/TuscanyAxisConfigurator.java @@ -0,0 +1,44 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.axis2; + +import org.apache.axis2.AxisFault; +import org.apache.axis2.context.ConfigurationContext; +import org.apache.axis2.context.ConfigurationContextFactory; +import org.apache.axis2.deployment.URLBasedAxisConfigurator; +import org.apache.axis2.engine.AxisConfigurator; + +/** + * Helps configure Axis2 from a resource in binding.axis2 instead of Axis2.xml + *

TODO: Review: should there be a single global Axis + * ConfigurationContext + */ +public class TuscanyAxisConfigurator extends URLBasedAxisConfigurator implements AxisConfigurator { + + public TuscanyAxisConfigurator() throws AxisFault { + super(TuscanyAxisConfigurator.class.getResource("/org/apache/tuscany/sca/binding/axis2/engine/config/axis2.xml"), null); + } + + public ConfigurationContext getConfigurationContext() throws AxisFault { + if (configContext == null) + configContext = ConfigurationContextFactory.createConfigurationContext(this); + return configContext; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/TuscanyDispatcher.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/TuscanyDispatcher.java new file mode 100644 index 0000000000..8988c74445 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/TuscanyDispatcher.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.axis2; + +import java.net.URI; +import java.util.HashMap; + +import org.apache.axis2.AxisFault; +import org.apache.axis2.addressing.EndpointReference; +import org.apache.axis2.context.ConfigurationContext; +import org.apache.axis2.context.MessageContext; +import org.apache.axis2.description.AxisService; +import org.apache.axis2.description.HandlerDescription; +import org.apache.axis2.engine.AxisConfiguration; +import org.apache.axis2.engine.RequestURIBasedDispatcher; +import org.apache.axis2.util.JavaUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * A Tuscany specific Axis2 Dispatcher that enables using services + * exposed at the SCA defined service URI instead of /services/ + */ +public class TuscanyDispatcher extends RequestURIBasedDispatcher { + + public static final String NAME = "TuscanyDispatcher"; + private static final Log log = LogFactory.getLog(RequestURIBasedDispatcher.class); + private static final boolean isDebugEnabled = log.isDebugEnabled(); + + /* + * (non-Javadoc) + * + * @see org.apache.axis2.engine.AbstractDispatcher#findService(org.apache.axis2.context.MessageContext) + */ + public AxisService findService(MessageContext messageContext) throws AxisFault { + EndpointReference toEPR = messageContext.getTo(); + + if (toEPR != null) { + if(isDebugEnabled){ + log.debug("Checking for Service using target endpoint address : " + toEPR.getAddress()); + } + + String path = URI.create(toEPR.getAddress()).getPath(); + + ConfigurationContext configurationContext = messageContext.getConfigurationContext(); + AxisConfiguration registry = configurationContext.getAxisConfiguration(); + + String serviceName = findAxisServiceName(registry, path); + return registry.getService(serviceName); + + } else { + if(isDebugEnabled){ + log.debug("Attempted to check for Service using null target endpoint URI"); + } + return null; + } + } + + public void initDispatcher() { + init(new HandlerDescription(NAME)); + } + + protected String findAxisServiceName(AxisConfiguration registry, String path) { + HashMap services = registry.getServices(); + if (services == null) { + return null; + } + String[] parts = JavaUtils.split(path, '/'); + String serviceName = ""; + for (int i=parts.length-1; i>=0; i--) { + serviceName = parts[i] + serviceName; + if (services.containsKey(serviceName)) { + return serviceName; + } + serviceName = "/" + serviceName; + if (services.containsKey(serviceName)) { + return serviceName; + } + } + + return null; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/TuscanyListingAgent.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/TuscanyListingAgent.java new file mode 100644 index 0000000000..87338ceb27 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/main/java/org/apache/tuscany/sca/binding/axis2/TuscanyListingAgent.java @@ -0,0 +1,334 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.axis2; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.xml.stream.FactoryConfigurationError; +import javax.xml.stream.XMLOutputFactory; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.axiom.attachments.utils.IOUtils; +import org.apache.axis2.Constants; +import org.apache.axis2.context.ConfigurationContext; +import org.apache.axis2.deployment.DeploymentConstants; +import org.apache.axis2.description.AxisDescription; +import org.apache.axis2.description.AxisService; +import org.apache.axis2.description.PolicyInclude; +import org.apache.axis2.transport.http.ListingAgent; +import org.apache.axis2.util.ExternalPolicySerializer; +import org.apache.axis2.util.JavaUtils; +import org.apache.neethi.Policy; +import org.apache.neethi.PolicyRegistry; +import org.apache.ws.commons.schema.XmlSchema; + +/** + * A Tuscany specific Axis2 ListingAgent as the Axis2 one does not work + * with the Tuscany sevice names which include slash ('/') characters. + * Unfortunately it ends up having to copy a fair amount of Axis2 code to do this. + */ +public class TuscanyListingAgent extends ListingAgent { + + private static final String LIST_SINGLE_SERVICE_JSP_NAME = + "listSingleService.jsp"; + + public TuscanyListingAgent(ConfigurationContext aConfigContext) { + super(aConfigContext); + } + + protected String findAxisServiceName(String path) { + HashMap services = configContext.getAxisConfiguration().getServices(); + if (services == null) { + return null; + } + String[] parts = JavaUtils.split(path, '/'); + String serviceName = ""; + for (int i=parts.length-1; i>=0; i--) { + serviceName = parts[i] + serviceName; + if (services.containsKey(serviceName)) { + return serviceName; + } + serviceName = "/" + serviceName; + if (services.containsKey(serviceName)) { + return serviceName; + } + } + + return null; + } + + @Override + public void processListService(HttpServletRequest req, + HttpServletResponse res) + throws IOException, ServletException { + + + String filePart = req.getRequestURL().toString(); +// String serviceName = filePart.substring(filePart.lastIndexOf("/") + 1, +// filePart.length()); +// Change the Axis2 code so as to use the complete ServletPath as the service name +// this line is the only change to to Axis2 code + + String serviceName = findAxisServiceName(filePart); + + String query = req.getQueryString(); + int wsdl2 = query.indexOf("wsdl2"); + int wsdl = query.indexOf("wsdl"); + int xsd = query.indexOf("xsd"); + int policy = query.indexOf("policy"); + + HashMap services = configContext.getAxisConfiguration().getServices(); + if ((services != null) && !services.isEmpty()) { + Object serviceObj = services.get(serviceName); + if (serviceObj != null) { + boolean isHttp = "http".equals(req.getScheme()); + if (wsdl2 >= 0) { + OutputStream out = res.getOutputStream(); + res.setContentType("text/xml"); + String ip = extractHostAndPort(filePart, isHttp); + ((AxisService) serviceObj) + .printWSDL2(out, ip, configContext.getServiceContextPath()); + out.flush(); + out.close(); + return; + } else if (wsdl >= 0) { + OutputStream out = res.getOutputStream(); + res.setContentType("text/xml"); + String ip = extractHostAndPort(filePart, isHttp); + ((AxisService) serviceObj).printWSDL(out, ip, configContext.getServicePath()); + out.flush(); + out.close(); + return; + } else if (xsd >= 0) { + OutputStream out = res.getOutputStream(); + res.setContentType("text/xml"); + AxisService axisService = (AxisService) serviceObj; + //call the populator + axisService.populateSchemaMappings(); + Map schemaMappingtable = + axisService.getSchemaMappingTable(); + ArrayList schemas = axisService.getSchema(); + + //a name is present - try to pump the requested schema + String xsds = req.getParameter("xsd"); + if (!"".equals(xsds)) { + XmlSchema schema = + (XmlSchema) schemaMappingtable.get(xsds); + if (schema != null) { + //schema is there - pump it outs + schema.write(new OutputStreamWriter(out, "UTF8")); + out.flush(); + out.close(); + } else { + InputStream in = axisService.getClassLoader() + .getResourceAsStream(DeploymentConstants.META_INF + "/" + xsds); + if (in != null) { + out.write(IOUtils.getStreamAsByteArray(in)); + out.flush(); + out.close(); + } else { + res.sendError(HttpServletResponse.SC_NOT_FOUND); + } + } + + //multiple schemas are present and the user specified + //no name - in this case we cannot possibly pump a schema + //so redirect to the service root + } else if (schemas.size() > 1) { + res.sendRedirect(""); + //user specified no name and there is only one schema + //so pump that out + } else { + XmlSchema schema = axisService.getSchema(0); + if (schema != null) { + schema.write(new OutputStreamWriter(out, "UTF8")); + out.flush(); + out.close(); + } + } + return; + } else if (policy >= 0) { + + OutputStream out = res.getOutputStream(); + + ExternalPolicySerializer serializer = new ExternalPolicySerializer(); + serializer.setAssertionsToFilter(configContext + .getAxisConfiguration().getLocalPolicyAssertions()); + + // check whether Id is set + String idParam = req.getParameter("id"); + + if (idParam != null) { + // Id is set + + Policy targetPolicy = findPolicy(idParam, (AxisService) serviceObj); + + if (targetPolicy != null) { + XMLStreamWriter writer; + + try { + writer = XMLOutputFactory.newInstance() + .createXMLStreamWriter(out); + + res.setContentType("text/xml"); + targetPolicy.serialize(writer); + writer.flush(); + + } catch (XMLStreamException e) { + throw new ServletException( + "Error occured when serializing the Policy", + e); + + } catch (FactoryConfigurationError e) { + throw new ServletException( + "Error occured when serializing the Policy", + e); + } + + } else { + + res.setContentType("text/html"); + String outStr = "No policy found for id=" + + idParam + ""; + out.write(outStr.getBytes()); + } + + } else { + + PolicyInclude policyInclude = ((AxisService) serviceObj).getPolicyInclude(); + Policy effecPolicy = policyInclude.getEffectivePolicy(); + + if (effecPolicy != null) { + XMLStreamWriter writer; + + try { + writer = XMLOutputFactory.newInstance() + .createXMLStreamWriter(out); + + res.setContentType("text/xml"); + effecPolicy.serialize(writer); + writer.flush(); + + } catch (XMLStreamException e) { + throw new ServletException( + "Error occured when serializing the Policy", + e); + + } catch (FactoryConfigurationError e) { + throw new ServletException( + "Error occured when serializing the Policy", + e); + } + } else { + + res.setContentType("text/html"); + String outStr = "No effective policy for " + + serviceName + " servcie"; + out.write(outStr.getBytes()); + } + } + + return; + } else { + req.getSession().setAttribute(Constants.SINGLE_SERVICE, + serviceObj); + } + } else { + req.getSession().setAttribute(Constants.SINGLE_SERVICE, null); + } + } + + renderView(LIST_SINGLE_SERVICE_JSP_NAME, req, res); + } + + private String extractHostAndPort(String filePart, boolean isHttp) { + int ipindex = filePart.indexOf("//"); + String ip = null; + if (ipindex >= 0) { + ip = filePart.substring(ipindex + 2, filePart.length()); + int seperatorIndex = ip.indexOf(":"); + int slashIndex = ip.indexOf("/"); + String port; + if (seperatorIndex >= 0) { + port = ip.substring(seperatorIndex + 1, slashIndex); + ip = ip.substring(0, seperatorIndex); + } else { + ip = ip.substring(0, slashIndex); + port = "80"; + } + if (isHttp) { + configContext.setProperty(RUNNING_PORT, port); + } + } + return ip; + } + + private Policy findPolicy(String id, AxisDescription des) { + + List policyElements = des.getPolicyInclude().getPolicyElements(); + PolicyRegistry registry = des.getPolicyInclude().getPolicyRegistry(); + + Object policyComponent; + + Policy policy = registry.lookup(id); + + if (policy != null) { + return policy; + } + + for (Iterator iterator = policyElements.iterator(); iterator.hasNext();) { + policyComponent = iterator.next(); + + if (policyComponent instanceof Policy) { + // policy found for the id + + if (id.equals(((Policy) policyComponent).getId())) { + return (Policy) policyComponent; + } + } + } + + AxisDescription child; + + for (Iterator iterator = des.getChildren(); iterator.hasNext();) { + child = (AxisDescription) iterator.next(); + policy = findPolicy(id, child); + + if (policy != null) { + return policy; + } + } + + return null; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator new file mode 100644 index 0000000000..f3bdb2511a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# Implementation class for the ExtensionActivator +org.apache.tuscany.sca.binding.axis2.Axis2ModuleActivator diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/main/resources/org/apache/tuscany/sca/binding/axis2/engine/config/axis2.xml b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/main/resources/org/apache/tuscany/sca/binding/axis2/engine/config/axis2.xml new file mode 100755 index 0000000000..20b47fa151 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/main/resources/org/apache/tuscany/sca/binding/axis2/engine/config/axis2.xml @@ -0,0 +1,411 @@ + + + + + + + true + false + false + false + + + + + + 30000 + + + + + true + + + + + + false + + admin + axis2 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + false + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 6060 + + + + + + + + + + + + + + + + + + + + + > + + + + + + + + + + + + + HTTP/1.1 + chunked + + + + + + + HTTP/1.1 + chunked + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/axis2/Axis2ReferenceTestCase.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/axis2/Axis2ReferenceTestCase.java new file mode 100755 index 0000000000..6b364eec68 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/axis2/Axis2ReferenceTestCase.java @@ -0,0 +1,83 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.axis2; + +import junit.framework.TestCase; + +public class Axis2ReferenceTestCase extends TestCase { + + public void testInvokeService() throws Exception { +// Axis2ReferenceBinding axis2Reference = createAxis2Reference("testWebAppName", "testServiceName"); +// ServiceContract contract = new JavaServiceContract(); +// Operation operation = new Operation("sayHi", null, null, null, false, null, NO_CONVERSATION); +// TargetInvoker targetInvoker = axis2Reference.createTargetInvoker(contract, operation); +// assertNotNull(targetInvoker); +// assertFalse(targetInvoker instanceof Axis2AsyncTargetInvoker); + } + + public void testAsyncTargetInvoker() throws Exception { +// Axis2ReferenceBinding axis2Reference = createAxis2Reference("testWebAppName", "testServiceName"); +// //Create a mocked InboundWire, make the call of ServiceBindingExtension.getInterface() returns a Class +// Wire inboundWire = EasyMock.createNiceMock(Wire.class); +// JavaServiceContract contract = new JavaServiceContract(Greeter.class); +// contract.setCallbackName(""); +// contract.setCallbackClass(GreetingCallback.class); +// Operation callbackOp = +// new Operation("sayHiCallback", null, null, null, true, null, NO_CONVERSATION); +// HashMap> callbackOps = new HashMap>(); +// callbackOps.put("sayHiCallback", callbackOp); +// contract.setCallbackOperations(callbackOps); +// EasyMock.expect(inboundWire.getTargetContract()).andReturn(contract).anyTimes(); +// EasyMock.replay(inboundWire); +// +// axis2Reference.setWire(inboundWire); +// Operation operation = new Operation("sayHi", null, null, null, true, null, NO_CONVERSATION); +// TargetInvoker asyncTargetInvoker = axis2Reference.createTargetInvoker(contract, operation); +// assertNotNull(asyncTargetInvoker); +// assertTrue(asyncTargetInvoker instanceof Axis2AsyncTargetInvoker); + } + +// @SuppressWarnings("unchecked") +// private Axis2ReferenceBinding createAxis2Reference(String webAppName, String serviceName) throws Exception { +// //Create WebServiceBindingDefinition +// String wsdlLocation = "/wsdl/hello_world_doc_lit.wsdl"; +// URL url = getClass().getResource(wsdlLocation); +// assertNotNull("Could not find wsdl " + url.toString(), url); +// +// WSDLFactory factory = WSDLFactory.newInstance(); +// WSDLReader reader = factory.newWSDLReader(); +// reader.setFeature("javax.wsdl.verbose", false); +// InputSource input = new InputSource(url.openStream()); +// Definition wsdlDef = reader.readWSDL(url.toString(), input); +// Service wsdlService = wsdlDef.getService(new QName("http://objectweb.org/hello_world_soap_http", +// "SOAPService")); +// Port port = wsdlService.getPort("SoapPort"); +// WebServiceBindingDefinition wsBinding = +// new WebServiceBindingDefinition(wsdlDef, port, "uri", "portURI", wsdlService); +// //Create a mocked WireService, make the call of ServiceBindingExtension.getServiceInstance() returns a proxy instance. +// // TODO figure out what to do with the service contract +// ServiceContract contract = new WSDLServiceContract(); +// contract.setInterfaceClass(Greeter.class); +// return new Axis2ReferenceBinding(URI.create(serviceName), +// wsBinding, +// contract, +// null, +// null); +// } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/axis2/Axis2ServiceTestCase.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/axis2/Axis2ServiceTestCase.java new file mode 100755 index 0000000000..13ea94dd66 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/axis2/Axis2ServiceTestCase.java @@ -0,0 +1,104 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.axis2; + +import junit.framework.TestCase; + +public class Axis2ServiceTestCase extends TestCase { + + public void testInvokeService() throws Exception { +// TestServletHost tomcatHost = new TestServletHost(); +// Axis2ServiceBinding axis2Service = createAxis2Service("testServiceName", tomcatHost, false); +// axis2Service.start(); +// +// if (true) return; +// Servlet servlet = tomcatHost.getMapping("testWebAppName/serviceBindings/testServiceName"); +// assertNotNull(servlet); +// +// //Create mocked HttpRequest and HttpResponse object to test the Axis2Servlet +// //To be done: + + } + + public void testAsyncMessageReceiver() throws Exception { + +// TestServletHost tomcatHost = new TestServletHost(); +// Axis2ServiceBinding axis2Service = createAxis2Service("testServiceName", tomcatHost, true); +// axis2Service.start(); + } + +// @SuppressWarnings("unchecked") +// private Axis2ServiceBinding createAxis2Service(String serviceName, ServletHost tomcatHost, boolean callback) +// throws Exception { +// //Create WebServiceBindingDefinition +// String wsdlLocation = "/wsdl/hello_world_doc_lit.wsdl"; +// URL url = getClass().getResource(wsdlLocation); +// assertNotNull("Could not find wsdl " + url.toString(), url); +// +// WSDLFactory factory = WSDLFactory.newInstance(); +// WSDLReader reader = factory.newWSDLReader(); +// reader.setFeature("javax.wsdl.verbose", false); +// InputSource input = new InputSource(url.openStream()); +// Definition wsdlDef = reader.readWSDL(url.toString(), input); +// Service wsdlService = wsdlDef.getService(new QName("http://objectweb.org/hello_world_soap_http", +// "SOAPService")); +// Port port = wsdlService.getPort("SoapPort"); +// WebServiceBindingDefinition wsBinding = new WebServiceBindingDefinition(wsdlDef, port, "uri", "portURI", wsdlService); +// +// //Create a mocked WireService, make the call of ServiceBindingExtension.getServiceInstance() returns a proxy instance. +//// WireService wireService = EasyMock.createNiceMock(WireService.class); +//// wireService.createProxy(EasyMock.isA(Class.class), EasyMock.isA(Wire.class)); +//// EasyMock.expectLastCall().andReturn(null); +//// EasyMock.replay(wireService); +// +// //Create a mocked InboundWire, make the call of ServiceBindingExtension.getInterface() returns a Class +// Wire inboundWire = EasyMock.createNiceMock(Wire.class); +// JavaServiceContract contract = new JavaServiceContract(Greeter.class); +// Map> opMap = new HashMap>(); +// for (Method m : Greeter.class.getMethods()) { +// opMap.put(m.getName(), new Operation(m.getName(), null, null, null)); +// } +// contract.setOperations(opMap); +// EasyMock.expect(inboundWire.getTargetContract()).andReturn(contract).anyTimes(); +// if (callback) { +// contract.setCallbackName(""); +// } +// EasyMock.replay(inboundWire); +// +// Wire outboundWire = EasyMock.createNiceMock(Wire.class); +// Map, InvocationChain> map = new HashMap, InvocationChain>(); +// EasyMock.expect(outboundWire.getInvocationChains()).andReturn(map).once(); +// EasyMock.replay(outboundWire); +// +// TuscanyAxisConfigurator tuscanyAxisConfigurator = new TuscanyAxisConfigurator(); +// ConfigurationContext configurationContext = tuscanyAxisConfigurator.getConfigurationContext(); +// Axis2ServiceBinding axis2Service = +// new Axis2ServiceBinding(URI.create(serviceName), +// contract, +// null, +// wsBinding, +// tomcatHost, +// configurationContext, null); +// axis2Service.setWire(inboundWire); +//// axis2Service.setOutboundWire(outboundWire); +// +// return axis2Service; +// } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/axis2/Greeter.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/axis2/Greeter.java new file mode 100755 index 0000000000..c604b954a4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/axis2/Greeter.java @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.axis2; + +public interface Greeter { + + String sayHi(); + + String greetMe(String requestType); + + void greetMeOneWay(String requestType); + + void greetMeWithCallback(String requestType); + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/axis2/GreetingCallback.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/axis2/GreetingCallback.java new file mode 100644 index 0000000000..bcf9baa42d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/axis2/GreetingCallback.java @@ -0,0 +1,24 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.axis2; + +public interface GreetingCallback { + + void greetMeCallback(String greetMeResponse); +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/axis2/itests/HelloWorld.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/axis2/itests/HelloWorld.java new file mode 100644 index 0000000000..dfc78e7cd8 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/axis2/itests/HelloWorld.java @@ -0,0 +1,29 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.axis2.itests; + +import org.osoa.sca.annotations.Remotable; + +@Remotable +public interface HelloWorld { + + public String getGreetings(String s); + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/axis2/itests/HelloWorldComponent.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/axis2/itests/HelloWorldComponent.java new file mode 100644 index 0000000000..3978726f2a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/axis2/itests/HelloWorldComponent.java @@ -0,0 +1,33 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.axis2.itests; + +import org.osoa.sca.annotations.Reference; + +public class HelloWorldComponent implements HelloWorld { + + @Reference + public HelloWorld helloWorldWS; + + public String getGreetings(String s) { + return helloWorldWS.getGreetings(s); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/axis2/itests/HelloWorldMultiService.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/axis2/itests/HelloWorldMultiService.java new file mode 100644 index 0000000000..8c1120f545 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/axis2/itests/HelloWorldMultiService.java @@ -0,0 +1,51 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.axis2.itests; + +import org.apache.axiom.om.OMAbstractFactory; +import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.OMFactory; + +public class HelloWorldMultiService implements HelloWorldOM, HelloWorldOM2 { + + public OMElement getGreetings(OMElement requestOM) { + String name = requestOM.getFirstElement().getText(); + + OMFactory omFactory = OMAbstractFactory.getOMFactory(); + OMElement responseOM = omFactory.createOMElement("getGreetingsResponse", "http://helloworld-om", "helloworld"); + OMElement param = omFactory.createOMElement("getGreetingsReturn", "http://helloworld-om", "helloworld"); + responseOM.addChild(param); + param.addChild(omFactory.createOMText("Hello " + name)); + + return responseOM; + } + + public OMElement getGreetings2(OMElement requestOM) { + String name = requestOM.getFirstElement().getText(); + + OMFactory omFactory = OMAbstractFactory.getOMFactory(); + OMElement responseOM = omFactory.createOMElement("getGreetingsResponse", "http://helloworld-om", "helloworld"); + OMElement param = omFactory.createOMElement("getGreetingsReturn", "http://helloworld-om", "helloworld"); + responseOM.addChild(param); + param.addChild(omFactory.createOMText("Hello2 " + name)); + + return responseOM; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/axis2/itests/HelloWorldOM.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/axis2/itests/HelloWorldOM.java new file mode 100644 index 0000000000..897ac8dcb9 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/axis2/itests/HelloWorldOM.java @@ -0,0 +1,30 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.axis2.itests; + +import org.apache.axiom.om.OMElement; +import org.osoa.sca.annotations.Remotable; + +@Remotable +public interface HelloWorldOM { + + public OMElement getGreetings(OMElement parmE); + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/axis2/itests/HelloWorldOM2.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/axis2/itests/HelloWorldOM2.java new file mode 100644 index 0000000000..8981541ad8 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/axis2/itests/HelloWorldOM2.java @@ -0,0 +1,30 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.axis2.itests; + +import org.apache.axiom.om.OMElement; +import org.osoa.sca.annotations.Remotable; + +@Remotable +public interface HelloWorldOM2 { + + public OMElement getGreetings2(OMElement parmE); + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/axis2/itests/HelloWorldOMComponent.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/axis2/itests/HelloWorldOMComponent.java new file mode 100644 index 0000000000..6b6abb843f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/axis2/itests/HelloWorldOMComponent.java @@ -0,0 +1,34 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.axis2.itests; + +import org.apache.axiom.om.OMElement; +import org.osoa.sca.annotations.Reference; + +public class HelloWorldOMComponent implements HelloWorldOM { + + @Reference + public HelloWorldOM helloWorldWS; + + public OMElement getGreetings(OMElement om) { + return helloWorldWS.getGreetings(om); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/axis2/itests/HelloWorldOMService.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/axis2/itests/HelloWorldOMService.java new file mode 100644 index 0000000000..861509c003 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/axis2/itests/HelloWorldOMService.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.axis2.itests; + +import org.apache.axiom.om.OMAbstractFactory; +import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.OMFactory; + +public class HelloWorldOMService implements HelloWorldOM { + + public OMElement getGreetings(OMElement requestOM) { + String name = requestOM.getFirstElement().getText(); + + OMFactory omFactory = OMAbstractFactory.getOMFactory(); + OMElement responseOM = omFactory.createOMElement("getGreetingsResponse", "http://helloworld-om", "helloworld"); + OMElement param = omFactory.createOMElement("getGreetingsReturn", "http://helloworld-om", "helloworld"); + responseOM.addChild(param); + param.addChild(omFactory.createOMText("Hello " + name)); + + return responseOM; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/axis2/itests/HelloWorldOMTestCase.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/axis2/itests/HelloWorldOMTestCase.java new file mode 100644 index 0000000000..40aa0e4480 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/axis2/itests/HelloWorldOMTestCase.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.axis2.itests; + +import junit.framework.Assert; +import junit.framework.TestCase; + +import org.apache.axiom.om.OMAbstractFactory; +import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.OMFactory; +import org.apache.axiom.om.OMText; +import org.apache.tuscany.sca.host.embedded.SCADomain; + +public class HelloWorldOMTestCase extends TestCase { + + private SCADomain domain; + private HelloWorldOM helloWorld; + + public void testCalculator() throws Exception { + OMFactory fac = OMAbstractFactory.getOMFactory(); + OMElement requestOM = fac.createOMElement("getGreetings", "http://helloworld-om", "helloworld"); + OMElement parmE = fac.createOMElement("name", "http://helloworld-om", "helloworld"); + requestOM.addChild(parmE); + parmE.addChild(fac.createOMText("petra")); + OMElement responseOM = helloWorld.getGreetings(requestOM); + OMElement child = (OMElement)responseOM.getFirstElement(); + Assert.assertEquals("Hello petra", ((OMText)child.getFirstOMChild()).getText()); + } + + protected void setUp() throws Exception { + domain = SCADomain.newInstance("org/apache/tuscany/sca/binding/axis2/itests/helloworld-om.composite"); + helloWorld = domain.getService(HelloWorldOM.class, "HelloWorldComponent"); + } + + protected void tearDown() throws Exception { + domain.close(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/axis2/itests/HelloWorldService.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/axis2/itests/HelloWorldService.java new file mode 100644 index 0000000000..d7d6b93f34 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/axis2/itests/HelloWorldService.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.axis2.itests; + +public class HelloWorldService implements HelloWorld { + + public String getGreetings(String s) { + return "Hello " + s; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/axis2/itests/HelloWorldTestCaseFIXME.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/axis2/itests/HelloWorldTestCaseFIXME.java new file mode 100644 index 0000000000..ee42e8cb5f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/axis2/itests/HelloWorldTestCaseFIXME.java @@ -0,0 +1,44 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.axis2.itests; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.host.embedded.SCADomain; + +public class HelloWorldTestCaseFIXME extends TestCase { + + private SCADomain domain; + private HelloWorld helloWorld; + + public void testCalculator() throws Exception { + assertEquals("Hello petra", helloWorld.getGreetings("petra")); + } + + protected void setUp() throws Exception { + domain = SCADomain.newInstance("org/apache/tuscany/sca/binding/axis2/itests/HelloWorld.composite"); + helloWorld = domain.getService(HelloWorld.class, "HelloWorldComponent"); + } + + protected void tearDown() throws Exception { + domain.close(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/axis2/itests/QuestionMarkWSDLTestCaseFIXME.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/axis2/itests/QuestionMarkWSDLTestCaseFIXME.java new file mode 100644 index 0000000000..768daa32c1 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/axis2/itests/QuestionMarkWSDLTestCaseFIXME.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.axis2.itests; + +import java.util.List; + +import javax.wsdl.Definition; +import javax.wsdl.Port; +import javax.wsdl.Service; +import javax.wsdl.extensions.soap.SOAPAddress; +import javax.wsdl.factory.WSDLFactory; +import javax.wsdl.xml.WSDLReader; +import javax.xml.namespace.QName; + +import junit.framework.TestCase; + +import org.apache.axis2.transport.http.server.HttpUtils; +import org.apache.tuscany.sca.host.embedded.SCADomain; + +/** + * TODO: This doesn't work right now as it seems to cause hangs when running + * from mvn. Also running in eclipse mostly only works if you comment out + * one of the test methods. + */ +public class QuestionMarkWSDLTestCaseFIXME extends TestCase { + + private SCADomain domain; + + /** + * Tests ?wsdl works and returns the correct port endpoint from the WSDL + */ + public void testWSDLPortEndpoint() throws Exception { + WSDLReader wsdlReader = WSDLFactory.newInstance().newWSDLReader(); + wsdlReader.setFeature("javax.wsdl.verbose",false); + wsdlReader.setFeature("javax.wsdl.importDocuments",true); + + Definition definition = wsdlReader.readWSDL("http://localhost:8085/services/HelloWorldWebService?wsdl"); + assertNotNull(definition); + Service service = definition.getService(new QName("http://helloworld-om", "HelloWorldService")); + Port port = service.getPort("HelloWorldSoapPort"); + + String endpoint = getEndpoint(port); + String ip = HttpUtils.getIpAddress(); + assertEquals("http://" + ip + ":8085/services/HelloWorldWebService", endpoint); + } + + /** + * Tests ?wsdl works and returns the correct port endpoint from binding.ws with a custom URI + */ + public void testCustomEndpoint() throws Exception { + WSDLReader wsdlReader = WSDLFactory.newInstance().newWSDLReader(); + wsdlReader.setFeature("javax.wsdl.verbose",false); + wsdlReader.setFeature("javax.wsdl.importDocuments",true); + + Definition definition = wsdlReader.readWSDL("http://localhost:8085/HelloWorldService/foo/bar?wsdl"); + assertNotNull(definition); + Service service = definition.getService(new QName("http://helloworld-om", "HelloWorldService")); + Port port = service.getPort("HelloWorldSoapPort"); + + String endpoint = getEndpoint(port); + String ip = HttpUtils.getIpAddress(); + assertEquals("http://" + ip + ":8085/HelloWorldService/foo/bar", endpoint); + } + + protected String getEndpoint(Port port) { + List wsdlPortExtensions = port.getExtensibilityElements(); + for (final Object extension : wsdlPortExtensions) { + if (extension instanceof SOAPAddress) { + return ((SOAPAddress) extension).getLocationURI(); + } + } + throw new RuntimeException("no SOAPAddress"); + } + + protected void setUp() throws Exception { + domain = SCADomain.newInstance("org/apache/tuscany/sca/binding/axis2/itests/questionmark-wsdl.composite"); + } + + protected void tearDown() throws Exception { + domain.close(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/axis2/itests/endpoints/AbstractHelloWorldOMTestCase.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/axis2/itests/endpoints/AbstractHelloWorldOMTestCase.java new file mode 100644 index 0000000000..b52c10e341 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/axis2/itests/endpoints/AbstractHelloWorldOMTestCase.java @@ -0,0 +1,62 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.axis2.itests.endpoints; + +import junit.framework.Assert; +import junit.framework.TestCase; + +import org.apache.axiom.om.OMAbstractFactory; +import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.OMFactory; +import org.apache.axiom.om.OMText; +import org.apache.tuscany.sca.binding.axis2.itests.HelloWorldOM; +import org.apache.tuscany.sca.host.embedded.SCADomain; + +public abstract class AbstractHelloWorldOMTestCase extends TestCase { + + private SCADomain domain; + private HelloWorldOM helloWorld; + + public void testCalculator() throws Exception { + OMFactory fac = OMAbstractFactory.getOMFactory(); + OMElement requestOM = fac.createOMElement("getGreetings", "http://helloworld-om", "helloworld"); + OMElement parmE = fac.createOMElement("name", "http://helloworld-om", "helloworld"); + requestOM.addChild(parmE); + parmE.addChild(fac.createOMText("petra")); + OMElement responseOM = helloWorld.getGreetings(requestOM); + OMElement child = (OMElement)responseOM.getFirstElement(); + Assert.assertEquals("Hello petra", ((OMText)child.getFirstOMChild()).getText()); + } + + protected void setUp() throws Exception { + domain = SCADomain.newInstance(getCompositeName()); + helloWorld = domain.getService(HelloWorldOM.class, "HelloWorldComponent"); + } + + protected void tearDown() throws Exception { + domain.close(); + } + + protected String getCompositeName() { + String className = this.getClass().getName(); + return className.substring(0, className.length() - 8).replace('.', '/') + ".composite"; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/axis2/itests/endpoints/DefaultMultiServiceTestCase.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/axis2/itests/endpoints/DefaultMultiServiceTestCase.java new file mode 100644 index 0000000000..3f1677fa90 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/axis2/itests/endpoints/DefaultMultiServiceTestCase.java @@ -0,0 +1,24 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.axis2.itests.endpoints; + +public class DefaultMultiServiceTestCase extends AbstractHelloWorldOMTestCase { + // super class does it all getting composite based on this class name +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/axis2/itests/endpoints/DefaultSingleServiceTestCase.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/axis2/itests/endpoints/DefaultSingleServiceTestCase.java new file mode 100644 index 0000000000..9b0ee7304d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/axis2/itests/endpoints/DefaultSingleServiceTestCase.java @@ -0,0 +1,24 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.axis2.itests.endpoints; + +public class DefaultSingleServiceTestCase extends AbstractHelloWorldOMTestCase { + // super class does it all getting composite based on this class name +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/axis2/itests/endpoints/WSDLExplicitURITestCase.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/axis2/itests/endpoints/WSDLExplicitURITestCase.java new file mode 100644 index 0000000000..7155d80100 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/axis2/itests/endpoints/WSDLExplicitURITestCase.java @@ -0,0 +1,24 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.axis2.itests.endpoints; + +public class WSDLExplicitURITestCase extends AbstractHelloWorldOMTestCase { + // super class does it all getting composite based on this class name +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/axis2/itests/endpoints/WSDLRelativeURITestCase.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/axis2/itests/endpoints/WSDLRelativeURITestCase.java new file mode 100644 index 0000000000..ce862be74e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/java/org/apache/tuscany/sca/binding/axis2/itests/endpoints/WSDLRelativeURITestCase.java @@ -0,0 +1,24 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.axis2.itests.endpoints; + +public class WSDLRelativeURITestCase extends AbstractHelloWorldOMTestCase { + // super class does it all getting composite based on this class name +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/axis2/itests/HelloWorld.composite b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/axis2/itests/HelloWorld.composite new file mode 100644 index 0000000000..ceb026d253 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/axis2/itests/HelloWorld.composite @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/axis2/itests/endpoints/DefaultMultiService.composite b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/axis2/itests/endpoints/DefaultMultiService.composite new file mode 100644 index 0000000000..b4daa4822f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/axis2/itests/endpoints/DefaultMultiService.composite @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/axis2/itests/endpoints/DefaultSingleService.composite b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/axis2/itests/endpoints/DefaultSingleService.composite new file mode 100644 index 0000000000..3cfffc5310 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/axis2/itests/endpoints/DefaultSingleService.composite @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/axis2/itests/endpoints/WSDLExplicitURI.composite b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/axis2/itests/endpoints/WSDLExplicitURI.composite new file mode 100644 index 0000000000..046bf60d53 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/axis2/itests/endpoints/WSDLExplicitURI.composite @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/axis2/itests/endpoints/WSDLRelativeURI.composite b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/axis2/itests/endpoints/WSDLRelativeURI.composite new file mode 100644 index 0000000000..48d47b7564 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/axis2/itests/endpoints/WSDLRelativeURI.composite @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/axis2/itests/endpoints/helloworld-om-relative-uri.wsdl b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/axis2/itests/endpoints/helloworld-om-relative-uri.wsdl new file mode 100644 index 0000000000..fe68755c47 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/axis2/itests/endpoints/helloworld-om-relative-uri.wsdl @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/axis2/itests/helloworld-om-uri.wsdl b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/axis2/itests/helloworld-om-uri.wsdl new file mode 100644 index 0000000000..baa223f41c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/axis2/itests/helloworld-om-uri.wsdl @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/axis2/itests/helloworld-om.composite b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/axis2/itests/helloworld-om.composite new file mode 100644 index 0000000000..bf76c5c8a8 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/axis2/itests/helloworld-om.composite @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/axis2/itests/helloworld-om.wsdl b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/axis2/itests/helloworld-om.wsdl new file mode 100644 index 0000000000..73ca02246d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/axis2/itests/helloworld-om.wsdl @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/axis2/itests/helloworld.wsdl b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/axis2/itests/helloworld.wsdl new file mode 100644 index 0000000000..4c85637f0d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/axis2/itests/helloworld.wsdl @@ -0,0 +1,80 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/axis2/itests/questionmark-wsdl.composite b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/axis2/itests/questionmark-wsdl.composite new file mode 100644 index 0000000000..fca9a4d754 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-axis2/src/test/resources/org/apache/tuscany/sca/binding/axis2/itests/questionmark-wsdl.composite @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-xml/.checkstyle b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-xml/.checkstyle new file mode 100644 index 0000000000..e3c216986d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-xml/.checkstyle @@ -0,0 +1,24 @@ + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-xml/.pmd b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-xml/.pmd new file mode 100644 index 0000000000..2db10d6a6a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-xml/.pmd @@ -0,0 +1,20 @@ + + +truefalse \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-xml/.ruleset b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-xml/.ruleset new file mode 100644 index 0000000000..ba9b5ce886 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-xml/.ruleset @@ -0,0 +1,190 @@ + + + + PMD Plugin preferences rule set + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-xml/DISCLAIMER b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-xml/DISCLAIMER new file mode 100644 index 0000000000..d68a410903 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-xml/DISCLAIMER @@ -0,0 +1,8 @@ +Apache Tuscany is an effort undergoing incubation at The Apache Software +Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is +required of all newly accepted projects until a further review indicates that +the infrastructure, communications, and decision making process have stabilized +in a manner consistent with other successful ASF projects. While incubation +status is not necessarily a reflection of the completeness or stability of the +code, it does indicate that the project has yet to be fully endorsed by the ASF. + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-xml/LICENSE b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-xml/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-xml/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-xml/NOTICE b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-xml/NOTICE new file mode 100644 index 0000000000..94481d6cfa --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-xml/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2007 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-xml/pom.xml b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-xml/pom.xml new file mode 100644 index 0000000000..366e5df2c7 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-xml/pom.xml @@ -0,0 +1,61 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 0.91-incubating-SNAPSHOT + ../pom.xml + + tuscany-binding-ws-xml + Apache Tuscany SCA XML Web Service Binding Extension + + + + org.apache.tuscany.sca + tuscany-contribution + 0.91-incubating-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-assembly-xml + 0.91-incubating-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-binding-ws + 0.91-incubating-SNAPSHOT + + + org.apache.tuscany.sca + tuscany-interface-wsdl + 0.91-incubating-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-interface-wsdl-xml + 0.91-incubating-SNAPSHOT + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-xml/src/main/java/org/apache/tuscany/sca/binding/ws/xml/WebServiceBindingProcessor.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-xml/src/main/java/org/apache/tuscany/sca/binding/ws/xml/WebServiceBindingProcessor.java new file mode 100644 index 0000000000..36afd1d92b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-xml/src/main/java/org/apache/tuscany/sca/binding/ws/xml/WebServiceBindingProcessor.java @@ -0,0 +1,334 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.ws.xml; + +import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; + +import java.util.List; +import java.util.Map; +import java.util.StringTokenizer; + +import javax.wsdl.Definition; +import javax.wsdl.Port; +import javax.wsdl.PortType; +import javax.wsdl.Service; +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.xml.Constants; +import org.apache.tuscany.sca.binding.ws.WebServiceBinding; +import org.apache.tuscany.sca.binding.ws.WebServiceBindingFactory; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.contribution.service.ContributionResolveException; +import org.apache.tuscany.sca.contribution.service.ContributionWriteException; +import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLDefinition; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLFactory; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterface; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterfaceContract; +import org.apache.tuscany.sca.interfacedef.wsdl.introspect.WSDLInterfaceIntrospector; +import org.apache.tuscany.sca.policy.Intent; +import org.apache.tuscany.sca.policy.PolicyFactory; +import org.apache.tuscany.sca.policy.PolicySet; +import org.apache.tuscany.sca.policy.PolicySetAttachPoint; + +public class WebServiceBindingProcessor implements + StAXArtifactProcessor, WebServiceConstants { + + private WSDLFactory wsdlFactory; + private WSDLInterfaceIntrospector introspector; + private WebServiceBindingFactory wsFactory; + private PolicyFactory policyFactory; + + public WebServiceBindingProcessor(AssemblyFactory assemblyFactory, + PolicyFactory policyFactory, + WebServiceBindingFactory wsFactory, + WSDLFactory wsdlFactory, + WSDLInterfaceIntrospector introspector) { + this.policyFactory = policyFactory; + this.wsFactory = wsFactory; + this.introspector = introspector; + this.wsdlFactory = wsdlFactory; + } + + public WebServiceBinding read(XMLStreamReader reader) throws ContributionReadException { + try { + + // Read a + WebServiceBinding wsBinding = wsFactory.createWebServiceBinding(); + wsBinding.setUnresolved(true); + + // Read policies + readPolicies(wsBinding, reader); + + // Read URI + wsBinding.setURI(reader.getAttributeValue(null, Constants.URI)); + + // Read a qname in the form: + // namespace#wsdl.???(name) + String wsdlElement = reader.getAttributeValue(null, WSDL_ELEMENT); + if (wsdlElement != null) { + int index = wsdlElement.indexOf('#'); + if (index == -1) { + throw new ContributionReadException( + "Invalid WebService binding wsdlElement attribute: " + wsdlElement); + } + String namespace = wsdlElement.substring(0, index); + wsBinding.setNamespace(namespace); + String name = wsdlElement.substring(index + 1); + if (name.startsWith("wsdl.service")) { + + // Read a wsdl.service + name = name.substring("wsdl.service(".length(), name.length() - 1); + wsBinding.setServiceName(new QName(namespace, name)); + + } else if (name.startsWith("wsdl.port")) { + + // Read a wsdl.port + name = name.substring("wsdl.port(".length(), name.length() - 1); + int s = name.indexOf('/'); + if (s == -1) { + throw new ContributionReadException( + "Invalid WebService binding wsdlElement attribute: " + wsdlElement); + } + wsBinding.setServiceName(new QName(namespace, name.substring(0, s))); + wsBinding.setPortName(name.substring(s + 1)); + + } else if (name.startsWith("wsdl.endpoint")) { + + // Read a wsdl.endpoint + name = name.substring("wsdl.endpoint(".length(), name.length() - 1); + int s = name.indexOf('/'); + if (s == -1) { + throw new ContributionReadException( + "Invalid WebService binding wsdlElement attribute: " + wsdlElement); + } + wsBinding.setServiceName(new QName(namespace, name.substring(0, s))); + wsBinding.setEndpointName(name.substring(s + 1)); + + } else if (name.startsWith("wsdl.binding")) { + + // Read a wsdl.service + name = name.substring("wsdl.binding(".length(), name.length() - 1); + wsBinding.setBindingName(new QName(namespace, name)); + + } else { + throw new ContributionReadException( + "Invalid WebService binding wsdlElement attribute: " + wsdlElement); + } + } + + // Read wsdlLocation + wsBinding.setLocation(reader.getAttributeValue(WSDLI_NS, WSDL_LOCATION)); + + // Skip to end element + while (reader.hasNext()) { + if (reader.next() == END_ELEMENT && BINDING_WS_QNAME.equals(reader.getName())) { + break; + } + } + return wsBinding; + + } catch (XMLStreamException e) { + throw new ContributionReadException(e); + } + } + + public void write(WebServiceBinding wsBinding, XMLStreamWriter writer) throws ContributionWriteException { + try { + // Write a + writer.writeStartElement(Constants.SCA10_NS, BINDING_WS); + + // Write binding URI + if (wsBinding.getURI() != null) { + writer.writeAttribute(Constants.URI, wsBinding.getURI()); + } + + // Write wsdlElement attribute + if (wsBinding.getPortName() != null) { + + // Write namespace#wsdl.port(service/port) + String wsdlElement = wsBinding.getServiceName().getNamespaceURI() + "#wsdl.port(" + + wsBinding.getServiceName().getLocalPart() + + "/" + + wsBinding.getPortName() + + ")"; + writer.writeAttribute(WSDL_ELEMENT, wsdlElement); + + } else if (wsBinding.getEndpointName() != null) { + + // Write namespace#wsdl.endpoint(service/endpoint) + String wsdlElement = wsBinding.getServiceName().getNamespaceURI() + "#wsdl.endpoint(" + + wsBinding.getServiceName().getLocalPart() + + "/" + + wsBinding.getEndpointName() + + ")"; + writer.writeAttribute(WSDL_ELEMENT, wsdlElement); + + } else if (wsBinding.getBindingName() != null) { + + // Write namespace#wsdl.binding(binding) + String wsdlElement = wsBinding.getBindingName().getNamespaceURI() + "#wsdl.binding(" + + wsBinding.getBindingName().getLocalPart() + + ")"; + writer.writeAttribute(WSDL_ELEMENT, wsdlElement); + + } else if (wsBinding.getServiceName() != null) { + + // Write namespace#wsdl.service(service) + String wsdlElement = wsBinding.getServiceName().getNamespaceURI() + "#wsdl.service(" + + wsBinding.getServiceName().getLocalPart() + + ")"; + writer.writeAttribute(WSDL_ELEMENT, wsdlElement); + } + + // Write location + if (wsBinding.getLocation() != null) { + writer.writeAttribute(WSDLI_NS, WSDL_LOCATION, wsBinding.getLocation()); + } + + writer.writeEndElement(); + + } catch (XMLStreamException e) { + throw new ContributionWriteException(e); + } + } + + public void resolve(WebServiceBinding model, ModelResolver resolver) throws ContributionResolveException { + WSDLDefinition wsdlDefinition = wsdlFactory.createWSDLDefinition(); + wsdlDefinition.setUnresolved(true); + wsdlDefinition.setNamespace(model.getNamespace()); + wsdlDefinition = resolver.resolveModel(WSDLDefinition.class, wsdlDefinition); + if (!wsdlDefinition.isUnresolved()) { + model.setDefinition(wsdlDefinition); + Definition definition = wsdlDefinition.getDefinition(); + if (model.getBindingName() != null) { + model.setBinding(definition.getBinding(model.getBindingName())); + } + if (model.getServiceName() != null) { + Service service = definition.getService(model.getServiceName()); + model.setService(service); + if (service != null && model.getPortName() != null) { + Port port = service.getPort(model.getPortName()); + model.setPort(port); + model.setBinding(port.getBinding()); + } + } + + PortType portType = getPortType(model); + if (portType != null) { + WSDLInterfaceContract interfaceContract = wsdlFactory.createWSDLInterfaceContract(); + WSDLInterface wsdlInterface; + try { + wsdlInterface = introspector.introspect(portType, + wsdlDefinition.getInlinedSchemas(), + resolver); + } catch (InvalidInterfaceException e) { + throw new ContributionResolveException(e); + } + interfaceContract.setInterface(wsdlInterface); + model.setBindingInterfaceContract(interfaceContract); + } + } + } + + private PortType getPortType(WebServiceBinding model) { + PortType portType = null; + if (model.getService() != null) { + // FIXME: How to find the compatible port? + Map ports = model.getService().getPorts(); + if (!ports.isEmpty()) { + Port port = (Port)ports.values().iterator().next(); + portType = port.getBinding().getPortType(); + } + } else if (model.getPort() != null) { + portType = model.getPort().getBinding().getPortType(); + } else if (model.getEndpoint() != null) { + portType = model.getPort().getBinding().getPortType(); + } else if (model.getBinding() != null) { + portType = model.getBinding().getPortType(); + } + return portType; + } + + public QName getArtifactType() { + return WebServiceConstants.BINDING_WS_QNAME; + } + + public Class getModelType() { + return WebServiceBinding.class; + } + + /** + * Reads policy intents and policy sets. + * @param attachPoint + * @param reader + */ + private void readPolicies(PolicySetAttachPoint attachPoint, XMLStreamReader reader) { + String value = reader.getAttributeValue(null, Constants.REQUIRES); + if (value != null) { + List requiredIntents = attachPoint.getRequiredIntents(); + for (StringTokenizer tokens = new StringTokenizer(value); tokens.hasMoreTokens();) { + QName qname = getQNameValue(reader, tokens.nextToken()); + Intent intent = policyFactory.createIntent(); + intent.setName(qname); + requiredIntents.add(intent); + } + } + + value = reader.getAttributeValue(null, Constants.POLICY_SETS); + if (value != null) { + List policySets = attachPoint.getPolicySets(); + for (StringTokenizer tokens = new StringTokenizer(value); tokens.hasMoreTokens();) { + QName qname = getQNameValue(reader, tokens.nextToken()); + PolicySet policySet = policyFactory.createPolicySet(); + policySet.setName(qname); + policySets.add(policySet); + } + } + } + + /** + * Returns a qname from a string. + * @param reader + * @param value + * @return + */ + private QName getQNameValue(XMLStreamReader reader, String value) { + if (value != null) { + int index = value.indexOf(':'); + String prefix = index == -1 ? "" : value.substring(0, index); + String localName = index == -1 ? value : value.substring(index + 1); + String ns = reader.getNamespaceContext().getNamespaceURI(prefix); + if (ns == null) { + ns = ""; + } + return new QName(ns, localName, prefix); + } else { + return null; + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-xml/src/main/java/org/apache/tuscany/sca/binding/ws/xml/WebServiceConstants.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-xml/src/main/java/org/apache/tuscany/sca/binding/ws/xml/WebServiceConstants.java new file mode 100644 index 0000000000..34d0fc4949 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-xml/src/main/java/org/apache/tuscany/sca/binding/ws/xml/WebServiceConstants.java @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.ws.xml; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.xml.Constants; + +public interface WebServiceConstants { + + String BINDING_WS = "binding.ws"; + QName BINDING_WS_QNAME = new QName(Constants.SCA10_NS, BINDING_WS); + String WSDL_ELEMENT = "wsdlElement"; + QName WSDL_ELEMENT_QNAME = new QName(Constants.SCA10_NS, WSDL_ELEMENT); + String WSDL_LOCATION = "wsdlLocation"; + String WSDLI_NS = "http://www.w3.org/2004/08/wsdl-instance"; + QName WSDL_LOCATION_QNAME = new QName(WSDLI_NS, WSDL_LOCATION); + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-xml/src/test/java/org/apache/tuscany/sca/binding/ws/xml/ReadTestCase.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-xml/src/test/java/org/apache/tuscany/sca/binding/ws/xml/ReadTestCase.java new file mode 100644 index 0000000000..8a0e462624 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-xml/src/test/java/org/apache/tuscany/sca/binding/ws/xml/ReadTestCase.java @@ -0,0 +1,121 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.ws.xml; + +import java.io.InputStream; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLOutputFactory; +import javax.xml.stream.XMLStreamReader; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.ComponentType; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory; +import org.apache.tuscany.sca.assembly.DefaultSCABindingFactory; +import org.apache.tuscany.sca.assembly.SCABindingFactory; +import org.apache.tuscany.sca.assembly.builder.impl.CompositeBuilderImpl; +import org.apache.tuscany.sca.assembly.xml.ComponentTypeProcessor; +import org.apache.tuscany.sca.assembly.xml.CompositeProcessor; +import org.apache.tuscany.sca.binding.ws.DefaultWebServiceBindingFactory; +import org.apache.tuscany.sca.binding.ws.WebServiceBindingFactory; +import org.apache.tuscany.sca.contribution.processor.DefaultStAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; +import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; +import org.apache.tuscany.sca.interfacedef.impl.InterfaceContractMapperImpl; +import org.apache.tuscany.sca.interfacedef.wsdl.DefaultWSDLFactory; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLFactory; +import org.apache.tuscany.sca.interfacedef.wsdl.introspect.DefaultWSDLInterfaceIntrospector; +import org.apache.tuscany.sca.interfacedef.wsdl.introspect.WSDLInterfaceIntrospector; +import org.apache.tuscany.sca.policy.DefaultPolicyFactory; +import org.apache.tuscany.sca.policy.PolicyFactory; + +/** + * Test reading WSDL interfaces. + * + * @version $Rev$ $Date$ + */ +public class ReadTestCase extends TestCase { + + XMLInputFactory inputFactory; + DefaultStAXArtifactProcessorExtensionPoint staxProcessors; + ExtensibleStAXArtifactProcessor staxProcessor; + private AssemblyFactory assemblyFactory; + private SCABindingFactory scaBindingFactory; + private PolicyFactory policyFactory; + private InterfaceContractMapper mapper; + private WebServiceBindingFactory wsFactory; + private WSDLInterfaceIntrospector introspector; + private WSDLFactory wsdlFactory; + + public void setUp() throws Exception { + assemblyFactory = new DefaultAssemblyFactory(); + scaBindingFactory = new DefaultSCABindingFactory(); + policyFactory = new DefaultPolicyFactory(); + mapper = new InterfaceContractMapperImpl(); + inputFactory = XMLInputFactory.newInstance(); + staxProcessors = new DefaultStAXArtifactProcessorExtensionPoint(); + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, XMLInputFactory.newInstance(), XMLOutputFactory.newInstance()); + wsFactory = new DefaultWebServiceBindingFactory(); + wsdlFactory = new DefaultWSDLFactory(); + + introspector = new DefaultWSDLInterfaceIntrospector(wsdlFactory); + + WebServiceBindingProcessor wsdlProcessor = new WebServiceBindingProcessor( + assemblyFactory, policyFactory, wsFactory, + wsdlFactory, introspector); + staxProcessors.addArtifactProcessor(wsdlProcessor); + } + + public void tearDown() throws Exception { + inputFactory = null; + staxProcessors = null; + staxProcessor = null; + policyFactory = null; + assemblyFactory = null; + mapper = null; + } + + public void testReadComponentType() throws Exception { + ComponentTypeProcessor componentTypeProcessor = new ComponentTypeProcessor(assemblyFactory, policyFactory, staxProcessor); + InputStream is = getClass().getResourceAsStream("CalculatorImpl.componentType"); + XMLStreamReader reader = inputFactory.createXMLStreamReader(is); + ComponentType componentType = componentTypeProcessor.read(reader); + assertNotNull(componentType); + + //new PrintUtil(System.out).print(componentType); + } + + public void testReadComposite() throws Exception { + CompositeProcessor compositeProcessor = new CompositeProcessor(assemblyFactory, policyFactory, mapper, staxProcessor); + InputStream is = getClass().getResourceAsStream("Calculator.composite"); + XMLStreamReader reader = inputFactory.createXMLStreamReader(is); + Composite composite = compositeProcessor.read(reader); + assertNotNull(composite); + + CompositeBuilderImpl compositeUtil = new CompositeBuilderImpl(assemblyFactory, scaBindingFactory, mapper, null); + compositeUtil.build(composite); + + //new PrintUtil(System.out).print(composite); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-xml/src/test/java/org/apache/tuscany/sca/binding/ws/xml/WriteTestCase.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-xml/src/test/java/org/apache/tuscany/sca/binding/ws/xml/WriteTestCase.java new file mode 100644 index 0000000000..b686cbacaf --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-xml/src/test/java/org/apache/tuscany/sca/binding/ws/xml/WriteTestCase.java @@ -0,0 +1,112 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.ws.xml; + +import java.io.ByteArrayOutputStream; +import java.io.InputStream; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLOutputFactory; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.ComponentType; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory; +import org.apache.tuscany.sca.assembly.xml.ComponentTypeProcessor; +import org.apache.tuscany.sca.assembly.xml.CompositeProcessor; +import org.apache.tuscany.sca.assembly.xml.ConstrainingTypeProcessor; +import org.apache.tuscany.sca.binding.ws.DefaultWebServiceBindingFactory; +import org.apache.tuscany.sca.binding.ws.WebServiceBindingFactory; +import org.apache.tuscany.sca.contribution.processor.DefaultStAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; +import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; +import org.apache.tuscany.sca.interfacedef.impl.InterfaceContractMapperImpl; +import org.apache.tuscany.sca.interfacedef.wsdl.DefaultWSDLFactory; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLFactory; +import org.apache.tuscany.sca.interfacedef.wsdl.introspect.DefaultWSDLInterfaceIntrospector; +import org.apache.tuscany.sca.interfacedef.wsdl.introspect.WSDLInterfaceIntrospector; +import org.apache.tuscany.sca.policy.DefaultPolicyFactory; +import org.apache.tuscany.sca.policy.PolicyFactory; + +/** + * Test reading/write WSDL interfaces. + * + * @version $Rev$ $Date$ + */ +public class WriteTestCase extends TestCase { + + XMLInputFactory inputFactory; + DefaultStAXArtifactProcessorExtensionPoint staxProcessors; + ExtensibleStAXArtifactProcessor staxProcessor; + private AssemblyFactory factory; + private PolicyFactory policyFactory; + private InterfaceContractMapper mapper; + private WebServiceBindingFactory wsFactory; + private WSDLInterfaceIntrospector introspector; + private WSDLFactory wsdlFactory; + + public void setUp() throws Exception { + factory = new DefaultAssemblyFactory(); + policyFactory = new DefaultPolicyFactory(); + mapper = new InterfaceContractMapperImpl(); + inputFactory = XMLInputFactory.newInstance(); + staxProcessors = new DefaultStAXArtifactProcessorExtensionPoint(); + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, XMLInputFactory.newInstance(), XMLOutputFactory.newInstance()); + wsFactory = new DefaultWebServiceBindingFactory(); + introspector = new DefaultWSDLInterfaceIntrospector(wsdlFactory); + wsdlFactory = new DefaultWSDLFactory(); + + staxProcessors.addArtifactProcessor(new CompositeProcessor(factory, policyFactory, mapper, staxProcessor)); + staxProcessors.addArtifactProcessor(new ComponentTypeProcessor(factory, policyFactory, staxProcessor)); + staxProcessors.addArtifactProcessor(new ConstrainingTypeProcessor(factory, policyFactory, staxProcessor)); + + WebServiceBindingProcessor wsdlProcessor = new WebServiceBindingProcessor( + factory, policyFactory, wsFactory, + wsdlFactory, introspector); + staxProcessors.addArtifactProcessor(wsdlProcessor); + } + + public void tearDown() throws Exception { + inputFactory = null; + staxProcessors = null; + policyFactory = null; + factory = null; + mapper = null; + } + + public void testReadWriteComponentType() throws Exception { + InputStream is = getClass().getResourceAsStream("CalculatorImpl.componentType"); + ComponentType componentType = staxProcessor.read(is, ComponentType.class); + assertNotNull(componentType); + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + staxProcessor.write(componentType, bos); + } + + public void testReadWriteComposite() throws Exception { + InputStream is = getClass().getResourceAsStream("Calculator.composite"); + Composite composite = staxProcessor.read(is, Composite.class); + assertNotNull(composite); + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + staxProcessor.write(composite, bos); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/Calculator.composite b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/Calculator.composite new file mode 100644 index 0000000000..896a901862 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/Calculator.composite @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/CalculatorImpl.componentType b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/CalculatorImpl.componentType new file mode 100644 index 0000000000..e575c02d7d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/CalculatorImpl.componentType @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/example.wsdl b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/example.wsdl new file mode 100644 index 0000000000..5e8e5dad0d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/example.wsdl @@ -0,0 +1,26 @@ + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/invalid-stockquote.wsdl b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/invalid-stockquote.wsdl new file mode 100644 index 0000000000..ad81fc7867 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/invalid-stockquote.wsdl @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/ipo.xsd b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/ipo.xsd new file mode 100644 index 0000000000..241ec15d36 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/ipo.xsd @@ -0,0 +1,136 @@ + + + + + + International Purchase order schema for Example.com + Copyright 2000 Example.com. All rights reserved. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/stockquote.wsdl b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/stockquote.wsdl new file mode 100644 index 0000000000..39cd5547d9 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/stockquote.wsdl @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/test1.wsdl b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/test1.wsdl new file mode 100644 index 0000000000..8e26f7b4b5 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/test1.wsdl @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/test1.xsd b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/test1.xsd new file mode 100644 index 0000000000..c2210f4a94 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/test1.xsd @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/test2.wsdl b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/test2.wsdl new file mode 100644 index 0000000000..529b395fd5 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/test2.wsdl @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/unwrapped-stockquote.wsdl b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/unwrapped-stockquote.wsdl new file mode 100644 index 0000000000..666a7e4069 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws-xml/src/test/resources/org/apache/tuscany/sca/binding/ws/xml/unwrapped-stockquote.wsdl @@ -0,0 +1,76 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws/.checkstyle b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws/.checkstyle new file mode 100644 index 0000000000..e3c216986d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws/.checkstyle @@ -0,0 +1,24 @@ + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws/.pmd b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws/.pmd new file mode 100644 index 0000000000..2db10d6a6a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws/.pmd @@ -0,0 +1,20 @@ + + +truefalse \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws/.ruleset b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws/.ruleset new file mode 100644 index 0000000000..ba9b5ce886 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws/.ruleset @@ -0,0 +1,190 @@ + + + + PMD Plugin preferences rule set + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws/DISCLAIMER b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws/DISCLAIMER new file mode 100644 index 0000000000..d68a410903 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws/DISCLAIMER @@ -0,0 +1,8 @@ +Apache Tuscany is an effort undergoing incubation at The Apache Software +Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is +required of all newly accepted projects until a further review indicates that +the infrastructure, communications, and decision making process have stabilized +in a manner consistent with other successful ASF projects. While incubation +status is not necessarily a reflection of the completeness or stability of the +code, it does indicate that the project has yet to be fully endorsed by the ASF. + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws/LICENSE b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws/NOTICE b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws/NOTICE new file mode 100644 index 0000000000..94481d6cfa --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2007 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws/pom.xml b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws/pom.xml new file mode 100644 index 0000000000..f0d295b54a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws/pom.xml @@ -0,0 +1,66 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 0.91-incubating-SNAPSHOT + ../pom.xml + + tuscany-binding-ws + Apache Tuscany Web Service Binding Model + + + + org.apache.tuscany.sca + tuscany-assembly + 0.91-incubating-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-interface-wsdl + 0.91-incubating-SNAPSHOT + + + + wsdl4j + wsdl4j + 1.6.2 + + + + + + + apache.ws.zone + Apache WS Zone Repository + http://ws.zones.apache.org/repository2 + + true + + + false + + + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/DefaultWebServiceBindingFactory.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/DefaultWebServiceBindingFactory.java new file mode 100644 index 0000000000..04f8ab0d3c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/DefaultWebServiceBindingFactory.java @@ -0,0 +1,30 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.ws; + +import org.apache.tuscany.sca.binding.ws.impl.WebServiceBindingFactoryImpl; + +/** + * A factory for the WSDL model. + * + * @version $Rev$ $Date$ + */ +public class DefaultWebServiceBindingFactory extends WebServiceBindingFactoryImpl implements WebServiceBindingFactory { + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/WebServiceBinding.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/WebServiceBinding.java new file mode 100644 index 0000000000..ecfd9cfbc7 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/WebServiceBinding.java @@ -0,0 +1,194 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.ws; + +import javax.wsdl.Port; +import javax.wsdl.Service; +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLDefinition; + + +/** + * Represents a WebService binding. + * + * @version $Rev$ $Date$ + */ +public interface WebServiceBinding extends Binding { + + /** + * Sets the WSDL location. + * @param location the WSDL location + */ + void setLocation(String location); + + /** + * Returns the WSDL location + * @return the WSDL location + */ + String getLocation(); + + /** + * Returns the name of the WSDL service. + * + * @return the name of the WSDL service + */ + QName getServiceName(); + + /** + * Sets the name of the WSDL service. + * + * @param className the name of the WSDL service + */ + void setServiceName(QName serviceName); + + /** + * Returns the name of the WSDL port. + * + * @return the name of the WSDL port + */ + String getPortName(); + + /** + * Sets the name of the WSDL port. + * + * @param className the name of the WSDL port + */ + void setPortName(String portName); + + /** + * Returns the name of the WSDL binding. + * + * @return the name of the WSDL binding + */ + QName getBindingName(); + + /** + * Sets the name of the WSDL binding. + * + * @param className the name of the WSDL binding + */ + void setBindingName(QName bindingName); + + /** + * Returns the name of the WSDL endpoint. + * + * @return the name of the WSDL endpoint + */ + String getEndpointName(); + + /** + * Sets the name of the WSDL endpoint. + * + * @param className the name of the WSDL endpoint + */ + void setEndpointName(String endpointName); + + /** + * Returns the WSDL service + * @return the WSDL service + */ + Service getService(); + + /** + * Sets the WSDL service. + * @param service the WSDL service + */ + void setService(Service service); + + /** + * Returns the WSDL port + * @return the WSDL port + */ + Port getPort(); + + /** + * Sets the WSDL endpoint + * @param port the WSDL endpoint + */ + void setEndpoint(Port endpoint); + + /** + * Returns the WSDL endpoint + * @return the WSDL endpoint + */ + Port getEndpoint(); + + /** + * Sets the WSDL port + * @param port the WSDL port + */ + void setPort(Port port); + + /** + * Returns the WSDL binding. + * @return the WSDL binding + */ + javax.wsdl.Binding getBinding(); + + /** + * Sets the WSDL binding + * @param binding the WSDL binding + */ + void setBinding(javax.wsdl.Binding binding); + + /** + * Returns the WSDL binding. + * @return the WSDL binding + */ + WSDLDefinition getWSDLDefinition(); + + /** + * Sets the WSDL binding + * @param binding the WSDL binding + */ + void setDefinition(WSDLDefinition wsdlDefinition); + + /** + * Returns the WSDL namespace. + * @return the WSDL namespace + */ + String getNamespace(); + + /** + * Sets the WSDL namespace + * @param namspace the WSDL namspace + */ + void setNamespace(String namespace); + + /** + * Returns true if the model element is unresolved. + * + * @return true if the model element is unresolved. + */ + boolean isUnresolved(); + + /** + * Sets whether the model element is unresolved. + * + * @param unresolved whether the model element is unresolved + */ + void setUnresolved(boolean unresolved); + + InterfaceContract getBindingInterfaceContract(); + + void setBindingInterfaceContract(InterfaceContract bindingInterfaceContract); +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/WebServiceBindingFactory.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/WebServiceBindingFactory.java new file mode 100644 index 0000000000..1ad38c69e4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/WebServiceBindingFactory.java @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.ws; + +/** + * Factory for the Web Service binding model. + * + * @version $Rev$ $Date$ + */ +public interface WebServiceBindingFactory { + + /** + * Creates a new WebService binding. + * + * @return a new WebService binding + */ + WebServiceBinding createWebServiceBinding(); + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/impl/WebServiceBindingFactoryImpl.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/impl/WebServiceBindingFactoryImpl.java new file mode 100644 index 0000000000..8902dd04ee --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/impl/WebServiceBindingFactoryImpl.java @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.binding.ws.impl; + +import org.apache.tuscany.sca.binding.ws.WebServiceBinding; +import org.apache.tuscany.sca.binding.ws.WebServiceBindingFactory; + +/** + * A factory for the WSDL model. + * + * @version $Rev$ $Date$ + */ +public abstract class WebServiceBindingFactoryImpl implements WebServiceBindingFactory { + + public WebServiceBinding createWebServiceBinding() { + return new WebServiceBindingImpl(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/impl/WebServiceBindingImpl.java b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/impl/WebServiceBindingImpl.java new file mode 100644 index 0000000000..910fb652a8 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/binding-ws/src/main/java/org/apache/tuscany/sca/binding/ws/impl/WebServiceBindingImpl.java @@ -0,0 +1,242 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.binding.ws.impl; + +import java.util.ArrayList; +import java.util.List; + +import javax.wsdl.Binding; +import javax.wsdl.Port; +import javax.wsdl.Service; +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.binding.ws.WebServiceBinding; +import org.apache.tuscany.sca.interfacedef.Interface; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLDefinition; +import org.apache.tuscany.sca.interfacedef.wsdl.WSDLInterface; +import org.apache.tuscany.sca.policy.Intent; +import org.apache.tuscany.sca.policy.PolicySet; + +/** + * Represents a WebService binding. + * + * @version $Rev$ $Date$ + */ +public class WebServiceBindingImpl implements WebServiceBinding { + private String name; + private String uri; + private List policySets = new ArrayList(); + private List requiredIntents = new ArrayList(); + private boolean unresolved; + private List extensions = new ArrayList(); + + private String location; + private Binding binding; + private Service service; + private Port port; + private Port endpoint; + private QName bindingName; + private String portName; + private QName serviceName; + private String endpointName; + private WSDLDefinition wsdlDefinition; + private String wsdlNamespace; + private InterfaceContract bindingInterfaceContract; + + protected WebServiceBindingImpl() { + } + + public String getName() { + return name; + } + + public String getURI() { + return uri; + } + + public void setName(String name) { + this.name = name; + } + + public void setURI(String uri) { + this.uri = uri; + } + + public List getRequiredIntents() { + return requiredIntents; + } + + public List getPolicySets() { + return policySets; + } + + public boolean isUnresolved() { + return unresolved; + } + + public void setUnresolved(boolean unresolved) { + this.unresolved = unresolved; + } + + public List getExtensions() { + return extensions; + } + + public String getLocation() { + return location; + } + + public void setLocation(String location) { + this.location = location; + } + + public Binding getBinding() { + return binding; + } + + public QName getBindingName() { + if (isUnresolved()) { + return bindingName; + } else if (binding != null) { + return binding.getQName(); + } else { + return null; + } + } + + public String getEndpointName() { + if (isUnresolved()) { + return endpointName; + } else if (endpoint != null) { + //TODO support WSDL 2.0 + return endpoint.getName(); + } else { + return null; + } + } + + public Port getEndpoint() { + return endpoint; + } + + public Port getPort() { + return port; + } + + public String getPortName() { + if (isUnresolved()) { + return portName; + } else if (port != null) { + return port.getName(); + } else { + return null; + } + } + + public Service getService() { + return service; + } + + public QName getServiceName() { + if (isUnresolved()) { + return serviceName; + } else if (service != null) { + return service.getQName(); + } else { + return null; + } + } + + public void setBinding(Binding binding) { + this.binding = binding; + } + + public void setBindingName(QName bindingName) { + if (!isUnresolved()) { + throw new IllegalStateException(); + } + this.bindingName = bindingName; + } + + public void setEndpoint(Port endpoint) { + this.endpoint = endpoint; + } + + public void setEndpointName(String endpointName) { + if (!isUnresolved()) { + throw new IllegalStateException(); + } + this.endpointName = endpointName; + } + + public void setPort(Port port) { + this.port = port; + } + + public void setPortName(String portName) { + if (!isUnresolved()) { + throw new IllegalStateException(); + } + this.portName = portName; + } + + public void setService(Service service) { + this.service = service; + } + + public void setServiceName(QName serviceName) { + if (!isUnresolved()) { + throw new IllegalStateException(); + } + this.serviceName = serviceName; + } + + public WSDLDefinition getWSDLDefinition() { + if (wsdlDefinition == null) { + Interface iface = bindingInterfaceContract.getInterface(); + if (iface instanceof WSDLInterface) { + wsdlDefinition = ((WSDLInterface) iface).getWsdlDefinition(); + } + } + return wsdlDefinition; + } + + public void setDefinition(WSDLDefinition wsdlDefinition) { + this.wsdlDefinition = wsdlDefinition; + } + + public String getNamespace() { + return wsdlNamespace; + } + + public void setNamespace(String namespace) { + this.wsdlNamespace = namespace; + } + + public InterfaceContract getBindingInterfaceContract() { + return bindingInterfaceContract; + } + + public void setBindingInterfaceContract(InterfaceContract bindingInterfaceContract) { + this.bindingInterfaceContract = bindingInterfaceContract; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/commonj-api/DISCLAIMER b/sca-java-1.x/branches/sca-java-0.91/modules/commonj-api/DISCLAIMER new file mode 100644 index 0000000000..d68a410903 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/commonj-api/DISCLAIMER @@ -0,0 +1,8 @@ +Apache Tuscany is an effort undergoing incubation at The Apache Software +Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is +required of all newly accepted projects until a further review indicates that +the infrastructure, communications, and decision making process have stabilized +in a manner consistent with other successful ASF projects. While incubation +status is not necessarily a reflection of the completeness or stability of the +code, it does indicate that the project has yet to be fully endorsed by the ASF. + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/commonj-api/LICENSE b/sca-java-1.x/branches/sca-java-0.91/modules/commonj-api/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/commonj-api/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/commonj-api/NOTICE b/sca-java-1.x/branches/sca-java-0.91/modules/commonj-api/NOTICE new file mode 100644 index 0000000000..94481d6cfa --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/commonj-api/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2007 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/commonj-api/pom.xml b/sca-java-1.x/branches/sca-java-0.91/modules/commonj-api/pom.xml new file mode 100644 index 0000000000..cef5c5d61f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/commonj-api/pom.xml @@ -0,0 +1,46 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 0.91-incubating-SNAPSHOT + ../pom.xml + + org.apache.tuscany + commonj-api + 0.91-incubating-SNAPSHOT + Apache Tuscany Commonj API for Timer and Work Manager + + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.4 + 1.4 + + + + install + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/commonj-api/src/main/java/commonj/timers/CancelTimerListener.java b/sca-java-1.x/branches/sca-java-0.91/modules/commonj-api/src/main/java/commonj/timers/CancelTimerListener.java new file mode 100644 index 0000000000..ba252e70dc --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/commonj-api/src/main/java/commonj/timers/CancelTimerListener.java @@ -0,0 +1,38 @@ +/** + * + * Copyright 2006 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// +// This source code implements specifications defined by the BEA and IBM. +// For more information, see: +// http://dev2dev.bea.com/technologies/commonj/index.jsp +// or +// http://www.ibm.com/developerworks/library/j-commonj-sdowmt +// +// In order to remain compliant with the specification +// DO NOT add / change / or delete method signatures! +// + +package commonj.timers; + +/** + * @version $Rev$ $Date$ + */ +public interface CancelTimerListener extends TimerListener { + + void timerCancel(Timer timer); + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/commonj-api/src/main/java/commonj/timers/StopTimerListener.java b/sca-java-1.x/branches/sca-java-0.91/modules/commonj-api/src/main/java/commonj/timers/StopTimerListener.java new file mode 100644 index 0000000000..92defc4bdc --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/commonj-api/src/main/java/commonj/timers/StopTimerListener.java @@ -0,0 +1,38 @@ +/** + * + * Copyright 2006 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// +// This source code implements specifications defined by the BEA and IBM. +// For more information, see: +// http://dev2dev.bea.com/technologies/commonj/index.jsp +// or +// http://www.ibm.com/developerworks/library/j-commonj-sdowmt +// +// In order to remain compliant with the specification +// DO NOT add / change / or delete method signatures! +// + +package commonj.timers; + +/** + * @version $Rev$ $Date$ + */ +public interface StopTimerListener extends TimerListener { + + void timerStop(Timer timer); + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/commonj-api/src/main/java/commonj/timers/Timer.java b/sca-java-1.x/branches/sca-java-0.91/modules/commonj-api/src/main/java/commonj/timers/Timer.java new file mode 100644 index 0000000000..0a5c3b65fb --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/commonj-api/src/main/java/commonj/timers/Timer.java @@ -0,0 +1,41 @@ +/** + * + * Copyright 2006 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// +// This source code implements specifications defined by the BEA and IBM. +// For more information, see: +// http://dev2dev.bea.com/technologies/commonj/index.jsp +// or +// http://www.ibm.com/developerworks/library/j-commonj-sdowmt +// +// In order to remain compliant with the specification +// DO NOT add / change / or delete method signatures! +// + +package commonj.timers; + +/** + * @version $Rev$ $Date$ + */ +public interface Timer { + + boolean cancel(); + long getPeriod(); + long getScheduledExecutionTime() throws IllegalStateException; + TimerListener getTimerListener(); + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/commonj-api/src/main/java/commonj/timers/TimerListener.java b/sca-java-1.x/branches/sca-java-0.91/modules/commonj-api/src/main/java/commonj/timers/TimerListener.java new file mode 100644 index 0000000000..6e3733b5f4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/commonj-api/src/main/java/commonj/timers/TimerListener.java @@ -0,0 +1,38 @@ +/** + * + * Copyright 2006 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// +// This source code implements specifications defined by the BEA and IBM. +// For more information, see: +// http://dev2dev.bea.com/technologies/commonj/index.jsp +// or +// http://www.ibm.com/developerworks/library/j-commonj-sdowmt +// +// In order to remain compliant with the specification +// DO NOT add / change / or delete method signatures! +// + +package commonj.timers; + +/** + * @version $Rev$ $Date$ + */ +public interface TimerListener { + + void timerExpired(Timer timer); + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/commonj-api/src/main/java/commonj/timers/TimerManager.java b/sca-java-1.x/branches/sca-java-0.91/modules/commonj-api/src/main/java/commonj/timers/TimerManager.java new file mode 100644 index 0000000000..c07b6478d5 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/commonj-api/src/main/java/commonj/timers/TimerManager.java @@ -0,0 +1,79 @@ +/** + * + * Copyright 2006 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// +// This source code implements specifications defined by the BEA and IBM. +// For more information, see: +// http://dev2dev.bea.com/technologies/commonj/index.jsp +// or +// http://www.ibm.com/developerworks/library/j-commonj-sdowmt +// +// In order to remain compliant with the specification +// DO NOT add / change / or delete method signatures! +// + +package commonj.timers; + +import java.util.Date; + +/** + * @version $Rev$ $Date$ + */ +public interface TimerManager { + + static final long IMMEDIATE = 0; + static final long INDEFINITE = java.lang.Long.MAX_VALUE; + + boolean isStopped(); + + boolean isStopping(); + + boolean isSuspended() throws IllegalStateException; + + boolean isSuspending() throws IllegalStateException; + + void resume() throws IllegalStateException; + + Timer schedule(TimerListener listener, long delayInMillis) + throws IllegalStateException, IllegalArgumentException; + + Timer schedule(TimerListener listener, long delayInMillis, long repeatIntervalInMillis) + throws IllegalStateException, IllegalArgumentException; + + Timer schedule(TimerListener listener, Date scheduleDate) + throws IllegalStateException, IllegalArgumentException; + + Timer schedule(TimerListener listener, Date scheduleDate, long repeatIntervalInMillis) + throws IllegalStateException, IllegalArgumentException; + + Timer scheduleAtFixedRate(TimerListener listener, long delayInMillis, long repeatIntervalInMillis) + throws IllegalStateException, IllegalArgumentException; + + Timer scheduleAtFixedRate(TimerListener listener, Date scheduleDate, long repeatIntervalInMillis) + throws IllegalStateException, IllegalArgumentException; + + void stop() throws IllegalStateException; + + void suspend() throws IllegalStateException; + + boolean waitForStop(long timeOut) + throws InterruptedException, IllegalArgumentException; + + boolean waitForSuspend(long timOut) + throws InterruptedException, IllegalStateException, IllegalArgumentException; + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/commonj-api/src/main/java/commonj/work/RemoteWorkItem.java b/sca-java-1.x/branches/sca-java-0.91/modules/commonj-api/src/main/java/commonj/work/RemoteWorkItem.java new file mode 100644 index 0000000000..f079dce312 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/commonj-api/src/main/java/commonj/work/RemoteWorkItem.java @@ -0,0 +1,39 @@ +/** + * + * Copyright 2006 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// +// This source code implements specifications defined by the BEA and IBM. +// For more information, see: +// http://dev2dev.bea.com/technologies/commonj/index.jsp +// or +// http://www.ibm.com/developerworks/library/j-commonj-sdowmt +// +// In order to remain compliant with the specification +// DO NOT add / change / or delete method signatures! +// + +package commonj.work; + +/** + * @version $Rev$ $Date$ + */ +public interface RemoteWorkItem extends WorkItem { + + WorkManager getPinnedWorkManager(); + void release(); + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/commonj-api/src/main/java/commonj/work/Work.java b/sca-java-1.x/branches/sca-java-0.91/modules/commonj-api/src/main/java/commonj/work/Work.java new file mode 100644 index 0000000000..1071fe4a2e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/commonj-api/src/main/java/commonj/work/Work.java @@ -0,0 +1,39 @@ +/** + * + * Copyright 2006 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// +// This source code implements specifications defined by the BEA and IBM. +// For more information, see: +// http://dev2dev.bea.com/technologies/commonj/index.jsp +// or +// http://www.ibm.com/developerworks/library/j-commonj-sdowmt +// +// In order to remain compliant with the specification +// DO NOT add / change / or delete method signatures! +// + +package commonj.work; + +/** + * @version $Rev$ $Date$ + */ +public interface Work extends Runnable { + + boolean isDaemon(); + void release(); + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/commonj-api/src/main/java/commonj/work/WorkCompletedException.java b/sca-java-1.x/branches/sca-java-0.91/modules/commonj-api/src/main/java/commonj/work/WorkCompletedException.java new file mode 100644 index 0000000000..21786c4b99 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/commonj-api/src/main/java/commonj/work/WorkCompletedException.java @@ -0,0 +1,73 @@ +/** + * + * Copyright 2006 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// +// This source code implements specifications defined by the BEA and IBM. +// For more information, see: +// http://dev2dev.bea.com/technologies/commonj/index.jsp +// or +// http://www.ibm.com/developerworks/library/j-commonj-sdowmt +// +// In order to remain compliant with the specification +// DO NOT add / change / or delete method signatures! +// + +package commonj.work; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +/** + * @version $Rev$ $Date$ + */ +public class WorkCompletedException extends WorkException { + private static final long serialVersionUID = 1L; + + private final List exceptionList; + + public WorkCompletedException() { + super(); + exceptionList = Collections.EMPTY_LIST; + } + public WorkCompletedException(String message) { + super(message); + exceptionList = Collections.EMPTY_LIST; + } + public WorkCompletedException(String message, Throwable cause) { + super(message, cause); + exceptionList = Collections.singletonList(cause); + } + public WorkCompletedException(Throwable cause) { + super(cause); + exceptionList = Collections.singletonList(cause); + } + public WorkCompletedException(String message, List list) { + super(message); + if ((list != null) && (list.size() > 0)) { + initCause((Throwable) list.get(0)); + exceptionList = Collections.unmodifiableList(new ArrayList(list)); + } else { + exceptionList = Collections.EMPTY_LIST; + } + } + + public List getExceptionList() { + return exceptionList; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/commonj-api/src/main/java/commonj/work/WorkEvent.java b/sca-java-1.x/branches/sca-java-0.91/modules/commonj-api/src/main/java/commonj/work/WorkEvent.java new file mode 100644 index 0000000000..9a7814b860 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/commonj-api/src/main/java/commonj/work/WorkEvent.java @@ -0,0 +1,45 @@ +/** + * + * Copyright 2006 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// +// This source code implements specifications defined by the BEA and IBM. +// For more information, see: +// http://dev2dev.bea.com/technologies/commonj/index.jsp +// or +// http://www.ibm.com/developerworks/library/j-commonj-sdowmt +// +// In order to remain compliant with the specification +// DO NOT add / change / or delete method signatures! +// + +package commonj.work; + +/** + * @version $Rev$ $Date$ + */ +public interface WorkEvent { + + static final int WORK_ACCEPTED = 1; + static final int WORK_REJECTED = 2; + static final int WORK_STARTED = 3; + static final int WORK_COMPLETED = 4; + + WorkException getException(); + int getType(); + WorkItem getWorkItem(); + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/commonj-api/src/main/java/commonj/work/WorkException.java b/sca-java-1.x/branches/sca-java-0.91/modules/commonj-api/src/main/java/commonj/work/WorkException.java new file mode 100644 index 0000000000..3d24ec1055 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/commonj-api/src/main/java/commonj/work/WorkException.java @@ -0,0 +1,50 @@ +/** + * + * Copyright 2006 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// +// This source code implements specifications defined by the BEA and IBM. +// For more information, see: +// http://dev2dev.bea.com/technologies/commonj/index.jsp +// or +// http://www.ibm.com/developerworks/library/j-commonj-sdowmt +// +// In order to remain compliant with the specification +// DO NOT add / change / or delete method signatures! +// + +package commonj.work; + +/** + * @version $Rev$ $Date$ + */ +public class WorkException extends Exception { + private static final long serialVersionUID = 1L; + + public WorkException() { + super(); + } + public WorkException(String message) { + super(message); + } + public WorkException(String message, Throwable cause) { + super(message, cause); + } + public WorkException(Throwable cause) { + super(cause); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/commonj-api/src/main/java/commonj/work/WorkItem.java b/sca-java-1.x/branches/sca-java-0.91/modules/commonj-api/src/main/java/commonj/work/WorkItem.java new file mode 100644 index 0000000000..6b8d3185a1 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/commonj-api/src/main/java/commonj/work/WorkItem.java @@ -0,0 +1,39 @@ +/** + * + * Copyright 2006 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// +// This source code implements specifications defined by the BEA and IBM. +// For more information, see: +// http://dev2dev.bea.com/technologies/commonj/index.jsp +// or +// http://www.ibm.com/developerworks/library/j-commonj-sdowmt +// +// In order to remain compliant with the specification +// DO NOT add / change / or delete method signatures! +// + +package commonj.work; + +/** + * @version $Rev$ $Date$ + */ +public interface WorkItem extends Comparable { + + Work getResult() throws WorkException; + int getStatus(); + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/commonj-api/src/main/java/commonj/work/WorkListener.java b/sca-java-1.x/branches/sca-java-0.91/modules/commonj-api/src/main/java/commonj/work/WorkListener.java new file mode 100644 index 0000000000..9b523f7321 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/commonj-api/src/main/java/commonj/work/WorkListener.java @@ -0,0 +1,44 @@ +/** + * + * Copyright 2006 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// +// This source code implements specifications defined by the BEA and IBM. +// For more information, see: +// http://dev2dev.bea.com/technologies/commonj/index.jsp +// or +// http://www.ibm.com/developerworks/library/j-commonj-sdowmt +// +// In order to remain compliant with the specification +// DO NOT add / change / or delete method signatures! +// + +package commonj.work; + +/** + * @version $Rev$ $Date$ + */ +public interface WorkListener { + + static long IMMEDIATE = 0; + static long INDEFINITE = java.lang.Long.MAX_VALUE; + + void workAccepted(WorkEvent event); + void workCompleted(WorkEvent event); + void workRejected(WorkEvent event); + void workStarted(WorkEvent event); + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/commonj-api/src/main/java/commonj/work/WorkManager.java b/sca-java-1.x/branches/sca-java-0.91/modules/commonj-api/src/main/java/commonj/work/WorkManager.java new file mode 100644 index 0000000000..2c4167d24c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/commonj-api/src/main/java/commonj/work/WorkManager.java @@ -0,0 +1,51 @@ +/** + * + * Copyright 2006 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// +// This source code implements specifications defined by the BEA and IBM. +// For more information, see: +// http://dev2dev.bea.com/technologies/commonj/index.jsp +// or +// http://www.ibm.com/developerworks/library/j-commonj-sdowmt +// +// In order to remain compliant with the specification +// DO NOT add / change / or delete method signatures! +// + +package commonj.work; + +import java.util.Collection; + +/** + * @version $Rev$ $Date$ + */ +public interface WorkManager { + + static final long IMMEDIATE = 0; + static final long INDEFINITE = java.lang.Long.MAX_VALUE; + + WorkItem schedule(Work work) throws WorkException, IllegalArgumentException; + + WorkItem schedule(Work work, WorkListener listener) throws WorkException, IllegalArgumentException; + + boolean waitForAll(Collection workItems, long timeout) + throws InterruptedException, IllegalArgumentException; + + Collection waitForAny(Collection workItems, long timeout) + throws InterruptedException, IllegalArgumentException; + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/commonj-api/src/main/java/commonj/work/WorkRejectedException.java b/sca-java-1.x/branches/sca-java-0.91/modules/commonj-api/src/main/java/commonj/work/WorkRejectedException.java new file mode 100644 index 0000000000..cee8ea588a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/commonj-api/src/main/java/commonj/work/WorkRejectedException.java @@ -0,0 +1,50 @@ +/** + * + * Copyright 2006 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// +// This source code implements specifications defined by the BEA and IBM. +// For more information, see: +// http://dev2dev.bea.com/technologies/commonj/index.jsp +// or +// http://www.ibm.com/developerworks/library/j-commonj-sdowmt +// +// In order to remain compliant with the specification +// DO NOT add / change / or delete method signatures! +// + +package commonj.work; + +/** + * @version $Rev$ $Date$ + */ +public class WorkRejectedException extends WorkException { + private static final long serialVersionUID = 1L; + + public WorkRejectedException() { + super(); + } + public WorkRejectedException(String message) { + super(message); + } + public WorkRejectedException(String message, Throwable cause) { + super(message, cause); + } + public WorkRejectedException(Throwable cause) { + super(cause); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/.checkstyle b/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/.checkstyle new file mode 100644 index 0000000000..ace5fe6f53 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/.checkstyle @@ -0,0 +1,25 @@ + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/.pmd b/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/.pmd new file mode 100644 index 0000000000..84af2f4d5d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/.pmd @@ -0,0 +1,20 @@ + + +true diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/.ruleset b/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/.ruleset new file mode 100644 index 0000000000..ac8671859d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/.ruleset @@ -0,0 +1,190 @@ + + + + PMD Plugin preferences rule set + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/DISCLAIMER b/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/DISCLAIMER new file mode 100644 index 0000000000..d68a410903 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/DISCLAIMER @@ -0,0 +1,8 @@ +Apache Tuscany is an effort undergoing incubation at The Apache Software +Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is +required of all newly accepted projects until a further review indicates that +the infrastructure, communications, and decision making process have stabilized +in a manner consistent with other successful ASF projects. While incubation +status is not necessarily a reflection of the completeness or stability of the +code, it does indicate that the project has yet to be fully endorsed by the ASF. + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/LICENSE b/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/NOTICE b/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/NOTICE new file mode 100644 index 0000000000..94481d6cfa --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2007 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/pom.xml b/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/pom.xml new file mode 100644 index 0000000000..f75f566270 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/pom.xml @@ -0,0 +1,45 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 0.91-incubating-SNAPSHOT + ../pom.xml + + tuscany-contribution-impl + Apache Tuscany SCA Contribution Service Implementation + + + + org.apache.tuscany.sca + tuscany-contribution + 0.91-incubating-SNAPSHOT + + + + org.codehaus.woodstox + wstx-asl + 3.2.0 + runtime + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/impl/ArtifactImpl.java b/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/impl/ArtifactImpl.java new file mode 100644 index 0000000000..38920fcb19 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/impl/ArtifactImpl.java @@ -0,0 +1,71 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.contribution.impl; + +import org.apache.tuscany.sca.contribution.Artifact; + + +/** + * Base Artifact interface to accomodate common properties between Contribution and Deployed Artifact + * + * @version $Rev$ $Date$ + */ +public abstract class ArtifactImpl implements Artifact { + private String uri; + private String location; + + protected ArtifactImpl() { + } + + public String getLocation() { + return this.location; + } + + public void setLocation(String location) { + this.location = location; + } + + public String getURI() { + return this.uri; + } + + public void setURI(String uri) { + this.uri = uri; + } + + @Override + public int hashCode() { + return uri.hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (obj == this) { + return true; + } else { + if (obj instanceof Artifact) { + return uri.equals(((Artifact)obj).getURI()); + } else { + return false; + } + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/impl/ContributionExportImpl.java b/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/impl/ContributionExportImpl.java new file mode 100644 index 0000000000..90bde0f67e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/impl/ContributionExportImpl.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.contribution.impl; + +import org.apache.tuscany.sca.contribution.ContributionExport; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; + +/** + * The representation of an export for the contribution + * + * @version $Rev$ $Date$ + */ +public class ContributionExportImpl implements ContributionExport { + private String namespace; // The namespace to be imported + private ModelResolver modelResolver; + + protected ContributionExportImpl() { + } + + public String getNamespace() { + return namespace; + } + + public void setNamespace(String namespace) { + this.namespace = namespace; + } + + public ModelResolver getModelResolver() { + return modelResolver; + } + + public void setModelResolver(ModelResolver modelResolver) { + this.modelResolver = modelResolver; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/impl/ContributionFactoryImpl.java b/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/impl/ContributionFactoryImpl.java new file mode 100644 index 0000000000..a349939a0e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/impl/ContributionFactoryImpl.java @@ -0,0 +1,51 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.contribution.impl; + +import org.apache.tuscany.sca.contribution.Contribution; +import org.apache.tuscany.sca.contribution.ContributionExport; +import org.apache.tuscany.sca.contribution.ContributionFactory; +import org.apache.tuscany.sca.contribution.ContributionImport; +import org.apache.tuscany.sca.contribution.DeployedArtifact; + + +/** + * Contribution model object factory + * + * @version $Rev$ $Date$ + */ +public class ContributionFactoryImpl implements ContributionFactory { + + public Contribution createContribution() { + return new ContributionImpl(); + } + + public DeployedArtifact createDeployedArtifact() { + return new DeployedArtifactImpl(); + } + + public ContributionImport createContributionImport() { + return new ContributionImportImpl(); + } + + public ContributionExport createContributionExport() { + return new ContributionExportImpl(); + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/impl/ContributionImpl.java b/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/impl/ContributionImpl.java new file mode 100644 index 0000000000..8d246eaf1c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/impl/ContributionImpl.java @@ -0,0 +1,74 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.contribution.impl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.contribution.Contribution; +import org.apache.tuscany.sca.contribution.ContributionExport; +import org.apache.tuscany.sca.contribution.ContributionImport; +import org.apache.tuscany.sca.contribution.DeployedArtifact; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; + +/** + * The representation of a deployed contribution + * + * @version $Rev: 531146 $ $Date: 2007-04-21 22:40:50 -0700 (Sat, 21 Apr 2007) $ + */ +public class ContributionImpl extends ArtifactImpl implements Contribution { + private List exports = new ArrayList(); + private List imports = new ArrayList(); + private List deployables = new ArrayList(); + private ModelResolver modelResolver; + + /** + * A list of artifacts in the contribution + */ + private List artifacts = new ArrayList(); + + protected ContributionImpl() { + } + + public List getExports() { + return exports; + } + + public List getImports() { + return imports; + } + + public List getDeployables() { + return deployables; + } + + public List getArtifacts() { + return artifacts; + } + + public ModelResolver getModelResolver() { + return modelResolver; + } + + public void setModelResolver(ModelResolver modelResolver) { + this.modelResolver = modelResolver; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/impl/ContributionImportImpl.java b/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/impl/ContributionImportImpl.java new file mode 100644 index 0000000000..3f241ff3d0 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/impl/ContributionImportImpl.java @@ -0,0 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.contribution.impl; + +import org.apache.tuscany.sca.contribution.ContributionImport; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; + +/** + * The representation of an import for the contribution + * + * @version $Rev: 527398 $ $Date: 2007-04-10 23:43:31 -0700 (Tue, 10 Apr 2007) $ + */ +public class ContributionImportImpl implements ContributionImport { + private String namespace; // The namespace to be imported + private String location; // Optional location to hint the where it should be imported + private ModelResolver modelResolver; + + protected ContributionImportImpl() { + } + + public String getLocation() { + return location; + } + + public void setLocation(String location) { + this.location = location; + } + + public String getNamespace() { + return namespace; + } + + public void setNamespace(String namespace) { + this.namespace = namespace; + } + + public ModelResolver getModelResolver() { + return modelResolver; + } + + public void setModelResolver(ModelResolver modelResolver) { + this.modelResolver = modelResolver; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/impl/DeployedArtifactImpl.java b/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/impl/DeployedArtifactImpl.java new file mode 100644 index 0000000000..1d9bb04114 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/impl/DeployedArtifactImpl.java @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.contribution.impl; + +import org.apache.tuscany.sca.contribution.DeployedArtifact; + +/** + * Representation of a deployed artifact + * + * @version $Rev: 527398 $ $Date: 2007-04-10 23:43:31 -0700 (Tue, 10 Apr 2007) $ + */ +public class DeployedArtifactImpl extends ArtifactImpl implements DeployedArtifact { + private Object modelObject; + + protected DeployedArtifactImpl() { + super(); + } + + public Object getModel() { + return modelObject; + } + + public void setModel(Object modelObject) { + this.modelObject = modelObject; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/FolderContributionProcessor.java b/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/FolderContributionProcessor.java new file mode 100644 index 0000000000..03abd92123 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/FolderContributionProcessor.java @@ -0,0 +1,120 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.contribution.processor.impl; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.sca.contribution.ContentType; +import org.apache.tuscany.sca.contribution.processor.PackageProcessor; +import org.apache.tuscany.sca.contribution.service.ContributionException; +import org.apache.tuscany.sca.contribution.service.util.FileHelper; + +/** + * Folder contribution package processor + * + * @version $Rev$ $Date$ + */ +public class FolderContributionProcessor implements PackageProcessor { + /** + * Package-type that this package processor can handle + */ + public static final String PACKAGE_TYPE = ContentType.FOLDER; + + public FolderContributionProcessor() { + } + + public String getPackageType() { + return PACKAGE_TYPE; + } + + /** + * Recursively traverse a root directory + * + * @param fileList + * @param file + * @throws IOException + */ + private void traverse(List fileList, File file, File root) throws IOException { + if (file.isFile()) { + fileList.add(root.toURI().relativize(file.toURI())); + + } else if (file.isDirectory()) { + // FIXME: Maybe we should externalize it as a property + // Regular expression to exclude .xxx files + + String uri = root.toURI().relativize(file.toURI()).toString(); + if (uri.endsWith("/")) { + uri = uri.substring(0, uri.length() - 1); + } + fileList.add(URI.create(uri)); + + File[] files = file.listFiles(FileHelper.getFileFilter("[^\u002e].*", true)); + for (int i = 0; i < files.length; i++) { + traverse(fileList, files[i], root); + } + } + } + + public URL getArtifactURL(URL sourceURL, URI artifact) throws MalformedURLException { + return new URL(sourceURL, artifact.toString()); + } + + /** + * Get a list of artifact URI from the folder + * + * @return The list of artifact URI for the folder + * @throws IOException + */ + public List getArtifacts(URL packageSourceURL, InputStream inputStream) throws ContributionException, + IOException { + if (packageSourceURL == null) { + throw new IllegalArgumentException("Invalid null package source URL."); + } + + List artifacts = new ArrayList(); + + // Assume the root is a jar file + File rootFolder; + + try { + rootFolder = new File(packageSourceURL.toURI()); + if (rootFolder.isDirectory()) { + if (!rootFolder.exists()) { + throw new InvalidFolderContributionException(rootFolder.getAbsolutePath()); + } + + this.traverse(artifacts, rootFolder, rootFolder); + } + + } catch (URISyntaxException e) { + throw new InvalidFolderContributionURIException(packageSourceURL.toExternalForm(), e); + } + + return artifacts; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/InvalidFolderContributionException.java b/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/InvalidFolderContributionException.java new file mode 100644 index 0000000000..6dbab56553 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/InvalidFolderContributionException.java @@ -0,0 +1,41 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.contribution.processor.impl; + +import org.apache.tuscany.sca.contribution.service.ContributionException; + +/** + * Exception that indicates that the supplied XML Document invalid. + * + */ +public class InvalidFolderContributionException extends ContributionException { + + /** + * + */ + private static final long serialVersionUID = 1564255850052593282L; + + protected InvalidFolderContributionException(String componentDefinitionLocatoin) { + super(componentDefinitionLocatoin); + } + + protected InvalidFolderContributionException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/InvalidFolderContributionURIException.java b/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/InvalidFolderContributionURIException.java new file mode 100644 index 0000000000..8022834438 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/InvalidFolderContributionURIException.java @@ -0,0 +1,41 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.contribution.processor.impl; + +import org.apache.tuscany.sca.contribution.service.ContributionException; + +/** + * Exception that indicates that the supplied XML Document invalid. + * + */ +public class InvalidFolderContributionURIException extends ContributionException { + + /** + * + */ + private static final long serialVersionUID = 1564255850052593282L; + + protected InvalidFolderContributionURIException(String componentDefinitionLocatoin) { + super(componentDefinitionLocatoin); + } + + protected InvalidFolderContributionURIException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/JarContributionProcessor.java b/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/JarContributionProcessor.java new file mode 100644 index 0000000000..fb7dbb89a4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/JarContributionProcessor.java @@ -0,0 +1,94 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.contribution.processor.impl; + +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URL; +import java.util.ArrayList; +import java.util.List; +import java.util.jar.JarEntry; +import java.util.jar.JarInputStream; + +import org.apache.tuscany.sca.contribution.ContentType; +import org.apache.tuscany.sca.contribution.processor.PackageProcessor; +import org.apache.tuscany.sca.contribution.service.ContributionException; + +/** + * Jar Contribution package processor + * + * @version $Rev$ $Date$ + */ +public class JarContributionProcessor implements PackageProcessor { + /** + * Package-type that this package processor can handle + */ + public static final String PACKAGE_TYPE = ContentType.JAR; + + public JarContributionProcessor() { + } + + public String getPackageType() { + return PACKAGE_TYPE; + } + + public URL getArtifactURL(URL sourceURL, URI artifact) throws MalformedURLException { + if (sourceURL.toString().startsWith("jar:")) { + return new URL(sourceURL, artifact.toString()); + } else { + return new URL("jar:" + sourceURL.toExternalForm() + "!/" + artifact); + } + } + + public List getArtifacts(URL packageSourceURL, InputStream inputStream) throws ContributionException, + IOException { + if (packageSourceURL == null) { + throw new IllegalArgumentException("Invalid null package source URL."); + } + + if (inputStream == null) { + throw new IllegalArgumentException("Invalid null source inputstream."); + } + + List artifacts = new ArrayList(); + + // Assume the root is a jar file + JarInputStream jar = new JarInputStream(inputStream); + try { + while (true) { + JarEntry entry = jar.getNextJarEntry(); + if (entry == null) { + // EOF + break; + } + + // FIXME: Maybe we should externalize the filter as a property + if (!entry.getName().startsWith(".")) { + artifacts.add(URI.create(entry.getName())); + } + } + } finally { + jar.close(); + } + return artifacts; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/resolver/impl/ModelResolverImpl.java b/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/resolver/impl/ModelResolverImpl.java new file mode 100644 index 0000000000..6c2257803a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/resolver/impl/ModelResolverImpl.java @@ -0,0 +1,92 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.contribution.resolver.impl; + +import java.lang.ref.WeakReference; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.tuscany.sca.contribution.resolver.ClassReference; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; + +/** + * A default implementation of an artifact resolver, based on a map. + * + * @version $Rev$ $Date$ + */ +public class ModelResolverImpl implements ModelResolver { + private static final long serialVersionUID = -7826976465762296634L; + + private Map map = new HashMap(); + + private WeakReference classLoader; + + public ModelResolverImpl(ClassLoader classLoader) { + this.classLoader = new WeakReference(classLoader); + } + + public T resolveModel(Class modelClass, T unresolved) { + Object resolved = map.get(unresolved); + if (resolved != null) { + + // Return the resolved object + return modelClass.cast(resolved); + + } else if (unresolved instanceof ClassReference) { + + // Load a class on demand + ClassReference classReference = (ClassReference)unresolved; + Class clazz; + try { + clazz = Class.forName(classReference.getClassName(), true, classLoader.get()); + } catch (ClassNotFoundException e) { + + // Return the unresolved object + return unresolved; + } + + // Store a new ClassReference wrappering the loaded class + resolved = new ClassReference(clazz); + map.put(resolved, resolved); + + // Return the resolved ClassReference + return modelClass.cast(resolved); + + } else { + + // Return the unresolved object + return unresolved; + } + } + + public void addModel(Object resolved) { + map.put(resolved, resolved); + } + + public Object removeModel(Object resolved) { + return map.remove(resolved); + } + + public Collection getModels() { + return map.values(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/ArtifactTypeDescriberImpl.java b/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/ArtifactTypeDescriberImpl.java new file mode 100644 index 0000000000..174a09a0c6 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/ArtifactTypeDescriberImpl.java @@ -0,0 +1,106 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.contribution.service.impl; + +import java.io.IOException; +import java.net.URL; +import java.net.URLConnection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.tuscany.sca.contribution.ContentType; +import org.apache.tuscany.sca.contribution.Contribution; +import org.apache.tuscany.sca.contribution.service.TypeDescriber; +import org.apache.tuscany.sca.contribution.service.util.FileHelper; + +/** + * Implementation of the content describer for files + * + * @version $Rev$ $Date$ + */ +public class ArtifactTypeDescriberImpl implements TypeDescriber { + private final Map contentTypeRegistry = new HashMap(); + + public ArtifactTypeDescriberImpl() { + super(); + init(); + } + + /** + * Initialize contentType registry with know types based on known file extensions + */ + private void init() { + contentTypeRegistry.put("COMPOSITE", ContentType.COMPOSITE); + contentTypeRegistry.put("SCDL", ContentType.COMPOSITE); + contentTypeRegistry.put("WSDL", ContentType.WSDL); + contentTypeRegistry.put("JAR", ContentType.JAR); + } + + protected String resolveContentyTypeByExtension(URL resourceURL) { + String artifactExtension = FileHelper.getExtension(resourceURL.getPath()); + if (artifactExtension == null) { + return null; + } + return contentTypeRegistry.get(artifactExtension.toUpperCase()); + } + + /** + * Build contentType for a specific resource. We first check if the file is + * a supported one (looking into our registry based on resource extension) + * If not found, we try to check file contentType Or we return + * defaultContentType provided + * + * @param resourceURL The artifact url + * @param defaultContentType The default content type if we can't find the correc one + * @return The content type + */ + public String getType(URL resourceURL, String defaultContentType) { + URLConnection connection = null; + String contentType = defaultContentType; + + if (resourceURL.getProtocol().equals("file") && FileHelper.toFile(resourceURL).isDirectory()) { + // Special case : contribution is a folder + contentType = ContentType.FOLDER; + } else if (resourceURL.toExternalForm().endsWith(Contribution.SCA_CONTRIBUTION_META) + || resourceURL.toExternalForm().endsWith(Contribution.SCA_CONTRIBUTION_GENERATED_META)) { + // Special case : contribution metadata + contentType = ContentType.CONTRIBUTION_METADATA; + } else { + contentType = resolveContentyTypeByExtension(resourceURL); + if (contentType == null) { + try { + connection = resourceURL.openConnection(); + contentType = connection.getContentType(); + + if (contentType == null || contentType.equals("content/unknown")) { + // here we couldn't figure out from our registry or from URL and it's not a special file + // return defaultContentType if provided + contentType = defaultContentType; + } + } catch (IOException io) { + // could not access artifact, just ignore and we will return + // null contentType + } + } + } + return contentType == null ? defaultContentType : contentType; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/ContributionMetadataLoaderImpl.java b/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/ContributionMetadataLoaderImpl.java new file mode 100644 index 0000000000..a089756308 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/ContributionMetadataLoaderImpl.java @@ -0,0 +1,132 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.contribution.service.impl; + +import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamConstants; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.contribution.Contribution; +import org.apache.tuscany.sca.contribution.ContributionExport; +import org.apache.tuscany.sca.contribution.ContributionFactory; +import org.apache.tuscany.sca.contribution.ContributionImport; +import org.apache.tuscany.sca.contribution.service.ContributionMetadataLoader; +import org.apache.tuscany.sca.contribution.service.ContributionMetadataLoaderException; + +/** + * Loader that handles contribution metadata files + * + * @version $Rev: 515261 $ $Date: 2007-03-06 11:22:46 -0800 (Tue, 06 Mar 2007) $ + */ +public class ContributionMetadataLoaderImpl implements ContributionMetadataLoader { + private static final String SCA10_NS = "http://www.osoa.org/xmlns/sca/1.0"; + private static final String TARGET_NAMESPACE = "targetNamespace"; + + private static final QName CONTRIBUTION = new QName(SCA10_NS, "contribution"); + private static final QName DEPLOYABLE = new QName(SCA10_NS, "deployable"); + private static final QName IMPORT = new QName(SCA10_NS, "import"); + private static final QName EXPORT = new QName(SCA10_NS, "export"); + + private final AssemblyFactory assemblyFactory; + private final ContributionFactory contributionFactory; + + public ContributionMetadataLoaderImpl(AssemblyFactory assemblyFactory, ContributionFactory contributionFactory) { + super(); + this.assemblyFactory = assemblyFactory; + this.contributionFactory = contributionFactory; + } + + public QName getXMLType() { + return CONTRIBUTION; + } + + public void load(Contribution contribution, XMLStreamReader reader) throws XMLStreamException, ContributionMetadataLoaderException { + String targetNameSpaceURI = null; + + while (true) { + int event = reader.next(); + switch (event) { + case START_ELEMENT: + QName element = reader.getName(); + if (CONTRIBUTION.equals(element)) { + targetNameSpaceURI = reader.getAttributeValue(null, TARGET_NAMESPACE); + } else if (DEPLOYABLE.equals(element)) { + String name = reader.getAttributeValue(null, "composite"); + if (name == null) { + throw new InvalidValueException("Attribute 'composite' is missing"); + } + QName compositeName = null; + + int index = name.indexOf(':'); + if (index != -1) { + String prefix = name.substring(0, index); + String localPart = name.substring(index + 1); + String ns = reader.getNamespaceContext().getNamespaceURI(prefix); + if (ns == null) { + throw new InvalidValueException("Invalid prefix: " + prefix); + } + compositeName = new QName(targetNameSpaceURI, localPart, prefix); + } else { + String prefix = ""; + String localPart = name; + compositeName = new QName(targetNameSpaceURI, localPart, prefix); + } + + Composite composite = assemblyFactory.createComposite(); + composite.setName(compositeName); + composite.setUnresolved(true); + + contribution.getDeployables().add(composite); + } else if (IMPORT.equals(element)) { + String ns = reader.getAttributeValue(null, "namespace"); + if (ns == null) { + throw new InvalidValueException("Attribute 'namespace' is missing"); + } + String location = reader.getAttributeValue(null, "location"); + ContributionImport contributionImport = this.contributionFactory.createContributionImport(); + if (location != null) { + contributionImport.setLocation(location); + } + contributionImport.setNamespace(ns); + contribution.getImports().add(contributionImport); + } else if (EXPORT.equals(element)) { + String ns = reader.getAttributeValue(null, "namespace"); + if (ns == null) { + throw new InvalidValueException("Attribute 'namespace' is missing"); + } + ContributionExport contributionExport = this.contributionFactory.createContributionExport(); + contributionExport.setNamespace(ns); + contribution.getExports().add(contributionExport); + } + break; + case XMLStreamConstants.END_ELEMENT: + if (CONTRIBUTION.equals(reader.getName())) { + return; + } + break; + + } + } + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/ContributionRepositoryImpl.java b/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/ContributionRepositoryImpl.java new file mode 100644 index 0000000000..e2dc89782d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/ContributionRepositoryImpl.java @@ -0,0 +1,266 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.contribution.service.impl; + +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; +import java.io.PrintWriter; +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URL; +import java.security.AccessController; +import java.security.PrivilegedAction; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamConstants; +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.sca.contribution.service.ContributionRepository; +import org.apache.tuscany.sca.contribution.service.util.FileHelper; +import org.apache.tuscany.sca.contribution.service.util.IOHelper; + +/** + * The default implementation of ContributionRepository + * + * @version $Rev$ $Date$ + */ +public class ContributionRepositoryImpl implements ContributionRepository { + private static final String NS = "http://tuscany.apache.org/xmlns/1.0-SNAPSHOT"; + private static final String DOMAIN_INDEX_FILENAME = "sca-domain.xml"; + private final File rootFile; + private Map contributionMap = new HashMap(); + + private URI domain; + private XMLInputFactory factory; + + /** + * Constructor with repository root + * + * @param repository + */ + public ContributionRepositoryImpl(final String repository) throws IOException { + String root = repository; + if (repository == null) { + root = AccessController.doPrivileged(new PrivilegedAction() { + public String run() { + // Default to /.tuscany/domains/local/ + String userHome = System.getProperty("user.home"); + String slash = File.separator; + return userHome + slash + ".tuscany" + slash + "domains" + slash + "local" + slash; + } + }); + } + this.rootFile = new File(root); + this.domain = rootFile.toURI(); + FileHelper.forceMkdir(rootFile); + if (!rootFile.exists() || !rootFile.isDirectory() || !rootFile.canRead()) { + throw new IOException("The root is not a directory: " + repository); + } + factory = XMLInputFactory.newInstance("javax.xml.stream.XMLInputFactory", getClass().getClassLoader()); + } + + public URI getDomain() { + return domain; + } + + /** + * Resolve contribution location in the repository -> root repository / + * contribution file -> contribution group id / artifact id / version + * + * @param contribution + * @return + */ + private File mapToFile(URL sourceURL) { + String fileName = FileHelper.toFile(sourceURL).getName(); + return new File(rootFile, "contributions" + File.separator + fileName); + } + + /** + * Write a specific source inputstream to a file on disk + * + * @param source contents of the file to be written to disk + * @param target file to be written + * @throws IOException + */ + public static void copy(InputStream source, File target) throws IOException { + BufferedOutputStream out = null; + BufferedInputStream in = null; + + try { + out = new BufferedOutputStream(new FileOutputStream(target)); + in = new BufferedInputStream(source); + IOHelper.copy(in, out); + } finally { + IOHelper.closeQuietly(out); + IOHelper.closeQuietly(in); + } + } + + public URL store(String contribution, URL sourceURL, InputStream contributionStream) throws IOException { + // where the file should be stored in the repository + File location = mapToFile(sourceURL); + FileHelper.forceMkdir(location.getParentFile()); + + copy(contributionStream, location); + + // add contribution to repositoryContent + URL contributionURL = location.toURL(); + URI relative = rootFile.toURI().relativize(location.toURI()); + contributionMap.put(contribution, relative.toString()); + saveMap(); + + return contributionURL; + } + + public URL store(String contribution, URL sourceURL) throws IOException { + // where the file should be stored in the repository + File location = mapToFile(sourceURL); + File source = FileHelper.toFile(sourceURL); + if (source == null || source.isFile()) { + InputStream is = sourceURL.openStream(); + try { + return store(contribution, sourceURL, is); + } finally { + IOHelper.closeQuietly(is); + } + } + + FileHelper.forceMkdir(location); + FileHelper.copyDirectory(source, location); + + // add contribution to repositoryContent + URI relative = rootFile.toURI().relativize(location.toURI()); + contributionMap.put(contribution, relative.toString()); + saveMap(); + + return location.toURL(); + } + + public URL find(String contribution) { + if (contribution == null) { + return null; + } + String location = contributionMap.get(contribution); + if (location == null) { + return null; + } + try { + return new File(rootFile, location).toURL(); + } catch (MalformedURLException e) { + // Should not happen + throw new AssertionError(e); + } + } + + public void remove(String contribution) { + URL contributionURL = this.find(contribution); + if (contributionURL != null) { + // remove + try { + FileHelper.forceDelete(FileHelper.toFile(contributionURL)); + this.contributionMap.remove(contribution); + saveMap(); + } catch (IOException ioe) { + // handle file could not be removed + } + } + } + + public List list() { + return new ArrayList(contributionMap.keySet()); + } + + public void init() { + File domainFile = new File(rootFile, "sca-domain.xml"); + if (!domainFile.isFile()) { + return; + } + FileInputStream is; + try { + is = new FileInputStream(domainFile); + } catch (FileNotFoundException e) { + return; + } + try { + XMLStreamReader reader = factory.createXMLStreamReader(new InputStreamReader(is, "UTF-8")); + while (reader.hasNext()) { + switch (reader.getEventType()) { + case XMLStreamConstants.START_ELEMENT: + String name = reader.getName().getLocalPart(); + if ("domain".equals(name)) { + String uri = reader.getAttributeValue(null, "uri"); + if (uri != null) { + domain = URI.create(uri); + } + } + if ("contribution".equals(name)) { + String uri = reader.getAttributeValue(null, "uri"); + String location = reader.getAttributeValue(null, "location"); + contributionMap.put(uri, location); + } + break; + default: + break; + } + reader.next(); + } + } catch (Exception e) { + // Ignore + } finally { + IOHelper.closeQuietly(is); + } + } + + private void saveMap() { + File domainFile = new File(rootFile, DOMAIN_INDEX_FILENAME); + FileOutputStream os = null; + try { + os = new FileOutputStream(domainFile); + PrintWriter writer = new PrintWriter(new OutputStreamWriter(os, "UTF-8")); + writer.println(""); + writer.println(""); + for (Map.Entry e : contributionMap.entrySet()) { + writer.println(" "); + } + writer.println(""); + writer.flush(); + } catch (IOException e) { + throw new IllegalArgumentException(e); + } finally { + IOHelper.closeQuietly(os); + } + } + + public void destroy() { + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/ContributionServiceImpl.java b/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/ContributionServiceImpl.java new file mode 100644 index 0000000000..73bf678e04 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/ContributionServiceImpl.java @@ -0,0 +1,340 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.contribution.service.impl; + +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URL; +import java.net.URLClassLoader; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.contribution.Contribution; +import org.apache.tuscany.sca.contribution.ContributionFactory; +import org.apache.tuscany.sca.contribution.DeployedArtifact; +import org.apache.tuscany.sca.contribution.processor.PackageProcessor; +import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.service.ContributionException; +import org.apache.tuscany.sca.contribution.service.ContributionMetadataLoaderException; +import org.apache.tuscany.sca.contribution.service.ContributionRepository; +import org.apache.tuscany.sca.contribution.service.ContributionService; +import org.apache.tuscany.sca.contribution.service.util.IOHelper; + +/** + * Service interface that manages artifacts contributed to a Tuscany runtime. + * + * @version $Rev$ $Date$ + */ +public class ContributionServiceImpl implements ContributionService { + + /** + * Repository where contributions are stored. Usually set by injection. + */ + private ContributionRepository contributionRepository; + + /** + * Registry of available package processors. + */ + private PackageProcessor packageProcessor; + + /** + * Registry of available artifact processors + */ + + private URLArtifactProcessor artifactProcessor; + + /** + * xml factory used to create reader instance to load contribution metadata + */ + private XMLInputFactory xmlFactory; + + /** + * contribution metadata loader + */ + private ContributionMetadataLoaderImpl contributionLoader; + + /** + * Contribution registry This is a registry of processed Contributions indexed by URI + */ + private Map contributionRegistry = new ConcurrentHashMap(); + + /** + * Contribution model facotry + */ + private ContributionFactory contributionFactory; + + + public ContributionServiceImpl(ContributionRepository repository, + PackageProcessor packageProcessor, + URLArtifactProcessor artifactProcessor, + AssemblyFactory assemblyFactory, + ContributionFactory contributionFactory, + XMLInputFactory xmlFactory) { + super(); + this.contributionRepository = repository; + this.packageProcessor = packageProcessor; + this.artifactProcessor = artifactProcessor; + this.xmlFactory = xmlFactory; + + this.contributionFactory = contributionFactory; + this.contributionLoader = new ContributionMetadataLoaderImpl(assemblyFactory, contributionFactory); + } + + public Contribution contribute(String contributionURI, URL sourceURL, ModelResolver modelResolver, boolean storeInRepository) throws ContributionException, + IOException { + if (contributionURI == null) { + throw new IllegalArgumentException("URI for the contribution is null"); + } + if (sourceURL == null) { + throw new IllegalArgumentException("Source URL for the contribution is null"); + } + + return addContribution(contributionURI, sourceURL, null, modelResolver, storeInRepository); + } + + public Contribution contribute(String contributionURI, URL sourceURL, InputStream input, ModelResolver modelResolver) + throws ContributionException, IOException { + + return addContribution(contributionURI, sourceURL, input, modelResolver, true); + } + + private Contribution initializeContributionMetadata(URL sourceURL, ModelResolver modelResolver) throws ContributionException { + Contribution contributionMetadata = null; + URL contributionMetadataURL; + URL generatedContributionMetadataURL; + InputStream metadataStream = null; + + URL[] clUrls = {sourceURL}; + URLClassLoader cl = new URLClassLoader(clUrls, null); + + contributionMetadataURL = cl.getResource(Contribution.SCA_CONTRIBUTION_META); + generatedContributionMetadataURL = cl.getResource(Contribution.SCA_CONTRIBUTION_GENERATED_META); + + try { + contributionMetadata = this.contributionFactory.createContribution(); + contributionMetadata.setModelResolver(modelResolver); + if (contributionMetadataURL != null || generatedContributionMetadataURL != null) { + URL metadataURL = contributionMetadataURL != null ? contributionMetadataURL + : generatedContributionMetadataURL; + + try { + metadataStream = metadataURL.openStream(); + XMLStreamReader xmlReader = this.xmlFactory.createXMLStreamReader(metadataStream); + this.contributionLoader.load(contributionMetadata, xmlReader); + + } catch (IOException ioe) { + throw new InvalidContributionMetadataException(ioe.getMessage(), metadataURL.toExternalForm(), ioe); + } catch (XMLStreamException xmle) { + throw new InvalidContributionMetadataException(xmle.getMessage(), metadataURL.toExternalForm(), + xmle); + } catch (ContributionMetadataLoaderException le) { + throw new InvalidContributionMetadataException(le.getMessage(), metadataURL.toExternalForm(), le); + } + } + } finally { + IOHelper.closeQuietly(metadataStream); + metadataStream = null; + } + + if (contributionMetadata == null) { + contributionMetadata = this.contributionFactory.createContribution(); + } + + return contributionMetadata; + + } + + public Contribution getContribution(String id) { + return this.contributionRegistry.get(id); + } + + public void remove(String contribution) throws ContributionException { + this.contributionRegistry.remove(contribution); + } + + public void addDeploymentComposite(Contribution contribution, Composite composite) throws ContributionException { + DeployedArtifact artifact = this.contributionFactory.createDeployedArtifact(); + artifact.setURI(composite.getURI()); + artifact.setModel(composite); + + contribution.getArtifacts().add(artifact); + + contribution.getDeployables().add(composite); + } + + /** + * Utility/Helper methods for contribution service + */ + + /** + * Note: + * + * @param contributionURI ContributionID + * @param sourceURL contribution location + * @param contributionStream contribution content + * @param storeInRepository flag if we store the contribution into the + * repository or not + * @return the contribution model representing the contribution + * @throws IOException + * @throws DeploymentException + */ + private Contribution addContribution(String contributionURI, + URL sourceURL, + InputStream contributionStream, + ModelResolver modelResolver, + boolean storeInRepository) throws IOException, ContributionException { + + if (contributionStream == null && sourceURL == null) { + throw new IllegalArgumentException("The content of the contribution is null"); + } + + // store the contribution in the contribution repository + URL locationURL = sourceURL; + if (contributionRepository != null && storeInRepository) { + if (contributionStream == null) { + locationURL = contributionRepository.store(contributionURI, sourceURL); + } else { + locationURL = contributionRepository.store(contributionURI, sourceURL, contributionStream); + } + } + + Contribution contribution = initializeContributionMetadata(locationURL, modelResolver); + contribution.setURI(contributionURI.toString()); + contribution.setLocation(locationURL.toString()); + + List contributionArtifacts = null; + + //NOTE: if a contribution is stored on the repository + //the stream would be consumed at this point + if (storeInRepository || contributionStream == null) { + contributionStream = sourceURL.openStream(); + try { + // process the contribution + contributionArtifacts = this.packageProcessor.getArtifacts(locationURL, contributionStream); + } finally { + IOHelper.closeQuietly(contributionStream); + contributionStream = null; + } + } else { + // process the contribution + contributionArtifacts = this.packageProcessor.getArtifacts(locationURL, contributionStream); + } + + // Read all artifacts in the contribution + processReadPhase(contribution, contributionArtifacts); + + // Resolve them + processResolvePhase(contribution); + + // Add all composites under META-INF/sca-deployables to the + // list of deployables + String prefix = Contribution.SCA_CONTRIBUTION_DEPLOYABLES; + for (DeployedArtifact artifact : contribution.getArtifacts()) { + if (artifact.getModel() instanceof Composite) { + if (artifact.getURI().startsWith(prefix)) { + Composite composite = (Composite)artifact.getModel(); + if (!contribution.getDeployables().contains(composite)) { + contribution.getDeployables().add(composite); + } + } + } + } + + // store the contribution on the registry + this.contributionRegistry.put(contribution.getURI(), contribution); + + return contribution; + } + + /** + * This utility method process each artifact and delegates to proper + * artifactProcessor to read the model and generate the in-memory representation + * + * @param contribution + * @param artifacts + * @throws ContributionException + * @throws MalformedURLException + */ + private void processReadPhase(Contribution contribution, List artifacts) throws ContributionException, + MalformedURLException { + + ModelResolver modelResolver = contribution.getModelResolver(); + URL contributionURL = new URL(contribution.getLocation()); + for (URI a : artifacts) { + URL artifactURL = packageProcessor.getArtifactURL(new URL(contribution.getLocation()), a); + + // Add the deployed artifact model to the resolver + DeployedArtifact artifact = this.contributionFactory.createDeployedArtifact(); + artifact.setURI(a.toString()); + artifact.setLocation(artifactURL.toString()); + contribution.getArtifacts().add(artifact); + modelResolver.addModel(artifact); + + // Let the artifact processor read the artifact into a model + Object model = this.artifactProcessor.read(contributionURL, a, artifactURL); + if (model != null) { + artifact.setModel(model); + + // Add the loaded model to the model resolver + modelResolver.addModel(model); + } + + } + } + + /** + * This utility method process each artifact and delegates to proper + * artifactProcessor to resolve the model references + * + * @param contribution + * @throws ContributionException + */ + @SuppressWarnings("unchecked") + private void processResolvePhase(Contribution contribution) throws ContributionException { + // for each artifact that was processed on the contribution + for (DeployedArtifact artifact : contribution.getArtifacts()) { + // resolve the model object + if (artifact.getModel() != null) { + this.artifactProcessor.resolve(artifact.getModel(), contribution.getModelResolver()); + } + } + + //resolve deployables from contribution metadata + List resolvedDeployables = new ArrayList(); + for (Composite deployableComposite : contribution.getDeployables()) { + Composite resolvedDeployable = contribution.getModelResolver().resolveModel(Composite.class, deployableComposite); + resolvedDeployables.add(resolvedDeployable); + } + + contribution.getDeployables().clear(); + contribution.getDeployables().addAll(resolvedDeployables); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/InvalidContributionMetadataException.java b/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/InvalidContributionMetadataException.java new file mode 100644 index 0000000000..a7e0e2f2f5 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/InvalidContributionMetadataException.java @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.contribution.service.impl; + +import org.apache.tuscany.sca.contribution.service.ContributionException; + +/** + * Exception that indicates that the supplied XML Document invalid. + * + * @version $Rev: 511466 $ $Date: 2007-02-25 00:45:22 -0800 (Sun, 25 Feb 2007) $ + */ +public class InvalidContributionMetadataException extends ContributionException { + + /** + * + */ + private static final long serialVersionUID = -3184477070625689942L; + + protected InvalidContributionMetadataException() { + } + + protected InvalidContributionMetadataException(String message) { + super(message); + } + + protected InvalidContributionMetadataException(String message, String identifier) { + super(message, identifier); + } + + protected InvalidContributionMetadataException(String message, Throwable cause) { + super(message, cause); + } + + protected InvalidContributionMetadataException(String message, String identifier, Throwable cause) { + super(message, identifier, cause); + } + + protected InvalidContributionMetadataException(Throwable cause) { + super(cause); + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/InvalidContributionURIException.java b/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/InvalidContributionURIException.java new file mode 100644 index 0000000000..e3109e795b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/InvalidContributionURIException.java @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.contribution.service.impl; + +import org.apache.tuscany.sca.contribution.service.ContributionException; + +/** + * Exception that indicates that the supplied contribution URI is invalid or inexistent. + * + * @version $Rev: 511466 $ $Date: 2007-02-25 00:45:22 -0800 (Sun, 25 Feb 2007) $ + */ +public class InvalidContributionURIException extends ContributionException { + + /** + * + */ + private static final long serialVersionUID = -3184477070625689942L; + + protected InvalidContributionURIException() { + } + + protected InvalidContributionURIException(String message) { + super(message); + } + + protected InvalidContributionURIException(String message, String identifier) { + super(message, identifier); + } + + protected InvalidContributionURIException(String message, Throwable cause) { + super(message, cause); + } + + protected InvalidContributionURIException(String message, String identifier, Throwable cause) { + super(message, identifier, cause); + } + + protected InvalidContributionURIException(Throwable cause) { + super(cause); + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/InvalidValueException.java b/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/InvalidValueException.java new file mode 100644 index 0000000000..ce0fb59476 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/InvalidValueException.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.contribution.service.impl; + +import org.apache.tuscany.sca.contribution.service.ContributionMetadataLoaderException; + +/** + * Denotate invalid value found during parsing of the contribution metadata sidefile + * + * @version $Rev$ $Date$ + */ +public class InvalidValueException extends ContributionMetadataLoaderException { + /** + * + */ + private static final long serialVersionUID = -1447696740893397938L; + + public InvalidValueException(String message) { + super(message); + } + + public InvalidValueException(String message, Throwable cause) { + super(message, cause); + } + + public InvalidValueException(String message, String identifier, Throwable cause) { + super(message, identifier, cause); + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/PackageTypeDescriberImpl.java b/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/PackageTypeDescriberImpl.java new file mode 100644 index 0000000000..165c9d0616 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/PackageTypeDescriberImpl.java @@ -0,0 +1,98 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.contribution.service.impl; + +import java.io.IOException; +import java.net.URL; +import java.net.URLConnection; +import java.util.HashMap; +import java.util.Map; + +import org.apache.tuscany.sca.contribution.ContentType; +import org.apache.tuscany.sca.contribution.service.TypeDescriber; +import org.apache.tuscany.sca.contribution.service.util.FileHelper; + +/** + * Implementation of the content describer for contribution packages + * + * @version $Rev$ $Date$ + */ +public class PackageTypeDescriberImpl implements TypeDescriber { + private final Map contentTypeRegistry = new HashMap(); + + public PackageTypeDescriberImpl() { + super(); + init(); + } + + /** + * Initialize contentType registry with know types based on known file extensions + */ + private void init() { + contentTypeRegistry.put("JAR", ContentType.JAR); + } + + protected String resolveContentyTypeByExtension(URL resourceURL) { + String artifactExtension = FileHelper.getExtension(resourceURL.getPath()); + if (artifactExtension == null) { + return null; + } + return contentTypeRegistry.get(artifactExtension.toUpperCase()); + } + + /** + * Build contentType for a specific resource. We first check if the file is + * a supported one (looking into our registry based on resource extension) + * If not found, we try to check file contentType Or we return + * defaultContentType provided + * + * @param resourceURL The artifact url + * @param defaultContentType The default content type if we can't find the correc one + * @return The content type + */ + public String getType(URL resourceURL, String defaultContentType) { + URLConnection connection = null; + String contentType = defaultContentType; + + if (resourceURL.getProtocol().equals("file") && FileHelper.toFile(resourceURL).isDirectory()) { + // Special case : contribution is a folder + contentType = ContentType.FOLDER; + } else { + contentType = resolveContentyTypeByExtension(resourceURL); + if (contentType == null) { + try { + connection = resourceURL.openConnection(); + contentType = connection.getContentType(); + + if (contentType == null || contentType.equals("content/unknown")) { + // here we couldn't figure out from our registry or from URL and it's not a special file + // return defaultContentType if provided + contentType = defaultContentType; + } + } catch (IOException io) { + // could not access artifact, just ignore and we will return + // null contentType + } + } + } + return contentType == null ? defaultContentType : contentType; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/util/FileHelper.java b/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/util/FileHelper.java new file mode 100644 index 0000000000..bc63dca4a8 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/util/FileHelper.java @@ -0,0 +1,704 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.contribution.service.util; + +import java.io.File; +import java.io.FileFilter; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.net.URL; +import java.util.regex.Pattern; + +public class FileHelper { + /** + * The extension separator character. + */ + private static final char EXTENSION_SEPARATOR = '.'; + + /** + * The Unix separator character. + */ + private static final char UNIX_SEPARATOR = '/'; + + /** + * The Windows separator character. + */ + private static final char WINDOWS_SEPARATOR = '\\'; + + protected FileHelper() { + } + + /** + * Returns the index of the last directory separator character. + *

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

+ * This method buffers the input internally, so there is no need to use a + * BufferedInputStream. + * + * @param input the InputStream to read from + * @param output the OutputStream to write to + * @return the number of bytes copied + * @throws NullPointerException if the input or output is null + * @throws IOException if an I/O error occurs + * @since Commons IO 1.1 + */ + public static int copy(InputStream input, OutputStream output) throws IOException { + byte[] buffer = new byte[DEFAULT_BUFFER_SIZE]; + int count = 0; + int n = 0; + while (-1 != (n = input.read(buffer))) { // NOPMD + output.write(buffer, 0, n); + count += n; + } + return count; + } + + public static InputStream getInputStream(URL url) throws IOException { + return new SafeURLInputStream(url); + } + + /** + * This class is a workaround for URL stream issue as illustrated below. + * InputStream is=url.getInputStream(); is.close(); // This line doesn't close + * the JAR file if the URL is a jar entry like "jar:file:/a.jar!/my.composite" We + * also need to turn off the JarFile cache. + * + * @see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4950148 + * + * @version $Rev$ $Date$ + */ + public static class SafeURLInputStream extends InputStream { + private JarFile jarFile; + private InputStream is; + + public SafeURLInputStream(URL url) throws IOException { + String protocol = url.getProtocol(); + if (protocol != null && (protocol.equals("jar"))) { + JarURLConnection connection = (JarURLConnection)url.openConnection(); + // We cannot use cache + connection.setUseCaches(false); + try { + is = connection.getInputStream(); + } catch (IOException e) { + throw e; + } + jarFile = connection.getJarFile(); + } else { + is = url.openStream(); + } + } + + public SafeURLInputStream(JarURLConnection connection) throws IOException { + // We cannot use cache + connection.setUseCaches(false); + is = connection.getInputStream(); + jarFile = connection.getJarFile(); + } + + public int available() throws IOException { + return is.available(); + } + + public void close() throws IOException { + is.close(); + // We need to close the JAR file + if (jarFile != null) { + jarFile.close(); + } + } + + public synchronized void mark(int readlimit) { + is.mark(readlimit); + } + + public boolean markSupported() { + return is.markSupported(); + } + + public int read() throws IOException { + return is.read(); + } + + public int read(byte[] b, int off, int len) throws IOException { + return is.read(b, off, len); + } + + public int read(byte[] b) throws IOException { + return is.read(b); + } + + public synchronized void reset() throws IOException { + is.reset(); + } + + public long skip(long n) throws IOException { + return is.skip(n); + } + } +} \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/processor/FolderContributionPackageProcessorTestCase.java b/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/processor/FolderContributionPackageProcessorTestCase.java new file mode 100644 index 0000000000..6a2f2ac3cc --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/processor/FolderContributionPackageProcessorTestCase.java @@ -0,0 +1,45 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.contribution.processor; + +import java.io.File; +import java.net.URI; +import java.util.List; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.contribution.processor.impl.FolderContributionProcessor; + +public class FolderContributionPackageProcessorTestCase extends TestCase { + private static final String FOLDER_CONTRIBUTION = "."; + + private File contributionRoot; + + protected void setUp() throws Exception { + super.setUp(); + this.contributionRoot = new File(FOLDER_CONTRIBUTION); + } + + public final void testProcessPackageArtifacts() throws Exception { + FolderContributionProcessor folderProcessor = new FolderContributionProcessor(); + + List artifacts = folderProcessor.getArtifacts(contributionRoot.toURL(), null); + assertNotNull(artifacts); + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/processor/JarContributionPackageProcessorTestCase.java b/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/processor/JarContributionPackageProcessorTestCase.java new file mode 100644 index 0000000000..8765423dbe --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/processor/JarContributionPackageProcessorTestCase.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.contribution.processor; + +import java.io.InputStream; +import java.net.URI; +import java.net.URL; +import java.util.List; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.contribution.processor.impl.JarContributionProcessor; +import org.apache.tuscany.sca.contribution.service.util.IOHelper; + +public class JarContributionPackageProcessorTestCase extends TestCase { + private static final String JAR_CONTRIBUTION = "/repository/sample-calculator.jar"; + + protected void setUp() throws Exception { + super.setUp(); + } + + public final void testProcessPackageArtifacts() throws Exception { + JarContributionProcessor jarProcessor = new JarContributionProcessor(); + + URL jarURL = getClass().getResource(JAR_CONTRIBUTION); + InputStream jarStream = jarURL.openStream(); + List artifacts = null; + try { + artifacts = jarProcessor.getArtifacts(jarURL, jarStream); + } finally { + IOHelper.closeQuietly(jarStream); + } + + assertNotNull(artifacts); + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/resolver/ArtifactResolverTestCase.java b/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/resolver/ArtifactResolverTestCase.java new file mode 100644 index 0000000000..0a1075b832 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/resolver/ArtifactResolverTestCase.java @@ -0,0 +1,102 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.contribution.resolver; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.contribution.ContributionFactory; +import org.apache.tuscany.sca.contribution.DeployedArtifact; +import org.apache.tuscany.sca.contribution.impl.ContributionFactoryImpl; +import org.apache.tuscany.sca.contribution.resolver.impl.ModelResolverImpl; + +/** + * Test DefaultArtifactResolver. + * + * @version $Rev$ $Date$ + */ +public class ArtifactResolverTestCase extends TestCase { + + private ModelResolver resolver; + private ContributionFactory factory; + + protected void setUp() throws Exception { + resolver = new ModelResolverImpl(getClass().getClassLoader()); + factory = new ContributionFactoryImpl(); + } + + protected void tearDown() throws Exception { + resolver = null; + factory = null; + } + + public void testResolved() { + Model a = new Model("a"); + resolver.addModel(a); + Model x = new Model("a"); + x = resolver.resolveModel(Model.class, x); + assertTrue(x == a); + } + + public void testUnresolved() { + Model x = new Model("a"); + Model y = resolver.resolveModel(Model.class, x); + assertTrue(x == y); + } + + public void testResolveClass() { + ClassReference ref = new ClassReference(getClass().getName()); + ClassReference clazz = resolver.resolveModel(ClassReference.class, ref); + assertTrue(clazz.getJavaClass() == getClass()); + } + + public void testUnresolvedClass() { + ClassReference ref = new ClassReference("NonExistentClass"); + ClassReference clazz = resolver.resolveModel(ClassReference.class, ref); + assertTrue(clazz.isUnresolved()); + assertTrue(clazz.getJavaClass() == null); + } + + public void testResolvedArtifact() { + DeployedArtifact artifact = factory.createDeployedArtifact(); + artifact.setURI("foo/bar"); + resolver.addModel(artifact); + DeployedArtifact x = factory.createDeployedArtifact(); + x.setURI("foo/bar"); + x = resolver.resolveModel(DeployedArtifact.class, x); + assertTrue(x == artifact); + } + + class Model { + private String name; + + Model(String name) { + this.name = name; + } + + public int hashCode() { + return name.hashCode(); + } + + public boolean equals(Object obj) { + return name.equals(((Model)obj).name); + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/services/ContentTypeDescriberImplTestCase.java b/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/services/ContentTypeDescriberImplTestCase.java new file mode 100644 index 0000000000..4f924225ae --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/services/ContentTypeDescriberImplTestCase.java @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.contribution.services; + +import java.net.URL; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.contribution.ContentType; +import org.apache.tuscany.sca.contribution.service.impl.ArtifactTypeDescriberImpl; + +public class ContentTypeDescriberImplTestCase extends TestCase { + private ArtifactTypeDescriberImpl contentTypeDescriber; + + public void testResolveContentType() throws Exception { + URL artifactURL = getClass().getResource("/test.composite"); + assertEquals(ContentType.COMPOSITE, contentTypeDescriber.getType(artifactURL, null)); + } + + + public void testResolveUnknownContentType() throws Exception { + URL artifactURL = getClass().getResource("/test.ext"); + assertNull(contentTypeDescriber.getType(artifactURL, null)); + } + + public void testDefaultContentType() throws Exception { + URL artifactURL = getClass().getResource("/test.ext"); + assertEquals("application/vnd.tuscany.ext", + contentTypeDescriber.getType(artifactURL, "application/vnd.tuscany.ext")); + } + + protected void setUp() throws Exception { + super.setUp(); + contentTypeDescriber = new ArtifactTypeDescriberImpl(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/services/ContributionMetadataLoaderTestCase.java b/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/services/ContributionMetadataLoaderTestCase.java new file mode 100644 index 0000000000..ac1d968f39 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/services/ContributionMetadataLoaderTestCase.java @@ -0,0 +1,96 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.contribution.services; + +import java.io.StringReader; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamReader; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory; +import org.apache.tuscany.sca.contribution.Contribution; +import org.apache.tuscany.sca.contribution.ContributionFactory; +import org.apache.tuscany.sca.contribution.impl.ContributionFactoryImpl; +import org.apache.tuscany.sca.contribution.resolver.impl.ModelResolverImpl; +import org.apache.tuscany.sca.contribution.service.impl.ContributionMetadataLoaderImpl; +import org.apache.tuscany.sca.contribution.service.impl.InvalidValueException; + +/** + * @version $Rev$ $Date$ + */ +public class ContributionMetadataLoaderTestCase extends TestCase { + + private static final String VALID_XML = + "" + + "" + + "" + + "" + + "" + + "" + + ""; + + private static final String INVALID_XML = + "" + + "" + + "" + + "" + + "" + + "" + + ""; + + private XMLInputFactory xmlFactory; + + protected void setUp() throws Exception { + super.setUp(); + xmlFactory = XMLInputFactory.newInstance(); + } + + public void testLoad() throws Exception { + XMLStreamReader reader = xmlFactory.createXMLStreamReader(new StringReader(VALID_XML)); + + ContributionFactory factory = new ContributionFactoryImpl(); + ContributionMetadataLoaderImpl loader = + new ContributionMetadataLoaderImpl(new DefaultAssemblyFactory(), factory); + Contribution contribution = factory.createContribution(); + contribution.setModelResolver(new ModelResolverImpl(getClass().getClassLoader())); + loader.load(contribution, reader); + assertNotNull(contribution); + assertEquals(1, contribution.getImports().size()); + assertEquals(1, contribution.getExports().size()); + assertEquals(2, contribution.getDeployables().size()); + } + + public void testLoadInvalid() throws Exception { + XMLStreamReader reader = xmlFactory.createXMLStreamReader(new StringReader(INVALID_XML)); + ContributionFactory factory = new ContributionFactoryImpl(); + ContributionMetadataLoaderImpl loader = + new ContributionMetadataLoaderImpl(new DefaultAssemblyFactory(), factory); + Contribution contribution = factory.createContribution(); + contribution.setModelResolver(new ModelResolverImpl(getClass().getClassLoader())); + try { + loader.load(contribution, reader); + fail("InvalidException should have been thrown"); + } catch (InvalidValueException e) { + assertTrue(true); + } + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/services/ContributionRepositoryTestCase.java b/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/services/ContributionRepositoryTestCase.java new file mode 100644 index 0000000000..98f69b9aa1 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/services/ContributionRepositoryTestCase.java @@ -0,0 +1,79 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.contribution.services; + +import java.io.File; +import java.io.InputStream; +import java.net.URL; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.contribution.service.impl.ContributionRepositoryImpl; +import org.apache.tuscany.sca.contribution.service.util.FileHelper; + +public class ContributionRepositoryTestCase extends TestCase { + private ContributionRepositoryImpl repository; + + protected void setUp() throws Exception { + super.setUp(); + // create repository (this should re-create the root directory) + this.repository = new ContributionRepositoryImpl("target/repository/"); + repository.init(); + } + + public void testStore() throws Exception { + String resourceLocation = "/repository/sample-calculator.jar"; + String contribution = "sample-calculator.jar"; + URL contributionLocation = getClass().getResource(resourceLocation); + InputStream contributionStream = getClass().getResourceAsStream(resourceLocation); + repository.store(contribution, contributionLocation, contributionStream); + + URL contributionURL = repository.find(contribution); + assertNotNull(contributionURL); + } + + public void testRemove() throws Exception { + String resourceLocation = "/repository/sample-calculator.jar"; + String contribution = "sample-calculator.jar"; + URL contributionLocation = getClass().getResource(resourceLocation); + InputStream contributionStream = getClass().getResourceAsStream(resourceLocation); + repository.store(contribution, contributionLocation, contributionStream); + + repository.remove(contribution); + URL contributionURL = repository.find(contribution); + assertNull(contributionURL); + } + + public void testList() throws Exception { + String resourceLocation = "/repository/sample-calculator.jar"; + String contribution = "sample-calculator.jar"; + URL contributionLocation = getClass().getResource(resourceLocation); + InputStream contributionStream = getClass().getResourceAsStream(resourceLocation); + repository.store(contribution, contributionLocation, contributionStream); + + assertEquals(1, repository.list().size()); + } + + @Override + protected void tearDown() throws Exception { + super.tearDown(); + FileHelper.deleteDirectory(new File("target/repository")); + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/services/PackageTypeDescriberImplTestCase.java b/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/services/PackageTypeDescriberImplTestCase.java new file mode 100644 index 0000000000..7ee873b9a3 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/services/PackageTypeDescriberImplTestCase.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.contribution.services; + +import java.net.URL; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.contribution.ContentType; +import org.apache.tuscany.sca.contribution.service.impl.PackageTypeDescriberImpl; + +public class PackageTypeDescriberImplTestCase extends TestCase { + private PackageTypeDescriberImpl packageTypeDescriber; + + public void testResolvePackageType() throws Exception { + URL artifactURL = getClass().getResource("/deployables/sample-calculator.jar"); + assertEquals(ContentType.JAR, this.packageTypeDescriber.getType(artifactURL, null)); + } + + public void testResolveUnknownPackageType() throws Exception { + URL artifactURL = getClass().getResource("/test.ext"); + assertNull(this.packageTypeDescriber.getType(artifactURL, null)); + } + + public void testDefaultPackageType() throws Exception { + URL artifactURL = getClass().getResource("/test.ext"); + assertEquals("application/vnd.tuscany.ext", + packageTypeDescriber.getType(artifactURL, "application/vnd.tuscany.ext")); + } + + protected void setUp() throws Exception { + super.setUp(); + packageTypeDescriber = new PackageTypeDescriberImpl(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/test/resources/deployables/sample-calculator.jar b/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/test/resources/deployables/sample-calculator.jar new file mode 100644 index 0000000000..0ca3a1b781 Binary files /dev/null and b/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/test/resources/deployables/sample-calculator.jar differ diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/test/resources/repository/sample-calculator.jar b/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/test/resources/repository/sample-calculator.jar new file mode 100644 index 0000000000..9c46c679d2 Binary files /dev/null and b/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/test/resources/repository/sample-calculator.jar differ diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/test/resources/test.composite b/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/test/resources/test.composite new file mode 100644 index 0000000000..1e09549194 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/test/resources/test.composite @@ -0,0 +1,22 @@ + + + + This file just needs to exist + \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/test/resources/test.ext b/sca-java-1.x/branches/sca-java-0.91/modules/contribution-impl/src/test/resources/test.ext new file mode 100644 index 0000000000..e69de29bb2 diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/contribution/.checkstyle b/sca-java-1.x/branches/sca-java-0.91/modules/contribution/.checkstyle new file mode 100644 index 0000000000..e3c216986d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/contribution/.checkstyle @@ -0,0 +1,24 @@ + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/contribution/.pmd b/sca-java-1.x/branches/sca-java-0.91/modules/contribution/.pmd new file mode 100644 index 0000000000..84af2f4d5d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/contribution/.pmd @@ -0,0 +1,20 @@ + + +true diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/contribution/.ruleset b/sca-java-1.x/branches/sca-java-0.91/modules/contribution/.ruleset new file mode 100644 index 0000000000..ac8671859d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/contribution/.ruleset @@ -0,0 +1,190 @@ + + + + PMD Plugin preferences rule set + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/contribution/DISCLAIMER b/sca-java-1.x/branches/sca-java-0.91/modules/contribution/DISCLAIMER new file mode 100644 index 0000000000..d68a410903 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/contribution/DISCLAIMER @@ -0,0 +1,8 @@ +Apache Tuscany is an effort undergoing incubation at The Apache Software +Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is +required of all newly accepted projects until a further review indicates that +the infrastructure, communications, and decision making process have stabilized +in a manner consistent with other successful ASF projects. While incubation +status is not necessarily a reflection of the completeness or stability of the +code, it does indicate that the project has yet to be fully endorsed by the ASF. + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/contribution/LICENSE b/sca-java-1.x/branches/sca-java-0.91/modules/contribution/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/contribution/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/contribution/NOTICE b/sca-java-1.x/branches/sca-java-0.91/modules/contribution/NOTICE new file mode 100644 index 0000000000..94481d6cfa --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/contribution/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2007 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/contribution/pom.xml b/sca-java-1.x/branches/sca-java-0.91/modules/contribution/pom.xml new file mode 100644 index 0000000000..866e3d4c3a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/contribution/pom.xml @@ -0,0 +1,44 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 0.91-incubating-SNAPSHOT + ../pom.xml + + tuscany-contribution + Apache Tuscany SCA Contribution Service + + + + org.apache.tuscany.sca + tuscany-assembly + 0.91-incubating-SNAPSHOT + + + + stax + stax-api + 1.0.1 + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/Artifact.java b/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/Artifact.java new file mode 100644 index 0000000000..c57054cfd0 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/Artifact.java @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.contribution; + + +/** + * Base Artifact interface to accomodate common properties between Contribution and Deployed Artifact + * + * @version $Rev$ $Date$ + */ +public interface Artifact { + /** + * Get the URI that unique identifies the artifact + * + * @return The artifact uri + */ + String getURI(); + + /** + * Set the URI that unique identifies the artifact + * + * @param uri The artifact uri + */ + void setURI(String uri); + + /** + * Get the URL location for the artifact + * + * @return The artifact location + */ + String getLocation(); + + /** + * Set the URL location for the artifact + * + * @param location The artifact location + */ + void setLocation(String location); + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/ContentType.java b/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/ContentType.java new file mode 100644 index 0000000000..2e9eb203ad --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/ContentType.java @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.contribution; + +/** + * Identifies internal content types for contribution package and artifacts + * + * @version $Rev$ $Date$ + */ +public interface ContentType { + /** + * Java compressed contribution package + */ + String JAR = "application/x-compressed"; + /** + * Filesystem folder contribution package + */ + String FOLDER = "application/vnd.tuscany.folder"; + /** + * Contribution metadata file + */ + String CONTRIBUTION_METADATA = "application/vnd.tuscany.contribution.metadata"; + /** + * SCA Composite description file + */ + String COMPOSITE = "application/vnd.tuscany.composite"; + /** + * WSDL file + */ + String WSDL = "application/vnd.tuscany.wsdl"; + /** + * Java source/binary file + */ + String JAVA = "application/java-vm"; + /** + * Unkown contentType + */ + String UNKNOWN = "content/unknown"; +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/Contribution.java b/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/Contribution.java new file mode 100644 index 0000000000..4775fba4e4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/Contribution.java @@ -0,0 +1,91 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.contribution; + +import java.util.List; + +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; + +/** + * The representation of a deployed contribution + * + * @version $Rev$ $Date$ + */ +public interface Contribution extends Artifact { + /** + * Default location of contribution metadata in a contribution package + */ + String SCA_CONTRIBUTION_META = "META-INF/sca-contribution.xml"; + /** + * default location of a generated contribution metadata in a contribution package + */ + String SCA_CONTRIBUTION_GENERATED_META = "META-INF/sca-contribution-generated.xml"; + /** + * Default location of deployables in a contribution + */ + String SCA_CONTRIBUTION_DEPLOYABLES = "META-INF/sca-deployables/"; + + + /** + * Get a list of exports based on the Contribution metadata sidefile + * + * @return The list of exported artifacts from this contribution + */ + List getExports(); + + /** + * Get a list of imports based on the Contribution metadata sidefile + * + * @return The list of imported artifacts on this contribution + */ + List getImports(); + + /** + * Get a list of deployables for the contribution based on the contribution metadata sidefile + * + * @return The list of deployable composites + */ + List getDeployables(); + + /** + * Get a list of artifacts from the contribution + * + * @return The list of deployed artifacts for the contribution + */ + List getArtifacts(); + + /** + * Returns the model resolver for the models representing the artifacts + * visible in the scope of this contribution. + * + * @return The model resolver + */ + ModelResolver getModelResolver(); + + /** + * Sets the model resolver for the models representing the artifacts + * visible in the scope of this contribution. + * + * @param modelResolver The model resolver + */ + void setModelResolver(ModelResolver modelResolver); + +} \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/ContributionExport.java b/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/ContributionExport.java new file mode 100644 index 0000000000..914788a8c7 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/ContributionExport.java @@ -0,0 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.contribution; + +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; + +/** + * The representation of an export for the contribution + * + * @version $Rev$ $Date$ + */ +public interface ContributionExport { + + /** + * Get Namespace that identifies the export + * + * @return The exported namespace + */ + String getNamespace(); + + /** + * Set Namespace that identifies the export + * + * @param namespace The exported namespace + */ + void setNamespace(String namespace); + + /** + * Returns the model resolver for the models representing artifacts + * made available by this export. + * + * @return The model resolver + */ + ModelResolver getModelResolver(); + + /** + * Sets the model resolver for the models representing artifacts + * made available by this export. + * + * @param modelResolver + */ + void setModelResolver(ModelResolver modelResolver); + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/ContributionFactory.java b/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/ContributionFactory.java new file mode 100644 index 0000000000..8e1ce6e8ec --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/ContributionFactory.java @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.contribution; + +/** + * Contribution model object factory + * + * @version $Rev$ $Date$ + */ +public interface ContributionFactory { + /** + * Create a contribution model object + * + * @return The new contribution model object + */ + Contribution createContribution(); + + /** + * Create a deployedArtifact model object + * + * @return The new deployedArtifact model object + */ + DeployedArtifact createDeployedArtifact(); + + /** + * Create a contribution import model + * + * @return The new ContributionImport model object + */ + ContributionImport createContributionImport(); + + /** + * Create a contribution import model + * + * @return The new ContributoinExport object + */ + ContributionExport createContributionExport(); +} \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/ContributionImport.java b/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/ContributionImport.java new file mode 100644 index 0000000000..e42d65947b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/ContributionImport.java @@ -0,0 +1,75 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.contribution; + +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; + + +/** + * The representation of an import for the contribution + * + * @version $Rev$ $Date$ + */ +public interface ContributionImport { + + /** + * Get the location used to resolve the definitions for this import + * + * @return The import location + */ + String getLocation(); + + /** + * Set the location used to resolve the definitions for this import + * + * @param location The import location + */ + void setLocation(String location); + + /** + * Get Namespace that identifies the import + * + * @return The namespace + */ + String getNamespace(); + + /** + * Set Namespace that identifies the import + * + * @param namespace The namespace + */ + void setNamespace(String namespace); + + /** + * Returns the model resolver for the models representing artifacts + * made available by this import. + * + * @return The model resolver + */ + ModelResolver getModelResolver(); + + /** + * Sets the model resolver for the models representing artifacts + * made available by this import. + * + * @param modelResolver The model resolver + */ + void setModelResolver(ModelResolver modelResolver); +} \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/DeployedArtifact.java b/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/DeployedArtifact.java new file mode 100644 index 0000000000..4b0fb1cc08 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/DeployedArtifact.java @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.contribution; + +/** + * Representation of a deployed artifact + * + * @version $Rev$ $Date$ + */ +public interface DeployedArtifact extends Artifact { + + /** + * Get the assembly model associated with this artifact + * + * @return The assembly model + */ + Object getModel(); + + /** + * Set the assembly model associated with this artifact + * + * @param modelObject The assembly model + */ + void setModel(Object modelObject); + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ArtifactProcessor.java b/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ArtifactProcessor.java new file mode 100644 index 0000000000..014c187733 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ArtifactProcessor.java @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.contribution.processor; + +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.service.ContributionResolveException; + +/** + * Interface for extensions that can process contributions. + * + * @version $Rev$ $Date$ + */ +public interface ArtifactProcessor { + + /** + * Resolve references from this model to other models. For example references + * from a composite to another one, or references from a composite to a WSDL + * model. + * + * @param model The model to resolve + * @param resolver The resolver to use to resolve referenced models + */ + void resolve(M model, ModelResolver resolver) throws ContributionResolveException; + + /** + * Returns the type of model handled by this artifact processor. + * + * @return The type of model handled by this artifact processor + */ + Class getModelType(); + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ArtifactProcessorExtensionPoint.java b/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ArtifactProcessorExtensionPoint.java new file mode 100644 index 0000000000..029df61f0f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ArtifactProcessorExtensionPoint.java @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.contribution.processor; + +/** + * An extension point for artifact processors. + * + * @version $Rev$ $Date$ + */ +public interface ArtifactProcessorExtensionPoint

{ + + /** + * Add an artifact processor. + * + * @param artifactProcessor The artifact processor to add + */ + void addArtifactProcessor(P artifactProcessor); + + /** + * Remove an artifact processor. + * + * @param artifactProcessor The artifact processor to remove + */ + void removeArtifactProcessor(P artifactProcessor); + + /** + * Returns the processor associated with the given artifact type. + * + * @param artifactType An artifact type + * @return The processor associated with the given artifact type + */ + P getProcessor(Object artifactType); + + /** + * Returns the processor associated with the given model type. + * + * @param modelType A model type + * @return The processor associated with the given model type + */ + P getProcessor(Class modelType); + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ContributionPostProcessor.java b/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ContributionPostProcessor.java new file mode 100644 index 0000000000..5475fe3b06 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ContributionPostProcessor.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.contribution.processor; + +import org.apache.tuscany.sca.contribution.Contribution; + +/** + * A processor invoked after the contribution is loaded + * + * @version $Rev$ $Date$ + */ +public interface ContributionPostProcessor { + + /** + * Visitor pattern to post process the contribution + * + * @param contribution The contribution to be post processed + */ + void visit(Contribution contribution); +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ContributionPostProcessorExtensionPoint.java b/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ContributionPostProcessorExtensionPoint.java new file mode 100644 index 0000000000..4aa866b6f2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ContributionPostProcessorExtensionPoint.java @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.contribution.processor; + +/** + * An extension point for contribution post processor extensions. + * + * @version $Rev$ $Date$ + */ +public interface ContributionPostProcessorExtensionPoint { + + /** + * Add a ContributionPostProcessor + * + * @param processor The post processor + */ + void addPostProcessor(ContributionPostProcessor processor); + + /** + * Remove a ContributionPostProcessor + * + * @param processor The post processor + */ + void removePostProcessor(ContributionPostProcessor processor); +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultArtifactProcessorExtensionPoint.java b/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultArtifactProcessorExtensionPoint.java new file mode 100644 index 0000000000..1c2faf9503 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultArtifactProcessorExtensionPoint.java @@ -0,0 +1,66 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.contribution.processor; + +import java.util.HashMap; +import java.util.Map; + +/** + * The default implementation of an artifact processor registry. + * + * @version $Rev$ $Date$ + */ +abstract class DefaultArtifactProcessorExtensionPoint

{ + protected final Map processorsByArtifactType = new HashMap(); + protected final Map, P> processorsByModelType = new HashMap, P>(); + + /** + * Constructs a new loader registry. + */ + public DefaultArtifactProcessorExtensionPoint() { + } + + /** + * Returns the processor associated with the given artifact type. + * + * @param artifactType An artifact type + * @return The processor associated with the given artifact type + */ + public P getProcessor(Object artifactType) { + return processorsByArtifactType.get(artifactType); + } + + /** + * Returns the processor associated with the given model type. + * + * @param modelType A model type + * @return The processor associated with the given model type + */ + public P getProcessor(Class modelType) { + Class[] classes = modelType.getInterfaces(); + for (Class c : classes) { + P processor = processorsByModelType.get(c); + if (processor != null) { + return processor; + } + } + return processorsByModelType.get(modelType); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultPackageProcessorExtensionPoint.java b/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultPackageProcessorExtensionPoint.java new file mode 100644 index 0000000000..15fb1d838f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultPackageProcessorExtensionPoint.java @@ -0,0 +1,51 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.contribution.processor; + +import java.util.HashMap; +import java.util.Map; + +/** + * Default implementation of ContributionProcessorRegistry + * + * @version $Rev$ $Date$ + */ +public class DefaultPackageProcessorExtensionPoint implements PackageProcessorExtensionPoint { + + /** + * Processor registry + */ + private Map registry = new HashMap(); + + public DefaultPackageProcessorExtensionPoint() { + } + + public void addPackageProcessor(PackageProcessor processor) { + registry.put(processor.getPackageType(), processor); + } + + public void removePackageProcessor(PackageProcessor processor) { + registry.remove(processor.getPackageType()); + } + + public PackageProcessor getPackageProcessor(String contentType) { + return registry.get(contentType); + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultStAXArtifactProcessorExtensionPoint.java b/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultStAXArtifactProcessorExtensionPoint.java new file mode 100644 index 0000000000..8b9333666c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultStAXArtifactProcessorExtensionPoint.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.contribution.processor; + +/** + * The default implementation of an extension point for StAX artifact processors. + * + * @version $Rev$ $Date$ + */ +public class DefaultStAXArtifactProcessorExtensionPoint + extends DefaultArtifactProcessorExtensionPoint + implements StAXArtifactProcessorExtensionPoint { + + /** + * Constructs a new extension point. + */ + public DefaultStAXArtifactProcessorExtensionPoint() { + } + + public void addArtifactProcessor(StAXArtifactProcessor artifactProcessor) { + processorsByArtifactType.put((Object)artifactProcessor.getArtifactType(), artifactProcessor); + processorsByModelType.put(artifactProcessor.getModelType(), artifactProcessor); + } + + public void removeArtifactProcessor(StAXArtifactProcessor artifactProcessor) { + processorsByArtifactType.remove((Object)artifactProcessor.getArtifactType()); + processorsByModelType.remove(artifactProcessor.getModelType()); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultURLArtifactProcessorExtensionPoint.java b/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultURLArtifactProcessorExtensionPoint.java new file mode 100644 index 0000000000..47c81fd04d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultURLArtifactProcessorExtensionPoint.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.contribution.processor; + +/** + * The default implementation of a StAX artifact processor registry. + * + * @version $Rev$ $Date$ + */ +public class DefaultURLArtifactProcessorExtensionPoint + extends DefaultArtifactProcessorExtensionPoint + implements URLArtifactProcessorExtensionPoint { + + /** + * Constructs a new extension point. + */ + public DefaultURLArtifactProcessorExtensionPoint() { + } + + public void addArtifactProcessor(URLArtifactProcessor artifactProcessor) { + processorsByArtifactType.put((Object)artifactProcessor.getArtifactType(), artifactProcessor); + processorsByModelType.put(artifactProcessor.getModelType(), artifactProcessor); + } + + public void removeArtifactProcessor(URLArtifactProcessor artifactProcessor) { + processorsByArtifactType.remove((Object)artifactProcessor.getArtifactType()); + processorsByModelType.remove(artifactProcessor.getModelType()); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensiblePackageProcessor.java b/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensiblePackageProcessor.java new file mode 100644 index 0000000000..ac8fd6f272 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensiblePackageProcessor.java @@ -0,0 +1,76 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.contribution.processor; + +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URL; +import java.util.List; + +import org.apache.tuscany.sca.contribution.service.ContributionException; +import org.apache.tuscany.sca.contribution.service.TypeDescriber; +import org.apache.tuscany.sca.contribution.service.UnsupportedContentTypeException; + +/** + * Default implementation of PackageProcessor. + * + * @version $Rev$ $Date$ + */ +public class ExtensiblePackageProcessor implements PackageProcessor { + + private PackageProcessorExtensionPoint processors; + + /** + * Helper method to describe contentType for each artifact + */ + private TypeDescriber packageTypeDescriber; + + public ExtensiblePackageProcessor(PackageProcessorExtensionPoint processors, TypeDescriber packageTypeDescriber) { + this.processors = processors; + this.packageTypeDescriber = packageTypeDescriber; + } + + public List getArtifacts(URL packageSourceURL, InputStream inputStream) + throws ContributionException, IOException { + String contentType = this.packageTypeDescriber.getType(packageSourceURL, null); + if (contentType == null) { + throw new UnsupportedContentTypeException("Unsupported contribution package", packageSourceURL.toString()); + } + + PackageProcessor packageProcessor = this.processors.getPackageProcessor(contentType); + if (packageProcessor == null) { + throw new UnsupportedContentTypeException(contentType, packageSourceURL.getPath()); + } + + return packageProcessor.getArtifacts(packageSourceURL, inputStream); + } + + public URL getArtifactURL(URL packageSourceURL, URI artifact) throws MalformedURLException { + String contentType = this.packageTypeDescriber.getType(packageSourceURL, null); + PackageProcessor packageProcessor = this.processors.getPackageProcessor(contentType); + return packageProcessor.getArtifactURL(packageSourceURL, artifact); + } + + public String getPackageType() { + return null; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleStAXArtifactProcessor.java b/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleStAXArtifactProcessor.java new file mode 100644 index 0000000000..40575960f4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleStAXArtifactProcessor.java @@ -0,0 +1,178 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.contribution.processor; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; + +import javax.xml.namespace.QName; +import javax.xml.stream.Location; +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLOutputFactory; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.contribution.service.ContributionResolveException; +import org.apache.tuscany.sca.contribution.service.ContributionWriteException; +import org.apache.tuscany.sca.contribution.service.UnrecognizedElementException; + +/** + * The default implementation of a StAX artifact processor registry. + * + * @version $Rev$ $Date$ + */ +public class ExtensibleStAXArtifactProcessor + implements StAXArtifactProcessor { + + private XMLInputFactory inputFactory; + private XMLOutputFactory outputFactory; + private StAXArtifactProcessorExtensionPoint processors; + + /** + * Constructs a new loader registry. + * @param inputFactory + * @param outputFactory + */ + public ExtensibleStAXArtifactProcessor(StAXArtifactProcessorExtensionPoint processors, XMLInputFactory inputFactory, XMLOutputFactory outputFactory) { + super(); + this.processors = processors; + this.inputFactory = inputFactory; + this.outputFactory = outputFactory; + this.outputFactory.setProperty("javax.xml.stream.isRepairingNamespaces", Boolean.TRUE); + } + + public Object read(XMLStreamReader source) throws ContributionReadException { + + // Delegate to the processor associated with the element qname + QName name = source.getName(); + StAXArtifactProcessor processor = (StAXArtifactProcessor)processors.getProcessor(name); + if (processor == null) { + return null; + } + try { + return processor.read(source); + } catch (XMLStreamException e) { + throw new ContributionReadException(e); + } + } + + @SuppressWarnings("unchecked") + public void write(Object model, XMLStreamWriter outputSource) throws ContributionWriteException { + + // Delegate to the processor associated with the model type + if (model != null) { + StAXArtifactProcessor processor = processors.getProcessor(model.getClass()); + if (processor != null) { + try { + processor.write(model, outputSource); + } catch (XMLStreamException e) { + throw new ContributionWriteException(e); + } + } + } + } + + @SuppressWarnings("unchecked") + public void resolve(Object model, ModelResolver resolver) throws ContributionResolveException { + + // Delegate to the processor associated with the model type + if (model != null) { + StAXArtifactProcessor processor = processors.getProcessor(model.getClass()); + if (processor != null) { + processor.resolve(model, resolver); + } + } + } + + /** + * Read a model from an input stream. + * @param is The artifact inputstream + * @param type Model type + * @return The model + * @throws ContributionReadException + */ + public MO read(InputStream is, Class type) throws ContributionReadException { + try { + XMLStreamReader reader; + try { + reader = inputFactory.createXMLStreamReader(is); + try { + reader.nextTag(); + QName name = reader.getName(); + Object mo = read(reader); + if (type.isInstance(mo)) { + return type.cast(mo); + } else { + UnrecognizedElementException e = new UnrecognizedElementException(name); + throw e; + } + } catch (ContributionReadException e) { + Location location = reader.getLocation(); + e.setLine(location.getLineNumber()); + e.setColumn(location.getColumnNumber()); + throw e; + } finally { + try { + reader.close(); + } catch (XMLStreamException e) { + // ignore + } + } + } finally { + try { + is.close(); + } catch (IOException e) { + // ignore + } + } + } catch (XMLStreamException e) { + ContributionReadException ce = new ContributionReadException(e); + throw ce; + } + } + + /** + * Write a model to an ouput stream. + * @param model + * @param os + * @throws ContributionWriteException + */ + public void write(Object model, OutputStream os) throws ContributionWriteException { + try { + XMLStreamWriter writer = outputFactory.createXMLStreamWriter(os); + write(model, writer); + writer.flush(); + writer.close(); + } catch (XMLStreamException e) { + throw new ContributionWriteException(e); + } + } + + public QName getArtifactType() { + return null; + } + + public Class getModelType() { + return null; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleURLArtifactProcessor.java b/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleURLArtifactProcessor.java new file mode 100644 index 0000000000..40917861da --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleURLArtifactProcessor.java @@ -0,0 +1,98 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.contribution.processor; + +import java.net.URI; +import java.net.URL; + +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.contribution.service.ContributionResolveException; +import org.apache.tuscany.sca.contribution.service.UnrecognizedElementException; + +/** + * The default implementation of a URL artifact processor. + * + * @version $Rev$ $Date$ + */ +public class ExtensibleURLArtifactProcessor + implements URLArtifactProcessor { + + private URLArtifactProcessorExtensionPoint processors; + + /** + * Constructs a new URL artifact processor. + * + * @param processors + */ + public ExtensibleURLArtifactProcessor(URLArtifactProcessorExtensionPoint processors) { + this.processors = processors; + } + + @SuppressWarnings("unchecked") + public Object read(URL contributionURL, URI sourceURI, URL sourceURL) throws ContributionReadException { + URLArtifactProcessor processor = null; + + // Delegate to the processor associated with file extension + String extension = sourceURL.getFile(); + int extensionStart = extension.lastIndexOf('.'); + //handle files without extension (e.g NOTICE) + if (extensionStart > 0) { + extension = extension.substring(extensionStart); + processor = (URLArtifactProcessor)processors.getProcessor(extension); + } + if (processor == null) { + return null; + } + return processor.read(contributionURL, sourceURI, sourceURL); + } + + @SuppressWarnings("unchecked") + public void resolve(Object model, ModelResolver resolver) throws ContributionResolveException { + + // Delegate to the processor associated with the model type + if (model != null) { + URLArtifactProcessor processor = processors.getProcessor(model.getClass()); + if (processor != null) { + processor.resolve(model, resolver); + } + } + } + + public MO read(URL contributionURL, URI artifactURI, URL artifactUrl, Class type) + throws ContributionReadException { + Object mo = read(contributionURL, artifactURI, artifactUrl); + if (type.isInstance(mo)) { + return type.cast(mo); + } else { + UnrecognizedElementException e = new UnrecognizedElementException(null); + e.setResourceURI(artifactURI.toString()); + throw e; + } + } + + public String getArtifactType() { + return null; + } + + public Class getModelType() { + return null; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/PackageProcessor.java b/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/PackageProcessor.java new file mode 100644 index 0000000000..28b268301f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/PackageProcessor.java @@ -0,0 +1,67 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.contribution.processor; + +import java.io.IOException; +import java.io.InputStream; +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URL; +import java.util.List; + +import org.apache.tuscany.sca.contribution.service.ContributionException; + +/** + * Contribution package processors + * These processors understand the internal format of the contribution and how to process the artifacts + * + * @version $Rev$ $Date$ + */ +public interface PackageProcessor { + + /** + * Returns the type of package supported by this package processor. + * + * @return the package type + */ + String getPackageType(); + + /** + * Retrieve a list of artifacts for the specific package type + * + * @param packageSourceURL Contribution package location URL + * @param inputStream Optional content of the package + * @return List of artifact URIs + * @throws ContributionException + * @throws IOException + */ + List getArtifacts(URL packageSourceURL, InputStream inputStream) throws ContributionException, IOException; + + /** + * Return the URL for an artifact in the package. + * This is needed in the case of special archives such as jar files that have special + * URL structure for internal artifacts + * + * @param packageSourceURL Contribution package location URL + * @param artifact The relative URI for the artifact + * @return The artifact URL + */ + URL getArtifactURL(URL packageSourceURL, URI artifact) throws MalformedURLException; + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/PackageProcessorExtensionPoint.java b/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/PackageProcessorExtensionPoint.java new file mode 100644 index 0000000000..27499b5847 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/PackageProcessorExtensionPoint.java @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.contribution.processor; + +/** + * An extension point for package processors + * + * @version $Rev$ $Date$ + */ +public interface PackageProcessorExtensionPoint { + + /** + * Register a PackageProcessor using the package type as the key + * + * @param processor The package processor + */ + void addPackageProcessor(PackageProcessor processor); + + /** + * Unregister a PackageProcessor + * + * @param processor The package processor + */ + void removePackageProcessor(PackageProcessor processor); + + /** + * Returns the PackageProcessor for the given package type. + * + * @param packageType The package type + * @return The package processor + */ + PackageProcessor getPackageProcessor(String packageType); + +} \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/StAXArtifactProcessor.java b/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/StAXArtifactProcessor.java new file mode 100644 index 0000000000..89c063a65e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/StAXArtifactProcessor.java @@ -0,0 +1,63 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.contribution.processor; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.contribution.service.ContributionWriteException; + +/** + * An artifact processor that can read models from a StAX XMLStreamReader. + * + * @version $Rev$ $Date$ + */ +public interface StAXArtifactProcessor extends ArtifactProcessor { + + /** + * Reads a model from an input source. Examples of input sources are: a URI, a + * DOM node, an XML reader. + * + * @param inputSource The input source + * @return A model representation of the input. + */ + M read(XMLStreamReader inputSource) throws ContributionReadException, XMLStreamException; + + /** + * Writes a model to an ouput source. Examples of output sources are: a URI, a + * DOM node, an XML writer. + * + * @param model A model representing the source + * @param outputSource The output source + * @throws ContributionWriteException + * @throws XMLStreamException + */ + void write(M model, XMLStreamWriter outputSource) throws ContributionWriteException, XMLStreamException; + + /** + * Returns the type of artifact handled by this artifact processor. + * + * @return The type of artifact handled by this artifact processor + */ + QName getArtifactType(); +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/StAXArtifactProcessorExtensionPoint.java b/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/StAXArtifactProcessorExtensionPoint.java new file mode 100644 index 0000000000..9a6388119e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/StAXArtifactProcessorExtensionPoint.java @@ -0,0 +1,29 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.contribution.processor; + +/** + * A registry for DOM artifact processors. + * + * @version $Rev$ $Date$ + */ +public interface StAXArtifactProcessorExtensionPoint extends + ArtifactProcessorExtensionPoint { + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/URLArtifactProcessor.java b/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/URLArtifactProcessor.java new file mode 100644 index 0000000000..ca95036912 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/URLArtifactProcessor.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.contribution.processor; + +import java.net.URI; +import java.net.URL; + +import org.apache.tuscany.sca.contribution.service.ContributionReadException; + +/** + * An artifact processor that can read models from an InputStream. + * + * @version $Rev$ $Date$ + */ +public interface URLArtifactProcessor extends ArtifactProcessor { + + /** + * Reads a model from an input source. Examples of input + * sources are: a URI, a DOM node, an XML reader. + * + * @param contributionURL Contribution location URL + * @param artifactURI Artifact URI + * @param artifactURL Artifact location URL + * @return A model representation of the input. + */ + M read(URL contributionURL, URI artifactURI, URL artifactURL) throws ContributionReadException; + + /** + * Returns the type of artifact handled by this artifact processor. + * + * @return The type of artifact handled by this artifact processor + */ + String getArtifactType(); + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/URLArtifactProcessorExtensionPoint.java b/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/URLArtifactProcessorExtensionPoint.java new file mode 100644 index 0000000000..95213f9dd1 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/URLArtifactProcessorExtensionPoint.java @@ -0,0 +1,29 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.contribution.processor; + +/** + * A registry for Stream artifact processors. + * + * @version $Rev$ $Date$ + */ +public interface URLArtifactProcessorExtensionPoint extends + ArtifactProcessorExtensionPoint { + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/ClassReference.java b/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/ClassReference.java new file mode 100644 index 0000000000..da216983ea --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/ClassReference.java @@ -0,0 +1,103 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.contribution.resolver; + +import java.lang.ref.WeakReference; + +/** + * A weak reference to a class, which should be used to register classes + * with an ArtifactResolver and resolve these classes later. + * + * @version $Rev$ $Date$ + */ +public class ClassReference { + + private WeakReference clazz; + private String className; + + /** + * Constructs a new ClassReference. + * + * @param clazz The class reference + */ + public ClassReference(Class clazz) { + this.clazz = new WeakReference(clazz); + this.className = clazz.getName(); + } + + /** + * Constructs a new ClassReference. + * + * @param className The class name + */ + public ClassReference(String className) { + this.className = className; + } + + /** + * Get the referenced class. + * + * @return The referenced class + */ + public Class getJavaClass() { + if (clazz != null) { + return clazz.get(); + } else { + return null; + } + } + + /** + * Get the referenced class name. + * + * @return The class name + */ + public String getClassName() { + return className; + } + + /** + * Returns true if the class reference is unresolved. + * + * @return Wether or not the class has been resolved + */ + boolean isUnresolved() { + return clazz == null; + } + + @Override + public int hashCode() { + return className.hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (obj == this) { + return true; + } else { + if (obj instanceof ClassReference) { + return className.equals(((ClassReference)obj).className); + } else { + return false; + } + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/ModelResolver.java b/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/ModelResolver.java new file mode 100644 index 0000000000..850f79fdea --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/ModelResolver.java @@ -0,0 +1,66 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.contribution.resolver; + +/** + * SCA Assemblies reference many artifacts of a wide variety of types. These + * include: + *
    + *
  • Reference from one SCA composite to another SCA composite + *
  • Reference to PolicySet files + *
  • Reference to interface definition files, either WSDL or Java interfaces + *
  • Reference to XSD files + *
  • Reference to any of a wide variety of implementation artifact files, + * including Java classes, BPEL scripts, C++ DLLs and classes, PHP scripts + *
+ * In the SCA assemblies, these various artifacts are referenced using either + * QNames or URIs that do not point to a specific entity. Resolution of these + * references to concrete artifacts is necessary as part of the operation of the + * SCA domain. + * + * @version $Rev$ $Date$ + */ +public interface ModelResolver { + + /** + * Resolve the model representing an artifact. + * + * @param modelClass the type of artifact + * @param unresolved the unresolved model + * @return the resolved model + */ + T resolveModel(Class modelClass, T unresolved); + + /** + * Add a resolved model. + * + * @param resolved The model + */ + void addModel(Object resolved); + + /** + * Remove a resolved model. + * + * @param resolved + * @return The removed model, or null if the model was not removed + */ + Object removeModel(Object resolved); + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/AbstractContributionException.java b/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/AbstractContributionException.java new file mode 100644 index 0000000000..7b58a9c2c3 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/AbstractContributionException.java @@ -0,0 +1,124 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.contribution.service; + +import java.io.PrintWriter; + +/** + * The root checked exception for the Contribution Service. + * + * @version $Rev: 508877 $ $Date: 2007-02-17 22:22:48 -0800 (Sat, 17 Feb 2007) $ + */ +public abstract class AbstractContributionException extends Exception { + private static final long serialVersionUID = -7847121698339635268L; + private final String identifier; + + /** + * Override constructor from Exception. + * + * @see Exception + */ + public AbstractContributionException() { + super(); + this.identifier = null; + } + + /** + * Override constructor from Exception. + * + * @param message passed to Exception + * @see Exception + */ + public AbstractContributionException(String message) { + super(message); + this.identifier = null; + } + + /** + * Override constructor from Exception. + * + * @param message passed to Exception + * @param identifier additional error information referred to in the error message + * @see Exception + */ + public AbstractContributionException(String message, String identifier) { + super(message); + this.identifier = identifier; + } + + /** + * Override constructor from Exception. + * + * @param message passed to Exception + * @param cause passed to Exception + * @see Exception + */ + public AbstractContributionException(String message, Throwable cause) { + super(message, cause); + this.identifier = null; + } + + /** + * Override constructor from Exception. + * + * @param message passed to Exception + * @param identifier additional error information referred to in the error message + * @param cause passed to Exception + * @see Exception + */ + public AbstractContributionException(String message, String identifier, Throwable cause) { + super(message, cause); + this.identifier = identifier; + } + + /** + * Override constructor from Exception. + * + * @param cause passed to Exception + * @see Exception + */ + public AbstractContributionException(Throwable cause) { + super(cause); + this.identifier = null; + } + + /** + * Returns a string representing additional error information referred to in the error message. + * + * @return additional error information + */ + public String getIdentifier() { + return identifier; + } + + public PrintWriter appendBaseMessage(PrintWriter writer) { + if (identifier == null) { + if (super.getMessage() == null) { + return writer; + } + return writer.append(super.getMessage()); + } + if (super.getMessage() != null) { + writer.append(super.getMessage()); + } + writer.append(" [").append(identifier).append(']'); + return writer; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionException.java b/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionException.java new file mode 100644 index 0000000000..84dcdc19c5 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionException.java @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.contribution.service; + +/** + * Base class for exceptions raised by contribution services. + * + * @version $Rev: 519710 $ $Date: 2007-03-18 15:19:16 -0700 (Sun, 18 Mar 2007) $ + */ +public class ContributionException extends AbstractContributionException { + /** + * + */ + private static final long serialVersionUID = 4432880414927652578L; + + protected ContributionException() { + super(); + } + + protected ContributionException(String message) { + super(message); + } + + protected ContributionException(String message, String identifier) { + super(message, identifier); + } + + protected ContributionException(String message, Throwable cause) { + super(message, cause); + } + + protected ContributionException(String message, String identifier, Throwable cause) { + super(message, identifier, cause); + } + + public ContributionException(Throwable cause) { + super(cause); + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionMetadataLoader.java b/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionMetadataLoader.java new file mode 100644 index 0000000000..e41b13a567 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionMetadataLoader.java @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.contribution.service; + +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.sca.contribution.Contribution; + +/** + * Loader responsible to process the contribution metadata loader + * + * @version $Rev$ $Date$ + */ +public interface ContributionMetadataLoader { + /** + * Create the model object for Contribution Service metadata information + * + * @param contribution The contribution to populate with the proper values from the side file + * @param reader The XML stream reader positioned on the applicable START_ELEMENT + * @throws XMLStreamException + * @throws ContributionMetadataReadException + */ + void load(Contribution contribution, XMLStreamReader reader) throws XMLStreamException, ContributionMetadataLoaderException; +} \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionMetadataLoaderException.java b/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionMetadataLoaderException.java new file mode 100644 index 0000000000..7dd52c6c1a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionMetadataLoaderException.java @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.contribution.service; + +/** + * Denotes an exception while processing the contribution metadata + * + * @version $Rev$ $Date$ + */ +public class ContributionMetadataLoaderException extends ContributionException { + private static final long serialVersionUID = 2442537028550702609L; + + public ContributionMetadataLoaderException() { + super(); + } + + public ContributionMetadataLoaderException(String message) { + super(message); + } + + public ContributionMetadataLoaderException(String message, String identifier) { + super(message, identifier); + } + + public ContributionMetadataLoaderException(String message, Throwable cause) { + super(message, cause); + } + + public ContributionMetadataLoaderException(String message, String identifier, Throwable cause) { + super(message, identifier, cause); + } + + public ContributionMetadataLoaderException(Throwable cause) { + super(cause); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionReadException.java b/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionReadException.java new file mode 100644 index 0000000000..f84fd98f0b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionReadException.java @@ -0,0 +1,94 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.contribution.service; + +/** + * Denotes an exception while reading artifacts inside an SCA contribution. + * + * @version $Rev: 526268 $ $Date: 2007-04-06 13:13:26 -0700 (Fri, 06 Apr 2007) $ + */ +public class ContributionReadException extends ContributionException { + public static final int UNDEFINED = -1; + private static final long serialVersionUID = -7459051598906813461L; + private String resourceURI; + private int line = UNDEFINED; + private int column = UNDEFINED; + + public ContributionReadException(String message) { + super(message); + } + + public ContributionReadException(String message, Throwable cause) { + super(message, cause); + } + + public ContributionReadException(Throwable cause) { + super(cause); + } + + /** + * Returns the location of the resource that was being read. + * + * @return the location of the resource that was being read + */ + public String getResourceURI() { + return resourceURI; + } + + /** + * Sets the location of the resource that was being read. + * + * @param resourceURI the location of the resource that was being read + */ + public void setResourceURI(String resourceURI) { + this.resourceURI = resourceURI; + } + + /** + * Returns the line inside the resource that was being read. + * @return the line inside the resource that was being read + */ + public int getLine() { + return line; + } + + /** + * Sets the line inside the resource that was being read. + * @param line the line inside the resource that was being read + */ + public void setLine(int line) { + this.line = line; + } + + /** + * Returns the column inside the resource that was being read. + * @return the column inside the resource that was being read + */ + public int getColumn() { + return column; + } + + /** + * Sets the column inside the resource that was being read. + * @param column the column inside the resource that was being read + */ + public void setColumn(int column) { + this.column = column; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionRepository.java b/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionRepository.java new file mode 100644 index 0000000000..d4c69bede3 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionRepository.java @@ -0,0 +1,93 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.contribution.service; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.net.URL; +import java.util.List; + +/** + * Contribution repository + * + * @version $Rev$ $Date$ + */ +public interface ContributionRepository { + /** + * Get the URI of the SCA domain + * + * @return The domain URI + */ + URI getDomain(); + + /** + * Copies a contribution to the repository. + * + * @param contribution A URl pointing to the contribution being copied to + * the repository + * @param sourceURL url of the source. this would be used to calculate the right + * filename to be stored on the repository when a inputStream is being + * provided + * @param contributionStream InputStream with the content of the + * distribution + * @return A URL pointing to the content of the contribution in the + * repository + * @throws IOException + */ + URL store(String contribution, URL sourceURL, InputStream contributionStream) throws IOException; + /** + * Copy a contribution from the source URL to the repository + * + * @param contribution A URl pointing to the contribution being copied to + * the repository + * @param sourceURL url of the source. this would be used to calculate the right + * filename to be stored on the repository when a inputStream is being + * provided + * @return A URL pointing to the content of the contribution in the + * repository + * @throws IOException + */ + URL store(String contribution, URL sourceURL) throws IOException; + + /** + * Look up the contribution by URI + * + * @param contribution The URI of the contribution + * @return A URL pointing to the content of the contribution in the + * repository, it will be null if the contribution cannot be found + * in the repository + */ + URL find(String contribution); + + /** + * Remove a contribution from the repository + * + * @param contribution The URI of the contribution to be removed + */ + void remove(String contribution); + + /** + * Get list of URIs for all the contributions in the repository + * + * @return A list of contribution URIs + */ + List list(); +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionResolveException.java b/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionResolveException.java new file mode 100644 index 0000000000..e9392f55eb --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionResolveException.java @@ -0,0 +1,41 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.contribution.service; + +/** + * Denotes a problem while resolving models inside an SCA contribution. + * + * @version $Rev: 526268 $ $Date: 2007-04-06 13:13:26 -0700 (Fri, 06 Apr 2007) $ + */ +public class ContributionResolveException extends ContributionException { + private static final long serialVersionUID = -7459051598906813461L; + + public ContributionResolveException(String message) { + super(message); + } + + public ContributionResolveException(String message, Throwable cause) { + super(message, cause); + } + + public ContributionResolveException(Throwable cause) { + super(cause); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionRuntimeException.java b/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionRuntimeException.java new file mode 100644 index 0000000000..90dae0018c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionRuntimeException.java @@ -0,0 +1,44 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.contribution.service; + +/** + * Base class for runtime exceptions raised by contribution services. + * + * @version $Rev: 526837 $ $Date: 2007-04-09 10:10:18 -0700 (Mon, 09 Apr 2007) $ + */ +public class ContributionRuntimeException extends RuntimeException { + private static final long serialVersionUID = 7711215366287498896L; + + protected ContributionRuntimeException() { + super(); + } + + protected ContributionRuntimeException(String message) { + super(message); + } + + protected ContributionRuntimeException(String message, Throwable cause) { + super(message, cause); + } + + public ContributionRuntimeException(Throwable cause) { + super(cause); + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionService.java b/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionService.java new file mode 100644 index 0000000000..1b21e60fbe --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionService.java @@ -0,0 +1,104 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.contribution.service; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; + +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.contribution.Contribution; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; + +/** + * Service interface that manages artifacts contributed to a Tuscany runtime. + * + * @version $Rev: 527398 $ $Date: 2007-04-10 23:43:31 -0700 (Tue, 10 Apr 2007) $ + */ +public interface ContributionService { + /** + * Contribute an artifact to the SCA Domain. The type of the contribution is + * determined by the Content-Type of the resource or, if that is undefined, + * by some implementation-specific means (such as mapping an extension in + * the URL's path). + * + * @param contributionURI The URI that is used as the contribution unique ID. + * @param sourceURL The location of the resource containing the artifact + * @param modelResolver The model resolver to use to resolve models in the + * scope of this contribution + * @param storeInRepository Flag that identifies if you want to copy the + * contribution to the repository + * @return The contribution model representing the contribution + * @throws DeploymentException if there was a problem with the contribution + * @throws IOException if there was a problem reading the resource + */ + Contribution contribute(String contributionURI, URL sourceURL, ModelResolver modelResolver, boolean storeInRepository) throws ContributionException, + IOException; + + /** + * Contribute an artifact to the SCA Domain. + * + * @param contributionURI The URI that is used as the contribution unique ID. + * @param sourceURL The location of the resource containing the artifact. + * This is used to identify what name should be used when storing + * the contribution on the repository + * @param modelResolver The model resolver to use to resolve models in the + * scope of this contribution + * @param contributionContent A stream containing the resource being + * contributed; the stream will not be closed but the read + * position after the call is undefined + * @return The contribution model representing the contribution + * @throws DeploymentException if there was a problem with the contribution + * @throws IOException if there was a problem reading the stream + */ + Contribution contribute(String contributionURI, URL sourceURL, InputStream contributionContent, ModelResolver modelResolver) + throws ContributionException, IOException; + + /** + * Get the model for an installed contribution + * + * @param contribution The URI of an installed contribution + * @return The model for the contribution or null if there is no such + * contribution + */ + Contribution getContribution(String contribution); + + /** + * Adds or updates a deployment composite using a supplied composite + * ("composite by value" - a data structure, not an existing resource in the + * domain) to the contribution identified by a supplied contribution URI. + * The added or updated deployment composite is given a relative URI that + * matches the "name" attribute of the composite, with a ".composite" + * suffix. + * + * @param contribution The contribution to where + * @param composite + * @throws ContributionException + */ + void addDeploymentComposite(Contribution contribution, Composite composite) throws ContributionException; + + /** + * Remove a contribution from the SCA domain + * + * @param contribution The URI of the contribution + * @throws DeploymentException + */ + void remove(String contribution) throws ContributionException; + +} \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionWireException.java b/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionWireException.java new file mode 100644 index 0000000000..6d13a0dfb7 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionWireException.java @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.contribution.service; + + +/** + * Denotes a problem while wiring models inside an SCA contribution. + * + * @version $Rev: 526268 $ $Date: 2007-04-06 13:13:26 -0700 (Fri, 06 Apr 2007) $ + */ +public class ContributionWireException extends ContributionException { + private static final long serialVersionUID = -7459051598906813461L; + + public ContributionWireException(String message) { + super(message); + } + + public ContributionWireException(String message, Throwable cause) { + super(message, cause); + } + + public ContributionWireException(Throwable cause) { + super(cause); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionWriteException.java b/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionWriteException.java new file mode 100644 index 0000000000..db078ebdf3 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionWriteException.java @@ -0,0 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.contribution.service; + + +/** + * Denotes an exception while writing artifacts inside an SCA contribution. + * + * @version $Rev: 526268 $ $Date: 2007-04-06 13:13:26 -0700 (Fri, 06 Apr 2007) $ + */ +public class ContributionWriteException extends ContributionException { + private static final long serialVersionUID = -7459051598906813461L; + private String resourceURI; + + public ContributionWriteException(String message) { + super(message); + } + + public ContributionWriteException(String message, Throwable cause) { + super(message, cause); + } + + public ContributionWriteException(Throwable cause) { + super(cause); + } + + /** + * Returns the location of the resource that was being written. + * + * @return the location of the resource that was being written + */ + public String getResourceURI() { + return resourceURI; + } + + /** + * Sets the location of the resource that was being written. + * + * @param resourceURI the location of the resource that was being written + */ + public void setResourceURI(String resourceURI) { + this.resourceURI = resourceURI; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/InvalidConfigurationException.java b/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/InvalidConfigurationException.java new file mode 100644 index 0000000000..a3ff0072a1 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/InvalidConfigurationException.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.contribution.service; + +/** + * Denotes an invalid configuration artifact + * + * @version $Rev: 525638 $ $Date: 2007-04-04 16:36:03 -0700 (Wed, 04 Apr 2007) $ + */ +public class InvalidConfigurationException extends ContributionReadException { + private static final long serialVersionUID = -4312958640212000366L; + + public InvalidConfigurationException(String message, Throwable cause) { + super(message, cause); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/TypeDescriber.java b/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/TypeDescriber.java new file mode 100644 index 0000000000..46ad89fc78 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/TypeDescriber.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.contribution.service; + +import java.net.URL; + +/** + * Provide content type for a given resource + * + * @version $Rev: 526079 $ $Date: 2007-04-06 00:17:44 -0700 (Fri, 06 Apr 2007) $ + */ +public interface TypeDescriber { + /** + * Get the content type for the specified resource + * + * @param resourceURL The resource url + * @param defaultType The default content type + * @return The content type + */ + String getType(URL resourceURL, String defaultType); +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/UnrecognizedElementException.java b/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/UnrecognizedElementException.java new file mode 100644 index 0000000000..42d74e5e22 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/UnrecognizedElementException.java @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.contribution.service; + +import javax.xml.namespace.QName; + +/** + * Exception that indicates an element was encountered that could not be handled. + * + * @version $Rev: 525638 $ $Date: 2007-04-04 16:36:03 -0700 (Wed, 04 Apr 2007) $ + */ +public class UnrecognizedElementException extends ContributionReadException { + private static final long serialVersionUID = 2549543622209829032L; + private final QName element; + + /** + * Constructor that indicates which element could not be handled. + * @param element the element that could not be handled + */ + public UnrecognizedElementException(QName element) { + super("Unrecognized element: " + element.toString()); + this.element = element; + } + + /** + * Returns the element that could not be handled. + * @return the element that could not be handled. + */ + public QName getElement() { + return element; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/UnsupportedContentTypeException.java b/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/UnsupportedContentTypeException.java new file mode 100644 index 0000000000..737362eb97 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/UnsupportedContentTypeException.java @@ -0,0 +1,49 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.contribution.service; + +/** + * Exception thrown to indicate that a Content-Type is not supported by this SCA Domain. + * The Content-Type value supplied will be returned as the message text for this exception. + * + * @version $Rev: 522653 $ $Date: 2007-03-26 15:30:21 -0700 (Mon, 26 Mar 2007) $ + */ +public class UnsupportedContentTypeException extends ContributionException { + private static final long serialVersionUID = -1831797280021355672L; + + /** + * Constructor specifying the Content-Type value that is not supported. + * + * @param contentType the type that is not supported + */ + public UnsupportedContentTypeException(String contentType) { + super(contentType); + } + + /** + * Constructor specifying the Content-Type value that is not supported + * and an identifier to use with this exception (typically the resource being processed). + * + * @param contentType the type that is not supported + * @param identifier an identifier for this exception + */ + public UnsupportedContentTypeException(String contentType, String identifier) { + super(contentType, identifier); + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core-databinding/.checkstyle b/sca-java-1.x/branches/sca-java-0.91/modules/core-databinding/.checkstyle new file mode 100644 index 0000000000..c7b30ffd5e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core-databinding/.checkstyle @@ -0,0 +1,25 @@ + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core-databinding/.pmd b/sca-java-1.x/branches/sca-java-0.91/modules/core-databinding/.pmd new file mode 100644 index 0000000000..2db10d6a6a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core-databinding/.pmd @@ -0,0 +1,20 @@ + + +truefalse \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core-databinding/.ruleset b/sca-java-1.x/branches/sca-java-0.91/modules/core-databinding/.ruleset new file mode 100644 index 0000000000..ba9b5ce886 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core-databinding/.ruleset @@ -0,0 +1,190 @@ + + + + PMD Plugin preferences rule set + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core-databinding/DISCLAIMER b/sca-java-1.x/branches/sca-java-0.91/modules/core-databinding/DISCLAIMER new file mode 100644 index 0000000000..d68a410903 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core-databinding/DISCLAIMER @@ -0,0 +1,8 @@ +Apache Tuscany is an effort undergoing incubation at The Apache Software +Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is +required of all newly accepted projects until a further review indicates that +the infrastructure, communications, and decision making process have stabilized +in a manner consistent with other successful ASF projects. While incubation +status is not necessarily a reflection of the completeness or stability of the +code, it does indicate that the project has yet to be fully endorsed by the ASF. + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core-databinding/LICENSE b/sca-java-1.x/branches/sca-java-0.91/modules/core-databinding/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core-databinding/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core-databinding/NOTICE b/sca-java-1.x/branches/sca-java-0.91/modules/core-databinding/NOTICE new file mode 100644 index 0000000000..94481d6cfa --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core-databinding/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2007 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core-databinding/pom.xml b/sca-java-1.x/branches/sca-java-0.91/modules/core-databinding/pom.xml new file mode 100644 index 0000000000..9fb6d998b6 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core-databinding/pom.xml @@ -0,0 +1,82 @@ + + + + + org.apache.tuscany.sca + tuscany-modules + 0.91-incubating-SNAPSHOT + ../pom.xml + + 4.0.0 + org.apache.tuscany.sca + tuscany-core-databinding + jar + Apache Tuscany Core/DataBinding Integration + Apache Tuscany Core/DataBinding Integration + + + org.apache.tuscany.sca + tuscany-databinding + ${project.version} + compile + + + + org.apache.tuscany.sca + tuscany-core-spi + ${project.version} + compile + + + + org.apache.tuscany.sca + tuscany-interface-java-xml + ${project.version} + compile + + + + org.codehaus.woodstox + wstx-asl + runtime + 3.2.0 + + + + stax + stax-api + 1.0.1 + + + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core-databinding/src/main/java/org/apache/tuscany/core/databinding/module/DataBindingModuleActivator.java b/sca-java-1.x/branches/sca-java-0.91/modules/core-databinding/src/main/java/org/apache/tuscany/core/databinding/module/DataBindingModuleActivator.java new file mode 100644 index 0000000000..32666174b2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core-databinding/src/main/java/org/apache/tuscany/core/databinding/module/DataBindingModuleActivator.java @@ -0,0 +1,151 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.core.databinding.module; + +import org.apache.tuscany.core.databinding.processor.DataBindingJavaInterfaceProcessor; +import org.apache.tuscany.core.databinding.transformers.Exception2ExceptionTransformer; +import org.apache.tuscany.core.databinding.transformers.Input2InputTransformer; +import org.apache.tuscany.core.databinding.transformers.Output2OutputTransformer; +import org.apache.tuscany.core.databinding.wire.DataBindingRuntimeWireProcessor; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.ModuleActivator; +import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint; +import org.apache.tuscany.sca.databinding.DefaultDataBindingExtensionPoint; +import org.apache.tuscany.sca.databinding.DefaultTransformerExtensionPoint; +import org.apache.tuscany.sca.databinding.TransformerExtensionPoint; +import org.apache.tuscany.sca.databinding.impl.MediatorImpl; +import org.apache.tuscany.sca.databinding.impl.Group2GroupTransformer; +import org.apache.tuscany.sca.databinding.javabeans.DOMNode2JavaBeanTransformer; +import org.apache.tuscany.sca.databinding.javabeans.JavaBean2DOMNodeTransformer; +import org.apache.tuscany.sca.databinding.javabeans.JavaBeansDataBinding; +import org.apache.tuscany.sca.databinding.xml.DOMDataBinding; +import org.apache.tuscany.sca.databinding.xml.InputSource2Node; +import org.apache.tuscany.sca.databinding.xml.InputSource2SAX; +import org.apache.tuscany.sca.databinding.xml.InputStream2Node; +import org.apache.tuscany.sca.databinding.xml.InputStream2SAX; +import org.apache.tuscany.sca.databinding.xml.Node2OutputStream; +import org.apache.tuscany.sca.databinding.xml.Node2String; +import org.apache.tuscany.sca.databinding.xml.Node2Writer; +import org.apache.tuscany.sca.databinding.xml.Node2XMLStreamReader; +import org.apache.tuscany.sca.databinding.xml.Reader2Node; +import org.apache.tuscany.sca.databinding.xml.Reader2SAX; +import org.apache.tuscany.sca.databinding.xml.SAX2DOMPipe; +import org.apache.tuscany.sca.databinding.xml.Source2ResultTransformer; +import org.apache.tuscany.sca.databinding.xml.StreamDataPipe; +import org.apache.tuscany.sca.databinding.xml.String2Node; +import org.apache.tuscany.sca.databinding.xml.String2SAX; +import org.apache.tuscany.sca.databinding.xml.String2XMLStreamReader; +import org.apache.tuscany.sca.databinding.xml.Writer2ReaderDataPipe; +import org.apache.tuscany.sca.databinding.xml.XMLGroupDataBinding; +import org.apache.tuscany.sca.databinding.xml.XMLStreamReader2Node; +import org.apache.tuscany.sca.databinding.xml.XMLStreamReader2SAX; +import org.apache.tuscany.sca.databinding.xml.XMLStreamReader2String; +import org.apache.tuscany.sca.databinding.xml.XMLStringDataBinding; +import org.apache.tuscany.sca.interfacedef.java.introspect.JavaInterfaceIntrospectorExtensionPoint; +import org.apache.tuscany.sca.runtime.RuntimeWireProcessorExtensionPoint; + +/** + * @version $Rev$ $Date$ + */ +public class DataBindingModuleActivator implements ModuleActivator { + + private DataBindingExtensionPoint dataBindings; + private TransformerExtensionPoint transformers; + + public Object[] getExtensionPoints() { + dataBindings = new DefaultDataBindingExtensionPoint(); + transformers = new DefaultTransformerExtensionPoint(dataBindings); + return new Object[] { dataBindings, transformers }; + } + + public void start(ExtensionPointRegistry registry) { + MediatorImpl mediator = new MediatorImpl(dataBindings, transformers); + Input2InputTransformer input2InputTransformer = new Input2InputTransformer(); + input2InputTransformer.setMediator(mediator); + + Output2OutputTransformer output2OutputTransformer = new Output2OutputTransformer(); + output2OutputTransformer.setMediator(mediator); + + Exception2ExceptionTransformer exception2ExceptionTransformer = new Exception2ExceptionTransformer(); + exception2ExceptionTransformer.setMediator(mediator); + + transformers.addTransformer(input2InputTransformer); + transformers.addTransformer(output2OutputTransformer); + transformers.addTransformer(exception2ExceptionTransformer); + + JavaInterfaceIntrospectorExtensionPoint introspectors = registry + .getExtensionPoint(JavaInterfaceIntrospectorExtensionPoint.class); + introspectors.addInterfaceVisitor(new DataBindingJavaInterfaceProcessor(dataBindings)); + + RuntimeWireProcessorExtensionPoint wireProcessorExtensionPoint = registry + .getExtensionPoint(RuntimeWireProcessorExtensionPoint.class); + if (wireProcessorExtensionPoint != null) { + wireProcessorExtensionPoint.addWireProcessor(new DataBindingRuntimeWireProcessor(mediator)); + } + + DOMDataBinding domDataBinding = new DOMDataBinding(); + domDataBinding.setDataBindingRegistry(dataBindings); + dataBindings.addDataBinding(domDataBinding); + XMLStringDataBinding xmlStringDataBinding = new XMLStringDataBinding(); + xmlStringDataBinding.setDataBindingRegistry(dataBindings); + dataBindings.addDataBinding(xmlStringDataBinding); + XMLGroupDataBinding xmlGroupDataBinding = new XMLGroupDataBinding(); + xmlGroupDataBinding.setDataBindingRegistry(dataBindings); + dataBindings.addDataBinding(xmlGroupDataBinding); + JavaBeansDataBinding javaBeansDataBinding = new JavaBeansDataBinding(); + javaBeansDataBinding.setDataBindingRegistry(dataBindings); + dataBindings.addDataBinding(javaBeansDataBinding); + + Group2GroupTransformer group2GroupTransformer = new Group2GroupTransformer(); + group2GroupTransformer.setMediator(mediator); + transformers.addTransformer(group2GroupTransformer); + + transformers.addTransformer(new InputSource2Node()); + transformers.addTransformer(new InputSource2SAX()); + transformers.addTransformer(new InputStream2Node()); + transformers.addTransformer(new InputStream2SAX()); + + transformers.addTransformer(new DOMNode2JavaBeanTransformer()); + transformers.addTransformer(new Node2OutputStream()); + transformers.addTransformer(new Node2String()); + transformers.addTransformer(new Node2Writer()); + transformers.addTransformer(new Node2XMLStreamReader()); + + transformers.addTransformer(new JavaBean2DOMNodeTransformer()); + transformers.addTransformer(new Reader2Node()); + + transformers.addTransformer(new Reader2SAX()); + transformers.addTransformer(new SAX2DOMPipe()); + + transformers.addTransformer(new Source2ResultTransformer()); + transformers.addTransformer(new StreamDataPipe()); + transformers.addTransformer(new String2Node()); + transformers.addTransformer(new String2SAX()); + transformers.addTransformer(new String2XMLStreamReader()); + transformers.addTransformer(new Writer2ReaderDataPipe()); + + transformers.addTransformer(new XMLStreamReader2Node()); + transformers.addTransformer(new XMLStreamReader2SAX()); + transformers.addTransformer(new XMLStreamReader2String()); + } + + public void stop(ExtensionPointRegistry registry) { + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core-databinding/src/main/java/org/apache/tuscany/core/databinding/processor/DataBindingJavaInterfaceProcessor.java b/sca-java-1.x/branches/sca-java-0.91/modules/core-databinding/src/main/java/org/apache/tuscany/core/databinding/processor/DataBindingJavaInterfaceProcessor.java new file mode 100644 index 0000000000..b26846c682 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core-databinding/src/main/java/org/apache/tuscany/core/databinding/processor/DataBindingJavaInterfaceProcessor.java @@ -0,0 +1,135 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.core.databinding.processor; + +import java.lang.reflect.Method; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint; +import org.apache.tuscany.sca.databinding.annotation.DataBinding; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.java.JavaInterface; +import org.apache.tuscany.sca.interfacedef.java.introspect.JavaInterfaceVisitor; +import org.osoa.sca.annotations.Reference; + +/** + * The databinding annotation processor for java interfaces + * + * @version $Rev$ $Date$ + */ +public class DataBindingJavaInterfaceProcessor implements JavaInterfaceVisitor { + private DataBindingExtensionPoint dataBindingRegistry; + + public DataBindingJavaInterfaceProcessor(@Reference + DataBindingExtensionPoint dataBindingRegistry) { + super(); + this.dataBindingRegistry = dataBindingRegistry; + } + + public void visitInterface(JavaInterface javaInterface) throws InvalidInterfaceException { + if (!javaInterface.isRemotable()) { + return; + } + List operations = javaInterface.getOperations(); + processInterface(javaInterface, operations); + } + + private void introspectWrapperStyle(Operation operation) { + if (operation.isWrapperStyle()) { + return; + } + DataType outputType = operation.getOutputType(); + DataType> inputType = operation.getInputType(); + if (outputType == null || inputType == null) { + return; + } + if (inputType.getLogical().size() != 1) { + return; + } + DataType wrapperType = inputType.getLogical().get(0); + if (outputType.getDataBinding().equals(wrapperType.getDataBinding())) { + operation.setWrapperStyle(true); + operation.setDataBinding(outputType.getDataBinding()); + } + } + + private void processInterface(JavaInterface javaInterface, List operations) { + Class clazz = javaInterface.getJavaClass(); + DataBinding dataBinding = clazz.getAnnotation(DataBinding.class); + String dataBindingId = null; + boolean wrapperStyle = false; + if (dataBinding != null) { + dataBindingId = dataBinding.value(); + wrapperStyle = dataBinding.wrapperStyle(); + } + + Map opMap = new HashMap(); + for (Operation op : javaInterface.getOperations()) { + opMap.put(op.getName(), op); + if (dataBindingId != null) { + op.setDataBinding(dataBindingId); + op.setWrapperStyle(wrapperStyle); + } + } + for (Method method : clazz.getMethods()) { + Operation operation = opMap.get(method.getName()); + DataBinding methodDataBinding = clazz.getAnnotation(DataBinding.class); + if (methodDataBinding == null) { + methodDataBinding = dataBinding; + } + dataBindingId = null; + wrapperStyle = false; + if (dataBinding != null) { + dataBindingId = dataBinding.value(); + wrapperStyle = dataBinding.wrapperStyle(); + operation.setDataBinding(dataBindingId); + operation.setWrapperStyle(wrapperStyle); + } + + // FIXME: We need a better way to identify simple java types + for (org.apache.tuscany.sca.interfacedef.DataType d : operation.getInputType().getLogical()) { + if (d.getDataBinding() == null) { + d.setDataBinding(dataBindingId); + } + dataBindingRegistry.introspectType(d, method.getAnnotations()); + } + if (operation.getOutputType() != null) { + DataType d = operation.getOutputType(); + if (d.getDataBinding() == null) { + d.setDataBinding(dataBindingId); + } + dataBindingRegistry.introspectType(d, method.getAnnotations()); + } + for (org.apache.tuscany.sca.interfacedef.DataType d : operation.getFaultTypes()) { + if (d.getDataBinding() == null) { + d.setDataBinding(dataBindingId); + } + dataBindingRegistry.introspectType(d, method.getAnnotations()); + } + + // FIXME: Do we want to heuristically check the wrapper style? + // introspectWrapperStyle(operation); + } + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core-databinding/src/main/java/org/apache/tuscany/core/databinding/transformers/Exception2ExceptionTransformer.java b/sca-java-1.x/branches/sca-java-0.91/modules/core-databinding/src/main/java/org/apache/tuscany/core/databinding/transformers/Exception2ExceptionTransformer.java new file mode 100644 index 0000000000..9711fe881a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core-databinding/src/main/java/org/apache/tuscany/core/databinding/transformers/Exception2ExceptionTransformer.java @@ -0,0 +1,126 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.core.databinding.transformers; + +import org.apache.tuscany.sca.databinding.DataBinding; +import org.apache.tuscany.sca.databinding.ExceptionHandler; +import org.apache.tuscany.sca.databinding.Mediator; +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.Transformer; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.osoa.sca.annotations.Reference; +import org.osoa.sca.annotations.Service; + +/** + * This is a special transformer to transform the exception from one IDL to the + * other one + */ +@Service(Transformer.class) +public class Exception2ExceptionTransformer extends BaseTransformer implements + PullTransformer { + + protected Mediator mediator; + + public Exception2ExceptionTransformer() { + super(); + } + + @Override + public String getSourceDataBinding() { + return DataBinding.IDL_FAULT; + } + + @Override + public String getTargetDataBinding() { + return DataBinding.IDL_FAULT; + } + + /** + * @param mediator the mediator to set + */ + @Reference + public void setMediator(Mediator mediator) { + this.mediator = mediator; + } + + /** + * @see org.apache.tuscany.sca.databinding.impl.BaseTransformer#getSourceType() + */ + @Override + protected Class getSourceType() { + return Exception.class; + } + + /** + * @see org.apache.tuscany.sca.databinding.impl.BaseTransformer#getTargetType() + */ + @Override + protected Class getTargetType() { + return Exception.class; + } + + /** + * @see org.apache.tuscany.sca.databinding.Transformer#getWeight() + */ + public int getWeight() { + return 10000; + } + + @SuppressWarnings("unchecked") + public Exception transform(Exception source, TransformationContext context) { + DataType sourceType = context.getSourceDataType(); + + DataType targetType = context.getTargetDataType(); + + ExceptionHandler exceptionHandler = getExceptionHandler(sourceType); + if (exceptionHandler == null) { + return source; + } + + Object sourceFaultInfo = exceptionHandler.getFaultInfo(source); + Object targetFaultInfo = + mediator.mediate(sourceFaultInfo, sourceType.getLogical(), targetType.getLogical(), context.getMetadata()); + + ExceptionHandler targetHandler = getExceptionHandler(targetType); + + if (targetHandler != null) { + Exception targetException = + targetHandler.createException(targetType, source.getMessage(), targetFaultInfo, source.getCause()); + return targetException; + } + + // FIXME + return source; + + } + + private ExceptionHandler getExceptionHandler(DataType targetType) { + DataType targetFaultType = (DataType)targetType.getLogical(); + DataBinding targetDataBinding = + mediator.getDataBindings().getDataBinding(targetFaultType.getDataBinding()); + if (targetDataBinding == null) { + return null; + } + ExceptionHandler targetHandler = targetDataBinding.getExceptionHandler(); + return targetHandler; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core-databinding/src/main/java/org/apache/tuscany/core/databinding/transformers/Input2InputTransformer.java b/sca-java-1.x/branches/sca-java-0.91/modules/core-databinding/src/main/java/org/apache/tuscany/core/databinding/transformers/Input2InputTransformer.java new file mode 100644 index 0000000000..88d47deed7 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core-databinding/src/main/java/org/apache/tuscany/core/databinding/transformers/Input2InputTransformer.java @@ -0,0 +1,204 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.core.databinding.transformers; + +import java.util.List; + +import org.apache.tuscany.sca.databinding.DataBinding; +import org.apache.tuscany.sca.databinding.Mediator; +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.Transformer; +import org.apache.tuscany.sca.databinding.WrapperHandler; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; +import org.apache.tuscany.sca.interfacedef.util.ElementInfo; +import org.apache.tuscany.sca.interfacedef.util.WrapperInfo; +import org.apache.tuscany.sca.interfacedef.util.XMLType; +import org.osoa.sca.annotations.Reference; +import org.osoa.sca.annotations.Service; + +/** + * This is a special transformer to transform the input from one IDL to the + * other one + */ +@Service(Transformer.class) +public class Input2InputTransformer extends BaseTransformer implements + PullTransformer { + + protected Mediator mediator; + + public Input2InputTransformer() { + super(); + } + + @Override + public String getSourceDataBinding() { + return DataBinding.IDL_INPUT; + } + + @Override + public String getTargetDataBinding() { + return DataBinding.IDL_INPUT; + } + + /** + * @param mediator the mediator to set + */ + @Reference + public void setMediator(Mediator mediator) { + this.mediator = mediator; + } + + /** + * @see org.apache.tuscany.sca.databinding.impl.BaseTransformer#getSourceType() + */ + @Override + protected Class getSourceType() { + return Object[].class; + } + + /** + * @see org.apache.tuscany.sca.databinding.impl.BaseTransformer#getTargetType() + */ + @Override + protected Class getTargetType() { + return Object[].class; + } + + /** + * @see org.apache.tuscany.sca.databinding.Transformer#getWeight() + */ + public int getWeight() { + return 10000; + } + + @SuppressWarnings("unchecked") + public Object[] transform(Object[] source, TransformationContext context) { + DataType> sourceType = context.getSourceDataType(); + Operation sourceOp = context.getSourceOperation(); + boolean sourceWrapped = sourceOp != null && sourceOp.isWrapperStyle(); + + WrapperHandler sourceWrapperHandler = null; + String sourceDataBinding = getDataBinding(sourceOp); + if (sourceWrapped) { + sourceWrapperHandler = getWrapperHandler(sourceDataBinding, true); + } + + DataType> targetType = context.getTargetDataType(); + Operation targetOp = (Operation)context.getTargetOperation(); + boolean targetWrapped = targetOp != null && targetOp.isWrapperStyle(); + WrapperHandler targetWrapperHandler = null; + String targetDataBinding = null; + if (targetWrapped) { + targetDataBinding = getDataBinding(targetOp); + targetWrapperHandler = getWrapperHandler(targetDataBinding, true); + } + + if ((!sourceWrapped) && targetWrapped) { + // Unwrapped --> Wrapped + WrapperInfo wrapper = targetOp.getWrapper(); + ElementInfo wrapperElement = wrapper.getInputWrapperElement(); + + // If the source can be wrapped, wrapped it first + if (sourceWrapperHandler != null) { + Object sourceWrapper = sourceWrapperHandler.create(wrapperElement, context); + for (int i = 0; i < source.length; i++) { + ElementInfo argElement = wrapper.getInputChildElements().get(i); + sourceWrapperHandler.setChild(sourceWrapper, i, argElement, source[0]); + } + } + Object targetWrapper = targetWrapperHandler.create(wrapperElement, context); + if (source == null) { + return new Object[] {targetWrapper}; + } + List argTypes = wrapper.getUnwrappedInputType().getLogical(); + + for (int i = 0; i < source.length; i++) { + ElementInfo argElement = wrapper.getInputChildElements().get(i); + DataType argType = argTypes.get(i); + Object child = source[i]; + child = mediator.mediate(source[i], sourceType.getLogical().get(i), argType, context.getMetadata()); + targetWrapperHandler.setChild(targetWrapper, i, argElement, child); + } + return new Object[] {targetWrapper}; + } else if (sourceWrapped && (!targetWrapped)) { + // Wrapped to Unwrapped + Object sourceWrapper = source[0]; + // List childElements = + // sourceOp.getWrapper().getInputChildElements(); + Object[] target = null; + + targetDataBinding = getDataBinding(targetOp); + targetWrapperHandler = getWrapperHandler(targetDataBinding, false); + if (targetWrapperHandler != null) { + ElementInfo wrapperElement = sourceOp.getWrapper().getInputWrapperElement(); + // Object targetWrapper = + // targetWrapperHandler.create(wrapperElement, context); + DataType targetWrapperType = new DataTypeImpl(targetDataBinding, Object.class, + new XMLType(wrapperElement)); + Object targetWrapper = mediator.mediate(sourceWrapper, + sourceType.getLogical().get(0), + targetWrapperType, + context.getMetadata()); + target = targetWrapperHandler.getChildren(targetWrapper).toArray(); + } else { + Object[] sourceChildren = sourceWrapperHandler.getChildren(sourceWrapper).toArray(); + target = new Object[sourceChildren.length]; + for (int i = 0; i < sourceChildren.length; i++) { + DataType childType = sourceOp.getWrapper().getUnwrappedInputType().getLogical().get(i); + target[i] = mediator.mediate(sourceChildren[i], childType, targetType.getLogical().get(i), context + .getMetadata()); + } + } + return target; + } else { + // Assuming wrapper to wrapper conversion can be handled here as + // well + Object[] newArgs = new Object[source.length]; + for (int i = 0; i < source.length; i++) { + Object child = mediator.mediate(source[i], sourceType.getLogical().get(i), targetType.getLogical() + .get(i), context.getMetadata()); + newArgs[i] = child; + } + return newArgs; + } + } + + private WrapperHandler getWrapperHandler(String dataBindingId, boolean required) { + WrapperHandler wrapperHandler = null; + if (dataBindingId != null) { + DataBinding dataBinding = mediator.getDataBindings().getDataBinding(dataBindingId); + wrapperHandler = dataBinding == null ? null : dataBinding.getWrapperHandler(); + } + if (wrapperHandler == null && required) { + throw new TransformationException("No wrapper handler is provided for databinding: " + dataBindingId); + } + return wrapperHandler; + } + + private String getDataBinding(Operation operation) { + return operation.getDataBinding(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core-databinding/src/main/java/org/apache/tuscany/core/databinding/transformers/Output2OutputTransformer.java b/sca-java-1.x/branches/sca-java-0.91/modules/core-databinding/src/main/java/org/apache/tuscany/core/databinding/transformers/Output2OutputTransformer.java new file mode 100644 index 0000000000..b1bc8dfe1b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core-databinding/src/main/java/org/apache/tuscany/core/databinding/transformers/Output2OutputTransformer.java @@ -0,0 +1,185 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.core.databinding.transformers; + +import java.util.List; + +import org.apache.tuscany.sca.databinding.DataBinding; +import org.apache.tuscany.sca.databinding.Mediator; +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.Transformer; +import org.apache.tuscany.sca.databinding.WrapperHandler; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; +import org.apache.tuscany.sca.interfacedef.util.ElementInfo; +import org.apache.tuscany.sca.interfacedef.util.WrapperInfo; +import org.apache.tuscany.sca.interfacedef.util.XMLType; +import org.osoa.sca.annotations.Reference; +import org.osoa.sca.annotations.Service; + +/** + * This is a special transformer to transform the output from one IDL to the + * other one + */ +@Service(Transformer.class) +public class Output2OutputTransformer extends BaseTransformer implements + PullTransformer { + + protected Mediator mediator; + + /** + * @param wrapperHandler + */ + public Output2OutputTransformer() { + super(); + } + + /** + * @param mediator the mediator to set + */ + @Reference + public void setMediator(Mediator mediator) { + this.mediator = mediator; + } + + @Override + public String getSourceDataBinding() { + return DataBinding.IDL_OUTPUT; + } + + @Override + public String getTargetDataBinding() { + return DataBinding.IDL_OUTPUT; + } + + /** + * @see org.apache.tuscany.sca.databinding.impl.BaseTransformer#getSourceType() + */ + @Override + protected Class getSourceType() { + return Object.class; + } + + /** + * @see org.apache.tuscany.sca.databinding.impl.BaseTransformer#getTargetType() + */ + @Override + protected Class getTargetType() { + return Object.class; + } + + /** + * @see org.apache.tuscany.sca.databinding.Transformer#getWeight() + */ + public int getWeight() { + return 10; + } + + private String getDataBinding(Operation operation) { + return operation.getDataBinding(); + } + + private WrapperHandler getWrapperHandler(String dataBindingId, boolean required) { + WrapperHandler wrapperHandler = null; + if (dataBindingId != null) { + DataBinding dataBinding = mediator.getDataBindings().getDataBinding(dataBindingId); + wrapperHandler = dataBinding == null ? null : dataBinding.getWrapperHandler(); + } + if (wrapperHandler == null && required) { + throw new TransformationException("No wrapper handler is provided for databinding: " + dataBindingId); + } + return wrapperHandler; + } + + @SuppressWarnings("unchecked") + public Object transform(Object response, TransformationContext context) { + try { + DataType sourceType = context.getSourceDataType(); + Operation sourceOp = context.getSourceOperation(); + boolean sourceWrapped = sourceOp != null && sourceOp.isWrapperStyle(); + WrapperHandler sourceWrapperHandler = null; + if (sourceWrapped) { + sourceWrapperHandler = getWrapperHandler(getDataBinding(sourceOp), true); + } + + DataType targetType = context.getTargetDataType(); + Operation targetOp = context.getTargetOperation(); + boolean targetWrapped = targetOp != null && targetOp.isWrapperStyle(); + WrapperHandler targetWrapperHandler = null; + if (targetWrapped) { + targetWrapperHandler = getWrapperHandler(getDataBinding(targetOp), true); + } + + if ((!sourceWrapped) && targetWrapped) { + // Unwrapped --> Wrapped + WrapperInfo wrapper = targetOp.getWrapper(); + Object targetWrapper = targetWrapperHandler.create(wrapper.getOutputWrapperElement(), context); + + List childElements = wrapper.getOutputChildElements(); + if (childElements.isEmpty()) { + // void output + return targetWrapper; + } + ElementInfo argElement = childElements.get(0); + DataType argType = wrapper.getUnwrappedOutputType(); + Object child = response; + child = mediator.mediate(response, sourceType.getLogical(), argType, context.getMetadata()); + targetWrapperHandler.setChild(targetWrapper, 0, argElement, child); + return targetWrapper; + } else if (sourceWrapped && (!targetWrapped)) { + // Wrapped to Unwrapped + Object sourceWrapper = response; + List childElements = sourceOp.getWrapper().getOutputChildElements(); + if (childElements.isEmpty()) { + // The void output + return null; + } + targetWrapperHandler = getWrapperHandler(getDataBinding(targetOp), false); + if (targetWrapperHandler != null) { + ElementInfo wrapperElement = sourceOp.getWrapper().getOutputWrapperElement(); + // Object targetWrapper = + // targetWrapperHandler.create(wrapperElement, context); + DataType targetWrapperType = new DataTypeImpl(targetType.getLogical() + .getDataBinding(), Object.class, new XMLType(wrapperElement)); + Object targetWrapper = mediator.mediate(sourceWrapper, + sourceType.getLogical(), + targetWrapperType, + context.getMetadata()); + return targetWrapperHandler.getChildren(targetWrapper).get(0); + } else { + Object child = sourceWrapperHandler.getChildren(sourceWrapper).get(0); + DataType childType = sourceOp.getWrapper().getUnwrappedOutputType(); + return mediator.mediate(child, childType, targetType.getLogical(), context.getMetadata()); + } + } else { + // FIXME: Do we want to handle wrapped to wrapped? + return mediator.mediate(response, sourceType.getLogical(), targetType.getLogical(), context + .getMetadata()); + } + } catch (Exception e) { + throw new TransformationException(e); + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core-databinding/src/main/java/org/apache/tuscany/core/databinding/wire/DataBindingRuntimeWireProcessor.java b/sca-java-1.x/branches/sca-java-0.91/modules/core-databinding/src/main/java/org/apache/tuscany/core/databinding/wire/DataBindingRuntimeWireProcessor.java new file mode 100644 index 0000000000..feaf48f501 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core-databinding/src/main/java/org/apache/tuscany/core/databinding/wire/DataBindingRuntimeWireProcessor.java @@ -0,0 +1,150 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.core.databinding.wire; + +import java.util.List; + +import org.apache.tuscany.sca.databinding.Mediator; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.InvocationChain; +import org.apache.tuscany.sca.runtime.RuntimeWire; +import org.apache.tuscany.sca.runtime.RuntimeWireProcessor; + +/** + * This processor is responsible to add an interceptor to invocation chain if + * the source and target operations have different databinding requirements + * + * @version $Rev$ $Date$ + */ +public class DataBindingRuntimeWireProcessor implements RuntimeWireProcessor { + private Mediator mediator; + + public DataBindingRuntimeWireProcessor(Mediator mediator) { + super(); + this.mediator = mediator; + } + + public boolean isTransformationRequired(DataType source, DataType target) { + if (source == target) { + return false; + } + String sourceDataBinding = source.getDataBinding(); + String targetDataBinding = target.getDataBinding(); + if (sourceDataBinding == targetDataBinding) { + return false; + } + if (sourceDataBinding == null || targetDataBinding == null) { + return true; + } + return !sourceDataBinding.equals(targetDataBinding); + } + + public boolean isTransformationRequired(Operation source, Operation target) { + if (source == target) { + return false; + } + + // Check output type + DataType sourceOutputType = source.getOutputType(); + DataType targetOutputType = target.getOutputType(); + + // Note the target output type is now the source for checking + // compatibility + if (isTransformationRequired(targetOutputType, sourceOutputType)) { + return true; + } + + List sourceInputType = source.getInputType().getLogical(); + List targetInputType = target.getInputType().getLogical(); + + int size = sourceInputType.size(); + for (int i = 0; i < size; i++) { + if (isTransformationRequired(sourceInputType.get(i), targetInputType.get(i))) { + return true; + } + } + + return false; + } + + private boolean isTransformationRequired(InterfaceContract sourceContract, + Operation sourceOperation, + InterfaceContract targetContract, + Operation targetOperation) { + if (targetContract == null) { + targetContract = sourceContract; + } + if (sourceContract == targetContract) { + return false; + } + return isTransformationRequired(sourceOperation, targetOperation); + } + + public void process(RuntimeWire wire) { + InterfaceContract sourceContract = wire.getSource().getInterfaceContract(); + InterfaceContract targetContract = wire.getTarget().getInterfaceContract(); + if (targetContract == null) { + targetContract = sourceContract; + } + if (sourceContract == targetContract) { + return; + } + List chains = wire.getInvocationChains(); + for (InvocationChain chain : chains) { + Operation sourceOperation = chain.getSourceOperation(); + Operation targetOperation = chain.getTargetOperation(); + + if (isTransformationRequired(sourceContract, sourceOperation, targetContract, targetOperation)) { + // Add the interceptor to the source side because multiple + // references can be wired + // to the same service + DataTransformationInteceptor interceptor = new DataTransformationInteceptor(wire, sourceOperation, + targetOperation); + interceptor.setMediator(mediator); + chain.addInterceptor(0, interceptor); + } + } + + // Object targetAddress = UriHelper.getBaseName(source.getUri()); + List callbackChains = wire.getCallbackInvocationChains(); + if (callbackChains == null) { + // callback chains could be null + return; + } + + for (InvocationChain chain : callbackChains) { + Operation sourceOperation = chain.getSourceOperation(); + Operation targetOperation = chain.getTargetOperation(); + if (isTransformationRequired(sourceContract, sourceOperation, targetContract, targetOperation)) { + + // Add the interceptor to the source side because multiple + // references can be wired + // to the same service + DataTransformationInteceptor interceptor = new DataTransformationInteceptor(wire, sourceOperation, + targetOperation); + interceptor.setMediator(mediator); + chain.addInterceptor(0, interceptor); + } + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core-databinding/src/main/java/org/apache/tuscany/core/databinding/wire/DataTransformationInteceptor.java b/sca-java-1.x/branches/sca-java-0.91/modules/core-databinding/src/main/java/org/apache/tuscany/core/databinding/wire/DataTransformationInteceptor.java new file mode 100644 index 0000000000..39bc6cf913 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core-databinding/src/main/java/org/apache/tuscany/core/databinding/wire/DataTransformationInteceptor.java @@ -0,0 +1,224 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.core.databinding.wire; + +import java.lang.reflect.InvocationTargetException; +import java.util.HashMap; +import java.util.Map; + +import org.apache.tuscany.sca.databinding.DataBinding; +import org.apache.tuscany.sca.databinding.ExceptionHandler; +import org.apache.tuscany.sca.databinding.Mediator; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; +import org.apache.tuscany.sca.interfacedef.util.FaultException; +import org.apache.tuscany.sca.invocation.Interceptor; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.runtime.RuntimeWire; + +/** + * An interceptor to transform data accross databindings on the wire + * + * @version $Rev$ $Date$ + */ +public class DataTransformationInteceptor implements Interceptor { + private Invoker next; + + private Operation sourceOperation; + + private Operation targetOperation; + + private Mediator mediator; + + public DataTransformationInteceptor(RuntimeWire wire, + Operation sourceOperation, + Operation targetOperation) { + super(); + this.sourceOperation = sourceOperation; + this.targetOperation = targetOperation; + } + + public Invoker getNext() { + return next; + } + + public Message invoke(Message msg) { + Object input = transform(msg.getBody(), sourceOperation.getInputType(), targetOperation.getInputType(), false); + msg.setBody(input); + Message resultMsg = next.invoke(msg); + Object result = resultMsg.getBody(); + if (sourceOperation.isNonBlocking()) { + // Not to reset the message body + return resultMsg; + } + + // FIXME: Should we fix the Operation model so that getOutputType + // returns DataType>? + DataType targetType = + new DataTypeImpl(DataBinding.IDL_OUTPUT, Object.class, targetOperation.getOutputType()); + + DataType sourceType = + new DataTypeImpl(DataBinding.IDL_OUTPUT, Object.class, sourceOperation.getOutputType()); + + if (resultMsg.isFault()) { + + // FIXME: We need to figure out what fault type it is and then + // transform it + // back the source fault type + // throw new InvocationRuntimeException((Throwable) result); + + if ((result instanceof Exception) && !(result instanceof RuntimeException)) { + // FIXME: How to match fault data to a fault type for the + // operation? + + // If the result is from an InvocationTargetException look at + // the actual cause. + if (result instanceof InvocationTargetException) { + result = ((InvocationTargetException)result).getCause(); + } + DataType targetDataType = null; + for (DataType exType : targetOperation.getFaultTypes()) { + if (((Class)exType.getPhysical()).isInstance(result)) { + if (result instanceof FaultException) { + if (((FaultException)result).isMatchingType(exType.getLogical())) { + targetDataType = exType; + break; + } + } else { + targetDataType = exType; + break; + } + } + } + + if (targetDataType == null) { + // Not a business exception + return resultMsg; + } + + DataType targetFaultType = getFaultType(targetDataType); + if (targetFaultType == null) { + throw new TransformationException("Target fault type cannot be resolved"); + } + + // FIXME: How to match a source fault type to a target fault + // type? + DataType sourceDataType = null; + DataType sourceFaultType = null; + for (DataType exType : sourceOperation.getFaultTypes()) { + DataType faultType = getFaultType(exType); + // Match by the QName (XSD element) of the fault type + if (faultType != null && targetFaultType.getLogical().equals(faultType.getLogical())) { + sourceDataType = exType; + sourceFaultType = faultType; + break; + } + } + + if (sourceFaultType == null) { + throw new TransformationException("No matching source fault type is found"); + } + + Object newResult = + transformException(result, targetDataType, sourceDataType, targetFaultType, sourceFaultType); + if (newResult != result) { + resultMsg.setFaultBody(newResult); + } + } + + } else { + assert !(result instanceof Throwable) : "Expected messages that are not throwable " + result; + + Object newResult = transform(result, targetType, sourceType, true); + if (newResult != result) { + resultMsg.setBody(newResult); + } + } + + return resultMsg; + } + + private Object transform(Object source, DataType sourceType, DataType targetType, boolean isResponse) { + if (sourceType == targetType || (sourceType != null && sourceType.equals(targetType))) { + return source; + } + Map metadata = new HashMap(); + metadata.put("source.operation", isResponse? targetOperation: sourceOperation); + metadata.put("target.operation", isResponse? sourceOperation: targetOperation); + return mediator.mediate(source, sourceType, targetType, metadata); + } + + private DataType getFaultType(DataType exceptionType) { + // FIXME: We cannot assume the exception will have a databinding set + DataBinding targetDataBinding = + mediator.getDataBindings().getDataBinding(exceptionType.getDataBinding()); + if (targetDataBinding == null) { + return null; + } + ExceptionHandler targetHandler = targetDataBinding.getExceptionHandler(); + if (targetHandler == null) { + return null; + } + return targetHandler.getFaultType(exceptionType); + } + + /** + * @param source The source exception + * @param sourceExType The data type for the source exception + * @param targetExType The data type for the target exception + * @param sourceType The fault type for the source + * @param targetType The fault type for the target + * @return + */ + private Object transformException(Object source, + DataType sourceExType, + DataType targetExType, + DataType sourceType, + DataType targetType) { + if (sourceType == targetType || (sourceType != null && sourceType.equals(targetType))) { + return source; + } + Map metadata = new HashMap(); + metadata.put("source.operation", targetOperation); + metadata.put("target.operation", sourceOperation); + + DataType eSourceDataType = + new DataTypeImpl("idl:fault", sourceExType.getPhysical(), sourceType); + DataType eTargetDataType = + new DataTypeImpl("idl:fault", targetExType.getPhysical(), targetType); + + return mediator.mediate(source, eSourceDataType, eTargetDataType, metadata); + } + + public void setNext(Invoker next) { + this.next = next; + } + + /** + * @param mediator the mediator to set + */ + public void setMediator(Mediator mediator) { + this.mediator = mediator; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core-databinding/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator b/sca-java-1.x/branches/sca-java-0.91/modules/core-databinding/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator new file mode 100644 index 0000000000..60f6de3b96 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core-databinding/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# Implementation class for the ExtensionActivator +org.apache.tuscany.core.databinding.module.DataBindingModuleActivator diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core-databinding/src/test/java/org/apache/tuscany/core/databinding/processor/DataBindingJavaInterfaceProcessorTestCase.java b/sca-java-1.x/branches/sca-java-0.91/modules/core-databinding/src/test/java/org/apache/tuscany/core/databinding/processor/DataBindingJavaInterfaceProcessorTestCase.java new file mode 100644 index 0000000000..1c521af842 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core-databinding/src/test/java/org/apache/tuscany/core/databinding/processor/DataBindingJavaInterfaceProcessorTestCase.java @@ -0,0 +1,83 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.core.databinding.processor; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint; +import org.apache.tuscany.sca.databinding.DefaultDataBindingExtensionPoint; +import org.apache.tuscany.sca.databinding.annotation.DataBinding; +import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.impl.OperationImpl; +import org.apache.tuscany.sca.interfacedef.java.DefaultJavaInterfaceFactory; +import org.apache.tuscany.sca.interfacedef.java.JavaInterface; +import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceContract; +import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory; +import org.osoa.sca.annotations.Remotable; +import org.w3c.dom.Node; + +/** + * + */ +public class DataBindingJavaInterfaceProcessorTestCase extends TestCase { + + /** + * @see junit.framework.TestCase#setUp() + */ + protected void setUp() throws Exception { + super.setUp(); + } + + /** + * @throws InvalidServiceContractException + */ + public final void testVisitInterface() throws InvalidInterfaceException { + DataBindingExtensionPoint registry = new DefaultDataBindingExtensionPoint(); + DataBindingJavaInterfaceProcessor processor = new DataBindingJavaInterfaceProcessor(registry); + JavaInterfaceFactory javaFactory = new DefaultJavaInterfaceFactory(); + + JavaInterface contract = javaFactory.createJavaInterface(); + contract.setJavaClass(MockInterface.class); + JavaInterfaceContract interfaceContract = javaFactory.createJavaInterfaceContract(); + interfaceContract.setInterface(contract); + Operation operation = new OperationImpl("call"); + Operation operation1 = new OperationImpl("call1"); + contract.getOperations().add(operation); + contract.getOperations().add(operation1); + contract.setRemotable(true); + processor.visitInterface(contract); + // Assert.assertEquals("org.w3c.dom.Node", contract.getDataBinding()); + // Assert.assertEquals("org.w3c.dom.Node", + // contract.getOperations().get("call").getDataBinding()); + // Assert.assertEquals("xml:string", + // contract.getOperations().get("call1").getDataBinding()); + } + + @DataBinding("org.w3c.dom.Node") + @Remotable + public static interface MockInterface { + Node call(Node msg); + + @DataBinding("xml:string") + String call1(String msg); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core-databinding/src/test/java/org/apache/tuscany/core/databinding/transformers/IDLTransformerTestCase.java.fixme b/sca-java-1.x/branches/sca-java-0.91/modules/core-databinding/src/test/java/org/apache/tuscany/core/databinding/transformers/IDLTransformerTestCase.java.fixme new file mode 100644 index 0000000000..ecae54188c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core-databinding/src/test/java/org/apache/tuscany/core/databinding/transformers/IDLTransformerTestCase.java.fixme @@ -0,0 +1,229 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.core.databinding.transformers; + +import static org.apache.tuscany.spi.databinding.DataBinding.IDL_INPUT; +import static org.apache.tuscany.spi.databinding.DataBinding.IDL_OUTPUT; + +import java.util.ArrayList; +import java.util.List; + +import javax.xml.namespace.QName; + +import junit.framework.TestCase; + +import org.apache.tuscany.databinding.impl.DataBindingRegistryImpl; +import org.apache.tuscany.databinding.impl.MediatorImpl; +import org.apache.tuscany.databinding.impl.TransformationContextImpl; +import org.apache.tuscany.databinding.impl.TransformerRegistryImpl; +import org.apache.tuscany.databinding.javabeans.DOMNode2JavaBeanTransformer; +import org.apache.tuscany.databinding.javabeans.JavaBean2DOMNodeTransformer; +import org.apache.tuscany.databinding.xml.DOMDataBinding; +import org.apache.tuscany.databinding.xml.Node2String; +import org.apache.tuscany.databinding.xml.String2Node; +import org.apache.tuscany.interfacedef.DataType; +import org.apache.tuscany.interfacedef.Operation; +import org.apache.tuscany.interfacedef.impl.DataTypeImpl; +import org.apache.tuscany.interfacedef.impl.OperationImpl; +import org.apache.tuscany.interfacedef.util.ElementInfo; +import org.apache.tuscany.interfacedef.util.TypeInfo; +import org.apache.tuscany.interfacedef.util.WrapperInfo; +import org.apache.tuscany.interfacedef.util.XMLType; +import org.apache.tuscany.spi.databinding.DataBindingRegistry; +import org.apache.tuscany.spi.databinding.TransformationContext; +import org.apache.tuscany.spi.databinding.extension.DOMHelper; +import org.apache.tuscany.spi.databinding.extension.SimpleTypeMapperExtension; +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +public class IDLTransformerTestCase extends TestCase { + private static final String IPO_XML = "" + "" + + " " + + " Helen Zoe" + + " 47 Eden Street" + + " Cambridge" + + " CB1 1JR" + + " " + + " " + + " Robert Smith" + + " 8 Oak Avenue" + + " Old Town" + + " PA" + + " 95819" + + " " + + " " + + " " + + " Lapis necklace" + + " 1" + + " 99.95" + + " Want this for the holidays" + + " 1999-12-05" + + " " + + " " + + ""; + + private static final String URI_ORDER_XSD = "http://example.com/order.xsd"; + + /** + * @see junit.framework.TestCase#setUp() + */ + protected void setUp() throws Exception { + super.setUp(); + } + + public void testTransform() throws Exception { + List types0 = new ArrayList(); + DataType wrapperType = new DataTypeImpl(null, Object.class, + new XMLType(new QName(URI_ORDER_XSD, + "checkOrderStatus"), null)); + types0.add(wrapperType); + DataType> inputType0 = new DataTypeImpl>(IDL_INPUT, + Object[].class, types0); + + List types1 = new ArrayList(); + DataType customerIdType = new DataTypeImpl( + null, + Object.class, + new XMLType( + new QName(URI_ORDER_XSD, "customerId"), + null)); + DataType orderType = new DataTypeImpl(null, Object.class, + new XMLType(new QName(URI_ORDER_XSD, "order"), null)); + DataType flagType = new DataTypeImpl(null, Object.class, new XMLType(new QName(URI_ORDER_XSD, + "flag"), null)); + types1.add(customerIdType); + types1.add(orderType); + types1.add(flagType); + + DataType statusType = new DataTypeImpl(null, Object.class, + new XMLType(new QName(URI_ORDER_XSD, "status"), null)); + DataType responseType = new DataTypeImpl(null, Object.class, + new XMLType(new QName(URI_ORDER_XSD, + "checkOrderStatusResponse"), + null)); + + Operation op = new OperationImpl("checkOrderStatus"); + op.setInputType(inputType0); + op.setOutputType(responseType); +// op.setDataBinding(DOMDataBinding.NAME); +// +// inputType0.setOperation(op); + op.setWrapperStyle(true); + ElementInfo inputElement = new ElementInfo(new QName(URI_ORDER_XSD, "checkOrderStatus"), new TypeInfo(null, + false, + null)); +// wrapperType.setMetadata(ElementInfo.class.getName(), inputElement); + + ElementInfo customerId = new ElementInfo(new QName("", "customerId"), + SimpleTypeMapperExtension.XSD_SIMPLE_TYPES.get("string")); + ElementInfo order = new ElementInfo(new QName("", "order"), new TypeInfo(new QName(URI_ORDER_XSD), false, null)); + ElementInfo flag = new ElementInfo(new QName("", "flag"), SimpleTypeMapperExtension.XSD_SIMPLE_TYPES.get("int")); + +// customerIdType.setMetadata(ElementInfo.class.getName(), customerId); +// orderType.setMetadata(ElementInfo.class.getName(), order); +// flagType.setMetadata(ElementInfo.class.getName(), flag); +// +// customerIdType.setOperation(op); +// orderType.setOperation(op); +// flagType.setOperation(op); + + List inputElements = new ArrayList(); + inputElements.add(customerId); + inputElements.add(order); + inputElements.add(flag); + + ElementInfo statusElement = new ElementInfo(new QName("", "status"), SimpleTypeMapperExtension.XSD_SIMPLE_TYPES + .get("string")); + +// statusType.setMetadata(ElementInfo.class.getName(), statusElement); +// statusType.setOperation(op); + + List outputElements = new ArrayList(); + outputElements.add(statusElement); + + ElementInfo outputElement = new ElementInfo(new QName(URI_ORDER_XSD, "checkOrderStatusResponse"), + new TypeInfo(null, false, null)); + +// responseType.setMetadata(ElementInfo.class.getName(), inputElement); +// responseType.setOperation(op); + + WrapperInfo wrapperInfo = new WrapperInfo(DOMDataBinding.NAME, inputElement, outputElement, inputElements, + outputElements); + op.setWrapper(wrapperInfo); +// op.setDataBinding(DOMDataBinding.NAME); + + MediatorImpl m = new MediatorImpl(); + TransformerRegistryImpl tr = new TransformerRegistryImpl(); + tr.registerTransformer(new String2Node()); + tr.registerTransformer(new Node2String()); + tr.registerTransformer(new DOMNode2JavaBeanTransformer()); + tr.registerTransformer(new JavaBean2DOMNodeTransformer()); + m.setTransformerRegistry(tr); + DataBindingRegistry dataBindingRegistry = new DataBindingRegistryImpl(); + dataBindingRegistry.register(new DOMDataBinding()); + m.setDataBindingRegistry(dataBindingRegistry); + + Object[] source = new Object[] {"cust001", IPO_XML, Integer.valueOf(1)}; + Input2InputTransformer t = new Input2InputTransformer(); + t.setMediator(m); + + TransformationContext context = new TransformationContextImpl(); + context.setSourceOperation(op); + List> types = new ArrayList>(); + types.add(new DataTypeImpl(Object.class.getName(), String.class, String.class)); + types.add(new DataTypeImpl("java.lang.String", String.class, String.class)); + types.add(new DataTypeImpl(Object.class.getName(), int.class, int.class)); + DataType>> inputType1 = new DataTypeImpl>>(IDL_INPUT, Object[].class, + types); + context.setSourceDataType(inputType1); + context.setTargetDataType(op.getInputType()); + Object[] results = t.transform(source, context); + assertEquals(1, results.length); + assertTrue(results[0] instanceof Element); + Element element = (Element)results[0]; + assertEquals("http://example.com/order.xsd", element.getNamespaceURI()); + assertEquals("checkOrderStatus", element.getLocalName()); + + TransformationContext context1 = new TransformationContextImpl(); + DataType sourceType = new DataTypeImpl(IDL_OUTPUT, Object.class, op.getOutputType()); + + context1.setSourceDataType(sourceType); + DataType targetType = new DataTypeImpl(IDL_OUTPUT, Object.class, + new DataTypeImpl("java.lang.Object", + String.class, String.class)); + context1.setTargetDataType(targetType); + + Document factory = DOMHelper.newDocument(); + Element responseElement = factory + .createElementNS("http://example.com/order.wsdl", "p:checkOrderStatusResponse"); + Element status = factory.createElement("status"); + responseElement.appendChild(status); + status.appendChild(factory.createTextNode("shipped")); + Output2OutputTransformer t2 = new Output2OutputTransformer(); + t2.setMediator(m); + Object st = t2.transform(responseElement, context1); + assertEquals("shipped", st); + + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/.checkstyle b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/.checkstyle new file mode 100644 index 0000000000..3e57539570 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/.checkstyle @@ -0,0 +1,24 @@ + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/.pmd b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/.pmd new file mode 100644 index 0000000000..4abfdec2b5 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/.pmd @@ -0,0 +1,20 @@ + + +truefalse \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/.ruleset b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/.ruleset new file mode 100644 index 0000000000..3886f07f2d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/.ruleset @@ -0,0 +1,190 @@ + + + + PMD Plugin preferences rule set + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/DISCLAIMER b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/DISCLAIMER new file mode 100644 index 0000000000..d68a410903 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/DISCLAIMER @@ -0,0 +1,8 @@ +Apache Tuscany is an effort undergoing incubation at The Apache Software +Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is +required of all newly accepted projects until a further review indicates that +the infrastructure, communications, and decision making process have stabilized +in a manner consistent with other successful ASF projects. While incubation +status is not necessarily a reflection of the completeness or stability of the +code, it does indicate that the project has yet to be fully endorsed by the ASF. + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/LICENSE b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/NOTICE b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/NOTICE new file mode 100644 index 0000000000..94481d6cfa --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2007 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/pom.xml b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/pom.xml new file mode 100644 index 0000000000..a8981db137 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/pom.xml @@ -0,0 +1,111 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 0.91-incubating-SNAPSHOT + ../pom.xml + + tuscany-core-spi + Apache Tuscany SCA Core SPI + + + + org.apache.tuscany.sca + sca-api + 0.91-incubating-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-assembly + 0.91-incubating-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-policy + 0.91-incubating-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-interface + 0.91-incubating-SNAPSHOT + compile + + + + org.apache.tuscany.sca + tuscany-contribution + 0.91-incubating-SNAPSHOT + + + + stax + stax-api + 1.0.1 + + + + javax.servlet + servlet-api + 2.5 + provided + + + + org.codehaus.woodstox + wstx-asl + 3.2.0 + runtime + + + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + + + package + package + + jar + + + + + true + true + Apache Tuscany is an effort undergoing incubation at the Apache Software Foundation(ASF) and sponsored by the Apache WS PMC. +
Apache Tuscany SCA Core SPI
+
Apache Tuscany SCA Core SPI
+ ${basedir}/src/main/java${path.separator}${basedir}/target/generated/src/main/java +
+
+
+
+ +
diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/doc/Context Model.emx b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/doc/Context Model.emx new file mode 100644 index 0000000000..0445ea5a6b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/doc/Context Model.emx @@ -0,0 +1,673 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + +
+ + + + + + +
+ + + + + + +
+ + + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/core/DefaultExtensionPointRegistry.java b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/core/DefaultExtensionPointRegistry.java new file mode 100644 index 0000000000..7a42300098 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/core/DefaultExtensionPointRegistry.java @@ -0,0 +1,69 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.core; + +import java.util.HashMap; +import java.util.Map; + + +/** + * Default implementation of a registry to hold all the Tuscany core extension + * points. As the point of contact for all extension artifacts this registry + * allows loaded extensions to find all other parts of the system and + * register themselves appropriately. + * + * @version $Rev$ $Date$ + */ +public class DefaultExtensionPointRegistry implements ExtensionPointRegistry { + private Map, Object> extensionPoints = new HashMap, Object>(); + + /** + * Add an extension point to the registry. This default implementation + * stores extensions against the interfaces that they implement. + * @param extensionPoint The instance of the extension point + */ + public void addExtensionPoint(Object extensionPoint) { + Class[] interfaces = extensionPoint.getClass().getInterfaces(); + for (int i = 0; i < interfaces.length; i++) { + extensionPoints.put(interfaces[i], extensionPoint); + } + } + + /** + * Get the extension point by the interface that it implements + * @param extensionPointType The lookup key (extension point interface) + * @return The instance of the extension point + */ + public T getExtensionPoint(Class extensionPointType) { + return extensionPointType.cast(extensionPoints.get(extensionPointType)); + } + + /** + * Remove an extension point based on the interface that it implements + * @param extensionPoint The extension point to remove + */ + public void removeExtensionPoint(Object extensionPoint) { + Class[] interfaces = extensionPoint.getClass().getInterfaces(); + for (int i = 0; i < interfaces.length; i++) { + extensionPoints.remove(interfaces[i]); + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/core/DefaultModelFactoryExtensionPoint.java b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/core/DefaultModelFactoryExtensionPoint.java new file mode 100644 index 0000000000..6765a6c8f1 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/core/DefaultModelFactoryExtensionPoint.java @@ -0,0 +1,67 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.core; + +import java.util.HashMap; + +/** + * Default implementation of a model factory extension point. + * + * @version $Rev$ $Date$ + */ +public class DefaultModelFactoryExtensionPoint implements ModelFactoryExtensionPoint { + + private HashMap, Object> factories = new HashMap, Object>(); + + /** + * Add a model factory extension. + * + * @param factory The factory to add + */ + public void addFactory(Object factory) { + Class[] interfaces = factory.getClass().getInterfaces(); + for (int i = 0; i T getFactory(Class factoryInterface) { + Object factory = factories.get(factoryInterface); + return factoryInterface.cast(factory); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/core/ExtensionPointRegistry.java b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/core/ExtensionPointRegistry.java new file mode 100644 index 0000000000..9609487080 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/core/ExtensionPointRegistry.java @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.core; + + +/** + * The registry for the Tuscany core extension points. As the point of contact + * for all extension artifacts this registry allows loaded extensions to find + * all other parts of the system and register themselves appropriately. + * + * @version $Rev$ $Date$ + */ +public interface ExtensionPointRegistry { + + /** + * Add an extension point to the registry + * @param extensionPoint The instance of the extension point + */ + void addExtensionPoint(Object extensionPoint); + + /** + * Get the extension point by the interface + * @param extensionPointType The lookup key (extension point interface) + * @return The instance of the extension point + */ + T getExtensionPoint(Class extensionPointType); + + /** + * Remove an extension point + * @param extensionPoint The extension point to remove + */ + void removeExtensionPoint(Object extensionPoint); +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/core/ModelFactoryExtensionPoint.java b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/core/ModelFactoryExtensionPoint.java new file mode 100644 index 0000000000..64706c6efc --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/core/ModelFactoryExtensionPoint.java @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.core; + +/** + * An extension point for model factories. Model factories are provided to + * abstract the classes that represent artifacts in the assembly model away + * from their creation mechanism. When the runtime needs to extend the model + * as it reads in contributed artifacts it looks up the factory for the + * artifact required in this registry + * + * @version $Rev$ $Date$ + */ +public interface ModelFactoryExtensionPoint { + + /** + * Add a model factory extension. + * + * @param factory The factory to add + */ + void addFactory(Object factory); + + /** + * Remove a model factory extension. + * + * @param factory The factory to remove + */ + void removeFactory(Object factory); + + /** + * Get a factory implementing the given interface. + * @param factoryInterface the lookup key (factory interface) + * @return The factory + */ + T getFactory(Class factoryInterface); + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/core/ModuleActivator.java b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/core/ModuleActivator.java new file mode 100644 index 0000000000..0244862309 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/core/ModuleActivator.java @@ -0,0 +1,68 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.core; + + +/** + * ModuleActivator represents a module that plugs into the Tuscany system. Each + * module should provide an implementation of this interface and register the + * ModuleActivator implementation class by defining a file named + * + * "META-INF/services/org.apache.tuscany.spi.bootstrp.ModuleActivator" + * + * The content of the file is the class name of the ModuleActivator implementation. + * The implementation class must have a no-arg constructor. The same instance + * will be used to invoke all the methods during different phases of the module + * activation. Note that the start and stop methods defined by this interface + * take a reference to the Tuscany SCA runtime ExtensionPointRegistry. This + * gives the ModuleActivator the oppotunity to add extension points to the + * registry as it is requested to start up and remove them when it is requested + * to shut down. + * + * @version $Rev$ $Date$ + */ +public interface ModuleActivator { + /** + * Get a map of the extension points defined by this module. The key is the + * java interface to represent the extension point and the the value is the + * instance of the implementation of the interface. + * + * @return All the extension points defined by this module + */ + Object[] getExtensionPoints(); + + /** + * This method is invoked when the module is started by the Tuscany system. + * It can be used by this module to registr extensions against extension + * points. + * + * @param registry The extension point registry + */ + void start(ExtensionPointRegistry registry); + + /** + * This method is invoked when the module is stopped by the Tuscany system. + * It can be used by this module to unregister extensions against the + * extension points. + * + * @param registry The extension point registry + */ + void stop(ExtensionPointRegistry registry); +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/event/Event.java b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/event/Event.java new file mode 100644 index 0000000000..6a0c44a404 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/event/Event.java @@ -0,0 +1,33 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.event; + +/** + * The base interface for events that are propagated in the runtime + * + * @version $$Rev$$ $$Date$$ + */ +public interface Event { + + /** + * Returns the source of the event + */ + Object getSource(); + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/event/EventFilter.java b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/event/EventFilter.java new file mode 100644 index 0000000000..c116be921c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/event/EventFilter.java @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.event; + +/** + * Evaluates whether a {@link RuntimeEventListener} is applicable to a given runtime event + * + * @version $$Rev$$ $$Date$$ + */ +public interface EventFilter { + + /** + * Performs the actual evaluation on an event + * @param event Returns true if the event matches implemented criteria + * @return Match result + */ + boolean match(Event event); + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/event/EventPublisher.java b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/event/EventPublisher.java new file mode 100644 index 0000000000..b0debc36c4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/event/EventPublisher.java @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.event; + +/** + * Publishes events in the runtime by accepting {@link Event} objects and + * forwarding them to all registered {@link RuntimeEventListener} objects. + * + * @version $$Rev$$ $$Date$$ + */ +public interface EventPublisher { + + /** + * Publish an event to all regisitered listeners + * @param object The event to publich + */ + void publish(Event object); + + /** + * Registers a listener to receive notifications for the context + * @param listener The listener to add + */ + void addListener(RuntimeEventListener listener); + + /** + * Registers a listener to receive notifications for the context + * @param filter The filter that will be applied before the lister is called + * @param listener The lister to add + */ + void addListener(EventFilter filter, RuntimeEventListener listener); + + + /** + * Removes a previously registered listener + * @param listener The listener to remove + */ + void removeListener(RuntimeEventListener listener); + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/event/RuntimeEventListener.java b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/event/RuntimeEventListener.java new file mode 100644 index 0000000000..b34dceee62 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/event/RuntimeEventListener.java @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.event; + +import java.util.EventListener; + +/** + * Listeners observe events fired in the SCA runtime. + * + * @version $Rev$ $Date$ + */ +public interface RuntimeEventListener extends EventListener { + + /** + * Accepts and event and acts on it + * @param event The event to act on + */ + void onEvent(Event event); +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/event/TrueFilter.java b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/event/TrueFilter.java new file mode 100644 index 0000000000..ca0f4889a5 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/event/TrueFilter.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.event; + +/** + * An event filter that always returns a true condition + * + * @version $$Rev$$ $$Date$$ + */ +public class TrueFilter implements EventFilter { + + /** + * Performs the actual evaluation on an event. Always returns true + * in this case + * @param event The incoming event which is ignored + * @return true + */ + public boolean match(Event event) { + return true; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/Interceptor.java b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/Interceptor.java new file mode 100644 index 0000000000..a5f221fc11 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/Interceptor.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.invocation; + +/** + * Synchronous mediation associated with a client- or target- side wire. + * + * @version $Rev$ $Date$ + */ +public interface Interceptor extends Invoker { + + /** + * Sets the next invoker + * @param next The next invoker + */ + void setNext(Invoker next); + + /** + * Returns the next invoker or null + * @return The next Invoker + */ + Invoker getNext(); + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/InvocationChain.java b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/InvocationChain.java new file mode 100644 index 0000000000..cd75d06ab3 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/InvocationChain.java @@ -0,0 +1,83 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.invocation; + +import org.apache.tuscany.sca.interfacedef.Operation; + +/** + * A wire consists of 1..n invocation chains associated with the operations of its source service contract. + *

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

+ * A Message is used to pass data associated with an invocation through the chain. + * + * @version $Rev$ $Date$ + */ +public interface InvocationChain { + /** + * Returns the target operation for this invocation chain. + * + * @return The target operation for this invocation chain + */ + Operation getTargetOperation(); + + /** + * Returns the source operation for this invocation chain. + * + * @return The source operation for this invocation chain + */ + Operation getSourceOperation(); + + /** + * Adds an interceptor to the chain + * + * @param interceptor The interceptor to add + */ + void addInterceptor(Interceptor interceptor); + + /** + * Adds an invoker to the chain + * + * @param invoker The invoker to add + */ + void addInvoker(Invoker invoker); + + /** + * Returns the first invoker in the chain. + * + * @return The first invoker in the chain + */ + Invoker getHeadInvoker(); + + /** + * Returns the last invoker in the chain. + * + * @return The last invoker in the chain + */ + Invoker getTailInvoker(); + + /** + * Adds an interceptor at the given position in the interceptor stack + * + * @param index The position in the interceptor stack to add the interceptor + * @param interceptor The interceptor to add + */ + void addInterceptor(int index, Interceptor interceptor); + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/Invoker.java b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/Invoker.java new file mode 100644 index 0000000000..2748bbed9a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/Invoker.java @@ -0,0 +1,36 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.invocation; + +/** + * Synchronous mediation associated with a client- or target- side wire. + * + * @version $Rev$ $Date$ + */ +public interface Invoker { + + /** + * Process a synchronous wire + * + * @param msg The request Message for the wire + * @return The response Message from the wire + */ + Message invoke(Message msg); + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/Message.java b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/Message.java new file mode 100644 index 0000000000..ef23118e78 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/Message.java @@ -0,0 +1,132 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.invocation; + +import org.apache.tuscany.sca.interfacedef.ConversationSequence; +import org.apache.tuscany.sca.runtime.EndpointReference; + +/** + * Represents a request, response, or exception flowing through a wire + * + * @version $Rev $Date + */ +public interface Message { + + /** + * Returns the body of the message, which will be the payload or parameters associated with the wire + * @return The body of the message + */ + T getBody(); + + /** + * Sets the body of the message. + * @param body The body of the message + */ + void setBody(T body); + + /** + * Get the conversation id + * @return The conversation ID + */ + String getConversationID(); + + /** + * Set the conversation id + * @param conversationId The conversation ID + */ + void setConversationID(String conversationId); + + /** + * Get the end point reference of the source reference + * @return The end point reference of the reference originating the message + */ + EndpointReference getFrom(); + + /** + * Set the end point reference of the reference originating the message + * @param from The end point reference of the reference originating the message + */ + void setFrom(EndpointReference from); + + /** + * Get the end point reference of target service + * @return The end point reference of the service that the message targets + */ + EndpointReference getTo(); + + /** + * Set the end point reference of target service + * @param to The end point reference of the service that the message targets + */ + void setTo(EndpointReference to); + + /** + * Returns the id of the message + * @return The message Id + */ + Object getMessageID(); + + /** + * Sets the id of the message + * @param messageId The message ID + */ + void setMessageID(Object messageId); + + /** + * Returns the correlation id of the message or null if one is not available. Correlation ids are used by transports + * for message routing. + * @return The correlation Id + */ + Object getCorrelationID(); + + /** + * Sets the correlation id of the message. Correlation ids are used by transports for message routing. + * @param correlationId The correlation Id + */ + void setCorrelationID(Object correlationId); + + /** + * Determines if the message represents a fault/exception + * + * @return true If the message body is a fault object, false if the body is a normal payload + */ + boolean isFault(); + + /** + * Set the message body with a fault object. After this method is called, isFault() returns true. + * + * @param fault The fault object represents an exception + */ + void setFaultBody(T fault); + + /** + * Returns the conversational sequence the message is associated with, NONE, START, CONTINUE, or END on TargetInvoker} + * + * @return The conversational sequence the message is associated with + */ + ConversationSequence getConversationSequence(); + + /** + * Returns the conversational sequence the message is associated with, NONE, START, CONTINUE, or END + * + * @param sequence The conversational sequence + */ + void setConversationSequence(ConversationSequence sequence); + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/MessageFactory.java b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/MessageFactory.java new file mode 100644 index 0000000000..c2a9c488b8 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/MessageFactory.java @@ -0,0 +1,36 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.invocation; + + +/** + * A factory for messages + * + * @version $Rev $Date + */ +public interface MessageFactory { + + /** + * Creates a new message. + * + * @return The new message + */ + Message createMessage(); + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/management/ManagementService.java b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/management/ManagementService.java new file mode 100644 index 0000000000..3626e16425 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/management/ManagementService.java @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.management; + +import org.apache.tuscany.sca.runtime.RuntimeComponent; + +/** + * Interface for the management service abstraction. The implementaion + * could be based on a variety of technologies including JMX, WSDM, + * SNMP etc. + * + * @version $Revision$ $Date$ + */ +public interface ManagementService { + + /** + * Registers a component for management. + * + * @param name Name of the component. + * @param component Component to be registered. + */ + void registerComponent(String name, RuntimeComponent component); +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/BindingProviderFactory.java b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/BindingProviderFactory.java new file mode 100644 index 0000000000..0f6a932c51 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/BindingProviderFactory.java @@ -0,0 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.provider; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + +/** + * A factory for creating the runtime artifacts that represent bindings. + * + * @version $Rev$ $Date$ + */ +public interface BindingProviderFactory extends ProviderFactory { + + /** + * Creates a new reference binding provider for the given component and + * reference. + * + * @param component The runtime component + * @param reference The reference on the runtime component + * @param binding The binding assembly model object + * @return The binding provider + */ + ReferenceBindingProvider createReferenceBindingProvider(RuntimeComponent component, + RuntimeComponentReference reference, + M binding); + + /** + * Creates a new service binding provider for the given component and + * service. + * + * @param component The runtime component + * @param service The service on the runtime component + * @param binding The binding assembly model object + * @return The binding provider + */ + ServiceBindingProvider createServiceBindingProvider(RuntimeComponent component, + RuntimeComponentService service, + M binding); + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/DefaultProviderFactoryExtensionPoint.java b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/DefaultProviderFactoryExtensionPoint.java new file mode 100644 index 0000000000..1adb9287f1 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/DefaultProviderFactoryExtensionPoint.java @@ -0,0 +1,76 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.provider; + +import java.util.HashMap; +import java.util.Map; + +/** + * Default implementation of a provider factory extension point. + * + * @version $Rev$ $Date$ + */ +public class DefaultProviderFactoryExtensionPoint implements ProviderFactoryExtensionPoint { + + protected final Map, ProviderFactory> providerFactories = + new HashMap, ProviderFactory>(); + + /** + * The default constructor. Does nothing. + * + */ + public DefaultProviderFactoryExtensionPoint() { + } + + /** + * Add a provider factory. + * + * @param providerFactory The provider factory + */ + public void addProviderFactory(ProviderFactory providerFactory) { + providerFactories.put(providerFactory.getModelType(), providerFactory); + } + + /** + * Remove a provider factory. + * + * @param providerFactory The provider factory + */ + public void removeProviderFactory(ProviderFactory providerFactory) { + providerFactories.remove(providerFactory.getModelType()); + } + + /** + * Returns the provider factory associated with the given model type. + * @param modelType A model type + * @return The provider factory associated with the given model type + */ + public ProviderFactory getProviderFactory(Class modelType) { + Class[] classes = modelType.getInterfaces(); + for (Class c : classes) { + ProviderFactory factory = providerFactories.get(c); + if (factory != null) { + return factory; + } + } + return providerFactories.get(modelType); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ImplementationProvider.java b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ImplementationProvider.java new file mode 100644 index 0000000000..a680277b99 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ImplementationProvider.java @@ -0,0 +1,68 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.provider; + +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + +/** + * A component implementation can implement this interface in order to tie + * into the Tuscany runtime + * + * @version $Rev$ $Date$ + */ +public interface ImplementationProvider { + + /** + * This method will be invoked when the component implementation + * is activated. + */ + void start(); + + /** + * This method will be invoked when the component implementation + * is deactivated. + */ + void stop(); + + /** + * Create an invoker for the component implementation in the invocation + * chain. The invoker will be responsible for calling the implementation + * logic for the given component. + * + * @param service The component service + * @param operation The operation that the interceptor will handle + * @return An invoker that handles the invocation logic, null should be + * returned if no invoker is required + */ + Invoker createInvoker(RuntimeComponentService service, Operation operation); + + /** + * Create an invoker to call back to the given component + * @param operation The operation + * @return An invoker that handles the invocation logic, null should be + * returned if no invoker is required + */ + Invoker createCallbackInvoker(Operation operation); + + // InterfaceContract getImplementationInterfaceContract(RuntimeComponentService service); + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ImplementationProviderFactory.java b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ImplementationProviderFactory.java new file mode 100644 index 0000000000..6a37d1e951 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ImplementationProviderFactory.java @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.provider; + +import org.apache.tuscany.sca.assembly.Implementation; +import org.apache.tuscany.sca.runtime.RuntimeComponent; + +/** + * An interface for factories that create implementation providers. + * + * @version $Rev$ $Date$ + */ +public interface ImplementationProviderFactory extends ProviderFactory { + + /** + * Creates a new implementation provider for the given + * component. + * + * @param component The runtime component + * @param Implementation The implementation type + * @return The implementation provider + */ + ImplementationProvider createImplementationProvider(RuntimeComponent component, M Implementation); + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ProviderFactory.java b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ProviderFactory.java new file mode 100644 index 0000000000..2102806881 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ProviderFactory.java @@ -0,0 +1,36 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.provider; + +/** + * A factory for runtime providers. + * + * @version $Rev$ $Date$ + */ +public interface ProviderFactory { + + /** + * The model type that this factory creates providers for. + * + * @return the model type + */ + Class getModelType(); + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ProviderFactoryExtensionPoint.java b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ProviderFactoryExtensionPoint.java new file mode 100644 index 0000000000..5e781dd5b3 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ProviderFactoryExtensionPoint.java @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.provider; + + +/** + * An extension point for provider factories. Holds all of the provider + * factories from loaded extension points. Allows a provider factory + * to be located based on a given model type. Hence the runtime can + * generate runtime artifacts from the in memory assembly model. + * + * @version $Rev$ $Date$ + */ +public interface ProviderFactoryExtensionPoint { + + + /** + * Add a provider factory. + * + * @param providerFactory The provider factory + */ + void addProviderFactory(ProviderFactory providerFactory); + + /** + * Remove a provider factory. + * + * @param providerFactory The provider factory + */ + void removeProviderFactory(ProviderFactory providerFactory); + + /** + * Returns the provider factory associated with the given model type. + * @param modelType A model type + * @return The provider factory associated with the given model type + */ + ProviderFactory getProviderFactory(Class modelType); + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ReferenceBindingProvider.java b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ReferenceBindingProvider.java new file mode 100644 index 0000000000..4da4108168 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ReferenceBindingProvider.java @@ -0,0 +1,68 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.provider; + +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Invoker; + +/** + * A reference binding implementation can options implement this + * interface to tie into the Tuscany SCA runtime + * + * @version $Rev$ $Date$ + */ +public interface ReferenceBindingProvider { + + /** + * This method will be invoked when the component reference binding is + * activated. + */ + void start(); + + /** + * This method will be invoked when the component reference binding is + * deactivated. + */ + void stop(); + + /** + * Create an invoker for the reference binding in the invocation chain. The + * invoker is responsible for making the outbound invocation over the + * binding protocol. + * + * @param operation The operation that the interceptor will handle + * @param isCallback A flag to tell if the operation is for the callback + * @return An invoker that handles the invocation logic, null should be + * returned if no invoker is required + */ + Invoker createInvoker(Operation operation, boolean isCallback); + + /** + * Get the effective interface contract imposed by the binding. For example, + * it will be interface contract introspected from the WSDL portType used by + * the endpoint for a WebService binding. + * + * @return The effective interface contract, if null is returned, the + * interface contract for the component reference will be used + */ + InterfaceContract getBindingInterfaceContract(); + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ServiceBindingProvider.java b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ServiceBindingProvider.java new file mode 100644 index 0000000000..d2646d8d00 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ServiceBindingProvider.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.provider; + +import org.apache.tuscany.sca.interfacedef.InterfaceContract; + +/** + * A service binding can optionally implement this interface to tie + * into the Tuscany SCA runtime + * + * @version $Rev$ $Date$ + */ +public interface ServiceBindingProvider { + /** + * This method will be invoked when the component service binding is + * activated. + */ + void start(); + + /** + * This method will be invoked when the component service binding is + * deactivated. + */ + void stop(); + + /** + * Get the effective interface contract imposed by the binding. For example, + * it will be interface contract introspected from the WSDL portType used by + * the endpoint for a WebService binding. + * + * @return The effective interface contract, if null is returned, the + * interface contract for the component service will be used + */ + InterfaceContract getBindingInterfaceContract(); +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/DefaultWireProcessorExtensionPoint.java b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/DefaultWireProcessorExtensionPoint.java new file mode 100644 index 0000000000..851afee3c1 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/DefaultWireProcessorExtensionPoint.java @@ -0,0 +1,63 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.runtime; + +import java.util.ArrayList; +import java.util.List; + + +/** + * The default implementation of a WireProcessorExtensionPoint + * + * @version $Rev$ $Date$ + */ +public class DefaultWireProcessorExtensionPoint implements RuntimeWireProcessorExtensionPoint { + + /** + * The list of WireProcessors available to the runtime + */ + private final List processors = new ArrayList(); + + /** + * Registers a wire-processor in the runtime + * + * @param processor The processor to register + */ + public void addWireProcessor(RuntimeWireProcessor processor) { + processors.add(processor); + } + + /** + * De-registers a wire-processor in the runtime + * + * @param processor The processor to de-register + */ + public void removeWireProcessor(RuntimeWireProcessor processor) { + processors.remove(processor); + } + + /** + * Returns a list of registered wire-processors. + * + * @return The list of wire processors + */ + public List getWireProcessors() { + return processors; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/EndpointReference.java b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/EndpointReference.java new file mode 100644 index 0000000000..627180b2d1 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/EndpointReference.java @@ -0,0 +1,64 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.runtime; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.Contract; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; + +/** + * The endpoint reference for a component service or reference + * + * @version $Rev$ $Date$ + */ +public interface EndpointReference { + /** + * Get the component for the endpoint + * @return The component, null of the EPR is for a non-SCA service + */ + RuntimeComponent getComponent(); + + /** + * Get the component service or reference for the endpoint + * @return The component service or reference, null if the EPR is for a non-SCA service + */ + Contract getContract(); + + /** + * Get the binding for the endpoint + * @return The binding + */ + Binding getBinding(); + + //FIXME Why do we need this? isn't the interface contract already on the Contract? + + /** + * Get the interface contract for the endpoint + * @return The interface contract + */ + InterfaceContract getInterfaceContract(); + + /** + * Get the URI for this endpoint + * @return The URI of the endpoint + */ + String getURI(); + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponent.java b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponent.java new file mode 100644 index 0000000000..ddb5ae746c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponent.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.runtime; + +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.provider.ImplementationProvider; +import org.osoa.sca.ComponentContext; + +/** + * The runtime component interface. Provides the bridge between the + * assembly model representation of a component and its runtime + * realization. + * + * @version $Rev$ $Date$ + */ +public interface RuntimeComponent extends Component, ComponentContext { + /** + * Set the implementation-specific configuration for this component + * @param implementationProvider The object that manages the component implementation + */ + void setImplementationProvider(ImplementationProvider implementationProvider); + + /** + * Get the implementation-specific configuation for this component + * @return The implementation provider for this component + */ + ImplementationProvider getImplementationProvider(); +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponentReference.java b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponentReference.java new file mode 100644 index 0000000000..18166d8c1d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponentReference.java @@ -0,0 +1,80 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.runtime; + +import java.util.List; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.ComponentReference; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.provider.ReferenceBindingProvider; + +/** + * The runtime component reference. Provides the bridge between the + * assembly model representation of a component reference and its runtime + * realization + * + * @version $Rev$ $Date$ + */ +public interface RuntimeComponentReference extends ComponentReference { + + /** + * Get a list of runtime wires to the reference + * + * @return The list of wires + */ + List getRuntimeWires(); + + /** + * Get the runtime wire for the given binding + * @param binding The assembly model binding + * @return The runtime wire + */ + RuntimeWire getRuntimeWire(Binding binding); + + /** + * Returns the reference binding provider associated with this + * component reference and the given binding. + * + * @param binding The assembly model binding + * @return The runtime reference binding provider + */ + ReferenceBindingProvider getBindingProvider(Binding binding); + + /** + * Sets the reference binding provider associated with this + * component reference and the given binding. + * + * @param binding The assembly model binding + * @param bindingProvider The runtime reference binding provider + */ + void setBindingProvider(Binding binding, ReferenceBindingProvider bindingProvider); + + + /** + * Get the invoker for the given binding and operation + * @param binding The assembly model binding + * @param operation The assembly model operation + * @return The runtime Invoker + */ + Invoker getInvoker(Binding binding, Operation operation); + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponentService.java b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponentService.java new file mode 100644 index 0000000000..19327321a6 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponentService.java @@ -0,0 +1,92 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.runtime; + +import java.util.List; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.ComponentService; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.provider.ServiceBindingProvider; + +/** + * The runtime component service. Provides the bridge between the + * assembly model representation of a component service and its runtime + * realization + * + * @version $Rev$ $Date$ + */ +public interface RuntimeComponentService extends ComponentService { + + /** + * Get a list of runtime wires to the service + * + * @return The list of wires + */ + List getRuntimeWires(); + /** + * Get the runtime wire for the given binding + * @param binding The assembly model binding + * @return The runtime wire + */ + RuntimeWire getRuntimeWire(Binding binding); + + /** + * Get the callback wires assoicated with this service + * + * @return The list of runtime callback wires + */ + List getCallbackWires(); + + /** + * Returns the service binding provider associated with this + * component service and the given binding. + * + * @param binding The assembly model binding + * @return The runtime service binding provider + */ + ServiceBindingProvider getBindingProvider(Binding binding); + + /** + * Sets the service binding provider associated with this + * component service and the given binding. + * + * @param binding The assembly model binding + * @param bindingProvider The runtime service binding provider + */ + void setBindingProvider(Binding binding, ServiceBindingProvider bindingProvider); + + /** + * Get the invoker for the given binding and operation + * @param binding The assembly model binding + * @param operation The assembly model operation + * @return The runtime invoker + */ + Invoker getInvoker(Binding binding, Operation operation); + + /** + * Get the callback invoker for the given binding and operation + * @param binding The assembly model binding + * @param operation The assembly model operation + * @return The runtime callback invoker + */ + Invoker getCallbackInvoker(Binding binding, Operation operation); +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeWire.java b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeWire.java new file mode 100644 index 0000000000..d6b56d822e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeWire.java @@ -0,0 +1,66 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.runtime; + +import java.util.List; + +import org.apache.tuscany.sca.invocation.InvocationChain; + +/** + * The runtime wire interface that connects a component reference to a + * component service (or an external service) over the selected binding + * + * @version $Rev$ $Date$ + */ +public interface RuntimeWire { + + /** + * Get the source of the wire + * + * @return The end point reference of the source + */ + EndpointReference getSource(); + + /** + * Get the target of the wire + * + * @return The end point reference of the target + */ + EndpointReference getTarget(); + + /** + * Returns the invocation chains for service operations associated with the + * wire + * + * @return the invocation chains for service operations associated with the + * wire + */ + List getInvocationChains(); + + /** + * Returns the invocation chains for callback service operations associated + * with the wire + * + * @return the invocation chains for callback service operations associated + * with the wire + */ + List getCallbackInvocationChains(); + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeWireProcessor.java b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeWireProcessor.java new file mode 100644 index 0000000000..fbb7aae467 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeWireProcessor.java @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.runtime; + +/** + * Implementations are called after wires are decorated with policy and before they are connected. + * + * @version $Rev$ $Date$ + */ +public interface RuntimeWireProcessor { + + /** + * Process the runtime wire to add interceptors + * + * @param wire + */ + void process(RuntimeWire wire); + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeWireProcessorExtensionPoint.java b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeWireProcessorExtensionPoint.java new file mode 100644 index 0000000000..4b2c71b397 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeWireProcessorExtensionPoint.java @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.runtime; + +import java.util.List; + +/** + * Acts as a delegating WireProcessorExtensionPoint, delegating + * processing of wires after policies have been applied and source and targets + * have been connected. + * + * @version $Rev$ $Date$ + */ +public interface RuntimeWireProcessorExtensionPoint { + + /** + * Registers a wire-processor in the runtime + * + * @param processor The processor to register + */ + void addWireProcessor(RuntimeWireProcessor processor); + + /** + * De-registers a wire-processor in the runtime + * + * @param processor The processor to de-register + */ + void removeWireProcessor(RuntimeWireProcessor processor); + + /** + * Returns a list of registered wire-processors. + * + * @return The list of wire processors + */ + List getWireProcessors(); + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/DuplicateRecordException.java b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/DuplicateRecordException.java new file mode 100644 index 0000000000..3cf82982dc --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/DuplicateRecordException.java @@ -0,0 +1,45 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.store; + +/** + * thrown when a record already exists during an insert operation + * + * @version $Rev$ $Date$ + */ +public class DuplicateRecordException extends StoreWriteException { + private static final long serialVersionUID = 3116253222569378447L; + + public DuplicateRecordException() { + super(); + } + + public DuplicateRecordException(String message, Throwable cause) { + super(message, cause); + } + + public DuplicateRecordException(String message) { + super(message); + } + + public DuplicateRecordException(Throwable cause) { + super(cause); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/RecoveryListener.java b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/RecoveryListener.java new file mode 100644 index 0000000000..9d965a3369 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/RecoveryListener.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.store; + +import java.util.UUID; + +/** + * Implementations receive callback events during a store recovery operation + * + * @version $Rev$ $Date$ + */ +public interface RecoveryListener { + + /** + * Signals the start of a recovery + */ + void onBegin(); + + /** + * Received when a record is recovered + * + * @param id + */ + void onRecord(UUID id); + + /** + * Signals the end of recovery + */ + void onEnd(); +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/Store.java b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/Store.java new file mode 100644 index 0000000000..b15cde066a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/Store.java @@ -0,0 +1,96 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.store; + +import org.apache.tuscany.sca.event.EventPublisher; +import org.apache.tuscany.sca.runtime.RuntimeComponent; + +/** + * Implementations provide a persistent store for runtime data such as conversational state. A persistent store could be + * implemented in a durable fashion using JDBC or a journaling system, or using a non-durable mechanism such as an + * in-memory map. + * + * @version $Rev$ $Date$ + */ +public interface Store extends EventPublisher { + + /* Used to indicate an the default expiration offset for records for the store */ + long DEFAULT_EXPIRATION_OFFSET = -1; + + /* Used to indicate an entry should not expire */ + long NEVER = -2; + + /** + * Adds the given record to the store. Implementations may choose different strategies for writing data such as + * write-through or write-behind. + * + * @param owner the instance owner + * @param id the unique id of the record + * @param object the object representing the data to write + * @param expiration the time in milliseconds when the entry expires + * @throws StoreWriteException if an error occurs during the write operation + */ + void insertRecord(RuntimeComponent owner, String id, Object object, long expiration) throws StoreWriteException; + + /** + * Updates a given record in the store, overwriting previous information. + * + * @param owner the instance owner + * @param id the unique id of the record + * @param object the object representing the data to write + * @param expiration the time in milliseconds when the entry expires + * @throws StoreWriteException + */ + void updateRecord(RuntimeComponent owner, String id, Object object, long expiration) throws StoreWriteException; + + /** + * Returns the deserialized object in the store corresponding to the given id + * + * @param owner the instance owner + * @param id the unique id of the record + * @return the deserialized object or null if one is not found + * @throws StoreReadException + */ + Object readRecord(RuntimeComponent owner, String id) throws StoreReadException; + + /** + * Removes a record from the store + * + * @param owner the instance owner + * @param id the unique id of the record + * @throws StoreWriteException + */ + void removeRecord(RuntimeComponent owner, String id) throws StoreWriteException; + + /** + * Removes all records from the store + * + * @throws StoreWriteException + */ + void removeRecords() throws StoreWriteException; + + /** + * Initiates a recovery operation, for example during restart after a crash + * + * @param listener the listener to receive recovery callback events + * @throws StoreReadException + */ + void recover(RecoveryListener listener) throws StoreReadException; + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/StoreException.java b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/StoreException.java new file mode 100644 index 0000000000..647eba33aa --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/StoreException.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.store; + + +/** + * Represents a generic exception thrown by a Store + * + * @version $Rev$ $Date$ + */ +public class StoreException extends Exception { + private static final long serialVersionUID = -319152147419962709L; + + public StoreException() { + super(); + } + + public StoreException(String message, Throwable cause) { + super(message, cause); + } + + public StoreException(String message) { + super(message); + } + + public StoreException(Throwable cause) { + super(cause); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/StoreExpirationEvent.java b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/StoreExpirationEvent.java new file mode 100644 index 0000000000..5c1a3ca79d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/StoreExpirationEvent.java @@ -0,0 +1,71 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.store; + +import org.apache.tuscany.sca.event.Event; +import org.apache.tuscany.sca.runtime.RuntimeComponent; + +/** + * Fired when a store implementation expires a resource + * + * @version $Rev$ $Date$ + */ +public class StoreExpirationEvent implements Event { + private Object source; + private RuntimeComponent owner; + private Object instance; + + /** + * Constructor. + * + * @param source the source of the event + * @param owner the owner of the expiring object + * @param instance the expiring object + */ + public StoreExpirationEvent(Object source, RuntimeComponent owner, Object instance) { + assert source != null; + assert owner != null; + assert instance != null; + this.source = source; + this.owner = owner; + this.instance = instance; + } + + public Object getSource() { + return source; + } + + /** + * Returns the owner of the expiring object. + * + * @return the owner of the expiring object. + */ + public RuntimeComponent getOwner() { + return owner; + } + + /** + * Returns the expiring object. + * + * @return the expiring object. + */ + public Object getInstance() { + return instance; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/StoreMonitor.java b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/StoreMonitor.java new file mode 100644 index 0000000000..66bbae684d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/StoreMonitor.java @@ -0,0 +1,71 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.store; + + +/** + * A generic monintor interface for services to log events + * + * @version $Rev$ $Date$ + */ +public interface StoreMonitor { + + /** + * Signals the service has started + * + * @param msg + */ + void start(String msg); + + /** + * Signals the service has been shutdown + * + * @param msg + */ + void stop(String msg); + + /** + * Fired when recovery is started + */ + + void beginRecover(); + + /** + * Fired when recovery is completed + */ + + void endRecover(); + + /** + * Fired when a record is processed during recovery + * + * @param recordId the id of the record being recovered + */ + + void recover(Object recordId); + + /** + * Signals an error event + * + * @param e the error + */ + + void error(Throwable e); + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/StoreReadException.java b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/StoreReadException.java new file mode 100644 index 0000000000..3a563b9fb5 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/StoreReadException.java @@ -0,0 +1,45 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.store; + +/** + * Thrown when an error occurs reading from persistent storage + * + * @version $Rev$ $Date$ + */ +public class StoreReadException extends StoreException { + private static final long serialVersionUID = -8624542082121467271L; + + public StoreReadException() { + super(); + } + + public StoreReadException(String message, Throwable cause) { + super(message, cause); + } + + public StoreReadException(String message) { + super(message); + } + + public StoreReadException(Throwable cause) { + super(cause); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/StoreWriteException.java b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/StoreWriteException.java new file mode 100644 index 0000000000..ad55ce386b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/StoreWriteException.java @@ -0,0 +1,45 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.store; + +/** + * Thrown when an error occurs writing to persistent storage + * + * @version $Rev$ $Date$ + */ +public class StoreWriteException extends StoreException { + private static final long serialVersionUID = 5539070473942048555L; + + public StoreWriteException() { + super(); + } + + public StoreWriteException(String message, Throwable cause) { + super(message, cause); + } + + public StoreWriteException(String message) { + super(message); + } + + public StoreWriteException(Throwable cause) { + super(cause); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/work/NotificationListener.java b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/work/NotificationListener.java new file mode 100644 index 0000000000..5701a04ed1 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/work/NotificationListener.java @@ -0,0 +1,66 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.work; + +/** + * A callback inyterface that can be optionally used for registering + * interest in status of asynchronously scheduled unit of work. + * + */ +public interface NotificationListener { + + /** + * Callback method when the unit of work is accepted. + * + * @param work Work that was accepted. + */ + void workAccepted(T work); + + /** + * Callback method when the unit of work is successfully completed. + * + * @param work Work that was succesfully completed. + */ + void workCompleted(T work); + + /** + * Callback when the unit of work is started. + * + * @param work Unit of work that was started. + */ + void workStarted(T work); + + /** + * Callback when the unit of work is rejected. + * + * @param work Unit of work that was rejected. + */ + void workRejected(T work); + + /** + * Callnack when the unit of work fails to complete. + * + * @param work Unit of work that failed to complete. + * @param error Error that caused the unit of work to fail. + */ + void workFailed(T work, Throwable error); + + + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/work/WorkScheduler.java b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/work/WorkScheduler.java new file mode 100644 index 0000000000..99cb601107 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/work/WorkScheduler.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.work; + +/** + * Defines the contract for scheduling asychronous units of work. + * + *

+ * Units of work can be scheduled with an optional NotificationListener. + * If a notification listener is specified, the caller will be notified regarding the + * status of the work. The unit of work can either be completed, rejected or completed + * with an error. If the work completed with an error, the caller is notfied with the + * error details. + *

+ * + */ +public interface WorkScheduler { + + /** + * Schedules a unit of work for future execution. The notification listener + * is used to register interest in callbacks regarding the status of the work. + * + * @param work The unit of work that needs to be asynchronously executed. + * @param listener Notification listener for callbacks. + */ + void scheduleWork(T work, NotificationListener listener); + + /** + * Schedules a unit of work for future execution. The notification listener + * is used to register interest in callbacks regarding the status of the work. + * + * @param work The unit of work that needs to be asynchronously executed. + */ + void scheduleWork(T work); + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/work/WorkSchedulerException.java b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/work/WorkSchedulerException.java new file mode 100644 index 0000000000..f3d32e376b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/main/java/org/apache/tuscany/sca/work/WorkSchedulerException.java @@ -0,0 +1,47 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.work; + + +/** + * Exception thrown by the work scheduler in case of unexpected exceptions. + * + * @version $Rev$ $Date$ + * + */ +@SuppressWarnings("serial") +public class WorkSchedulerException extends RuntimeException { + + public WorkSchedulerException() { + super(); + } + + public WorkSchedulerException(String message, Throwable cause) { + super(message, cause); + } + + public WorkSchedulerException(String message) { + super(message); + } + + public WorkSchedulerException(Throwable cause) { + super(cause); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/test/resources/org/apache/tuscany/spi/util/stax/test.composite b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/test/resources/org/apache/tuscany/spi/util/stax/test.composite new file mode 100644 index 0000000000..337ec02f06 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core-spi/src/test/resources/org/apache/tuscany/spi/util/stax/test.composite @@ -0,0 +1,34 @@ + + + + + + + + 123 + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core-spring/DISCLAIMER b/sca-java-1.x/branches/sca-java-0.91/modules/core-spring/DISCLAIMER new file mode 100644 index 0000000000..d68a410903 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core-spring/DISCLAIMER @@ -0,0 +1,8 @@ +Apache Tuscany is an effort undergoing incubation at The Apache Software +Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is +required of all newly accepted projects until a further review indicates that +the infrastructure, communications, and decision making process have stabilized +in a manner consistent with other successful ASF projects. While incubation +status is not necessarily a reflection of the completeness or stability of the +code, it does indicate that the project has yet to be fully endorsed by the ASF. + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core-spring/LICENSE b/sca-java-1.x/branches/sca-java-0.91/modules/core-spring/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/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/sca-java-1.x/branches/sca-java-0.91/modules/core-spring/NOTICE b/sca-java-1.x/branches/sca-java-0.91/modules/core-spring/NOTICE new file mode 100644 index 0000000000..94481d6cfa --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core-spring/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2007 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core-spring/pom.xml b/sca-java-1.x/branches/sca-java-0.91/modules/core-spring/pom.xml new file mode 100644 index 0000000000..25c9eb8634 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core-spring/pom.xml @@ -0,0 +1,94 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 0.91-incubating-SNAPSHOT + ../pom.xml + + tuscany-core-spring + Apache Tuscany SCA Spring-based Core Runtime + + + + + org.apache.tuscany.sca + tuscany-assembly + 0.91-incubating-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-interface-java + 0.91-incubating-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-implementation-java + 0.91-incubating-SNAPSHOT + + + + org.springframework + spring-core + 2.0.3 + + + + org.springframework + spring-beans + 2.0.3 + + + + org.springframework + spring-context + 2.0.3 + + + + org.apache.tuscany.sca + sca-api + 0.91-incubating-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-assembly-xml + 0.91-incubating-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-interface-java-xml + 0.91-incubating-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-implementation-java-xml + 0.91-incubating-SNAPSHOT + + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/assembly/impl/BeanAssemblyFactory.java b/sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/assembly/impl/BeanAssemblyFactory.java new file mode 100644 index 0000000000..5b04d9e363 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/assembly/impl/BeanAssemblyFactory.java @@ -0,0 +1,135 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.spring.assembly.impl; + +import org.apache.tuscany.sca.assembly.AbstractProperty; +import org.apache.tuscany.sca.assembly.AbstractReference; +import org.apache.tuscany.sca.assembly.AbstractService; +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.Callback; +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.ComponentProperty; +import org.apache.tuscany.sca.assembly.ComponentReference; +import org.apache.tuscany.sca.assembly.ComponentService; +import org.apache.tuscany.sca.assembly.ComponentType; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.CompositeReference; +import org.apache.tuscany.sca.assembly.CompositeService; +import org.apache.tuscany.sca.assembly.ConstrainingType; +import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory; +import org.apache.tuscany.sca.assembly.Property; +import org.apache.tuscany.sca.assembly.Reference; +import org.apache.tuscany.sca.assembly.SCABinding; +import org.apache.tuscany.sca.assembly.Service; +import org.apache.tuscany.sca.assembly.Wire; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.springframework.beans.factory.support.BeanDefinitionRegistry; + +/** + * An alternate implementation of the SCA assembly model factory that creates SCA + * assembly model objects backed by Spring bean definitions. + * + * @version $Rev$ $Date$ + */ +public class BeanAssemblyFactory implements AssemblyFactory { + + private AssemblyFactory defaultFactory; + private BeanDefinitionRegistry beanRegistry; + + public BeanAssemblyFactory(AssemblyFactory defaultFactory, BeanDefinitionRegistry beanRegistry) { + this.defaultFactory = defaultFactory; + this.beanRegistry = beanRegistry; + } + + public BeanAssemblyFactory(BeanDefinitionRegistry beanRegistry) { + this(new DefaultAssemblyFactory(), beanRegistry); + } + + public AbstractProperty createAbstractProperty() { + return defaultFactory.createAbstractProperty(); + } + + public AbstractReference createAbstractReference() { + return defaultFactory.createAbstractReference(); + } + + public AbstractService createAbstractService() { + return defaultFactory.createAbstractService(); + } + + public Callback createCallback() { + return defaultFactory.createCallback(); + } + + public Component createComponent() { + return new BeanComponentImpl(beanRegistry); + } + + public ComponentProperty createComponentProperty() { + return defaultFactory.createComponentProperty(); + } + + public ComponentReference createComponentReference() { + return defaultFactory.createComponentReference(); + } + + public ComponentService createComponentService() { + return defaultFactory.createComponentService(); + } + + public ComponentType createComponentType() { + return defaultFactory.createComponentType(); + } + + public Composite createComposite() { + return defaultFactory.createComposite(); + } + + public CompositeReference createCompositeReference() { + return defaultFactory.createCompositeReference(); + } + + public CompositeService createCompositeService() { + return defaultFactory.createCompositeService(); + } + + public ConstrainingType createConstrainingType() { + return defaultFactory.createConstrainingType(); + } + + public Property createProperty() { + return defaultFactory.createProperty(); + } + + public Reference createReference() { + return defaultFactory.createReference(); + } + + public Service createService() { + return defaultFactory.createService(); + } + + public Wire createWire() { + return defaultFactory.createWire(); + } + + public Operation createOperation() { + return defaultFactory.createOperation(); + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/assembly/impl/BeanComponentImpl.java b/sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/assembly/impl/BeanComponentImpl.java new file mode 100644 index 0000000000..85c5e7ec43 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/assembly/impl/BeanComponentImpl.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.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.assembly.Visitor; +import org.apache.tuscany.sca.policy.Intent; +import org.apache.tuscany.sca.policy.PolicySet; +import org.springframework.beans.factory.support.BeanDefinitionRegistry; +import org.springframework.beans.factory.support.ChildBeanDefinition; + +/** + * An implementation of the SCA assembly Component interface backed by a Spring + * Bean definition. + * + * @version $Rev$ $Date$ + */ +public class BeanComponentImpl extends ChildBeanDefinition implements Component, Cloneable { + private static final long serialVersionUID = 1L; + + private ConstrainingType constrainingType; + private Implementation implementation; + private String name; + private String uri; + private List services = new ArrayList(); + private List requiredIntents = new ArrayList(); + private List policySets = new ArrayList(); + private List extensions = new ArrayList(); + private boolean unresolved = false; + private BeanDefinitionRegistry beanRegistry; + + protected BeanComponentImpl(BeanDefinitionRegistry beanRegistry) { + super((String)""); + this.beanRegistry = beanRegistry; + } + + @Override + public Object clone() throws CloneNotSupportedException { + BeanComponentImpl clone = (BeanComponentImpl)super.clone(); + + clone.getProperties().clear(); + for (ComponentProperty property: getProperties()) { + clone.getProperties().add((ComponentProperty)property.clone()); + } + clone.getReferences().clear(); + for (ComponentReference reference: getReferences()) { + clone.getReferences().add((ComponentReference)reference.clone()); + } + clone.getServices().clear(); + for (ComponentService service: getServices()) { + clone.getServices().add((ComponentService)service.clone()); + } + return clone; + } + + 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 + 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 + 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 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 boolean accept(Visitor visitor) { + if (!visitor.visit(this)) { + return false; + } + for (ComponentProperty property : properties) { + if (!visitor.visit(property)) { + return false; + } + } + for (ComponentReference reference : references) { + if (!visitor.visit(reference)) { + return false; + } + } + for (ComponentService service : services) { + if (!visitor.visit(service)) { + return false; + } + } + return true; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/assembly/impl/BeanReferenceImpl.java b/sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/assembly/impl/BeanReferenceImpl.java new file mode 100644 index 0000000000..bc139a3ef3 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/assembly/impl/BeanReferenceImpl.java @@ -0,0 +1,65 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.spring.assembly.impl; + +import org.apache.tuscany.sca.assembly.ComponentService; +import org.apache.tuscany.sca.assembly.Reference; +import org.apache.tuscany.sca.assembly.SCABinding; +import org.springframework.beans.factory.config.RuntimeBeanReference; + +/** + * An implementation of RuntimeBeanReference wrappering an SCA assembly Reference + * + * @version $Rev$ $Date$ + */ +public class BeanReferenceImpl extends RuntimeBeanReference { + private Reference reference; + + protected BeanReferenceImpl(Reference reference) { + super("temp"); + this.reference = reference; + } + + public String getBeanName() { + //TODO handle multiplicity + ComponentService componentService = reference.getTargets().get(0); + if (!componentService.isUnresolved()) { + SCABinding binding = componentService.getBinding(SCABinding.class); + return binding.getComponent().getURI(); + } else { + return null; + } + } + + 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; + } + + public int hashCode() { + return getBeanName().hashCode() * 29 + (this.isToParent() ? 1 : 0); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/context/ModelResolverImpl.java b/sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/context/ModelResolverImpl.java new file mode 100644 index 0000000000..ba2d5045f2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/context/ModelResolverImpl.java @@ -0,0 +1,88 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.core.spring.context; + +import java.lang.ref.WeakReference; +import java.util.HashMap; +import java.util.Map; + +import org.apache.tuscany.sca.contribution.resolver.ClassReference; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; + + +/** + * A default implementation of an artifact resolver, based on a map. + * + * @version $Rev$ $Date$ + */ +public class ModelResolverImpl implements ModelResolver { + private static final long serialVersionUID = -7826976465762296634L; + + private Map map = new HashMap(); + + private WeakReference classLoader; + + public ModelResolverImpl(ClassLoader classLoader) { + this.classLoader = new WeakReference(classLoader); + } + + public T resolveModel(Class modelClass, T unresolved) { + Object resolved = map.get(unresolved); + if (resolved != null) { + + // Return the resolved object + return modelClass.cast(resolved); + + } else if (unresolved instanceof ClassReference) { + + // Load a class on demand + ClassReference classReference = (ClassReference)unresolved; + Class clazz; + try { + clazz = Class.forName(classReference.getClassName(), true, classLoader.get()); + } catch (ClassNotFoundException e) { + + // Return the unresolved object + return unresolved; + } + + // Store a new ClassReference wrappering the loaded class + resolved = new ClassReference(clazz); + map.put(resolved, resolved); + + // Return the resolved ClassReference + return modelClass.cast(resolved); + + } else { + + // Return the unresolved object + return unresolved; + } + } + + public void addModel(Object resolved) { + map.put(resolved, resolved); + } + + public Object removeModel(Object resolved) { + return map.remove(resolved); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/context/SCADomainContext.java b/sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/context/SCADomainContext.java new file mode 100644 index 0000000000..24bc719e6a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/context/SCADomainContext.java @@ -0,0 +1,195 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.spring.context; + +import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLOutputFactory; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory; +import org.apache.tuscany.sca.assembly.DefaultSCABindingFactory; +import org.apache.tuscany.sca.assembly.SCABindingFactory; +import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException; +import org.apache.tuscany.sca.assembly.builder.CompositeBuilderMonitor; +import org.apache.tuscany.sca.assembly.builder.Problem; +import org.apache.tuscany.sca.assembly.builder.impl.CompositeBuilderImpl; +import org.apache.tuscany.sca.assembly.xml.ComponentTypeProcessor; +import org.apache.tuscany.sca.assembly.xml.CompositeProcessor; +import org.apache.tuscany.sca.assembly.xml.ConstrainingTypeProcessor; +import org.apache.tuscany.sca.contribution.processor.DefaultStAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.service.ContributionException; +import org.apache.tuscany.sca.core.spring.assembly.impl.BeanAssemblyFactory; +import org.apache.tuscany.sca.core.spring.implementation.java.impl.BeanJavaImplementationFactory; +import org.apache.tuscany.sca.implementation.java.JavaImplementationFactory; +import org.apache.tuscany.sca.implementation.java.introspect.DefaultJavaClassIntrospectorExtensionPoint; +import org.apache.tuscany.sca.implementation.java.introspect.ExtensibleJavaClassIntrospector; +import org.apache.tuscany.sca.implementation.java.introspect.JavaClassIntrospector; +import org.apache.tuscany.sca.implementation.java.introspect.JavaClassIntrospectorExtensionPoint; +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.ConstructorProcessor; +import org.apache.tuscany.sca.implementation.java.introspect.impl.ContextProcessor; +import org.apache.tuscany.sca.implementation.java.introspect.impl.ConversationProcessor; +import org.apache.tuscany.sca.implementation.java.introspect.impl.DestroyProcessor; +import org.apache.tuscany.sca.implementation.java.introspect.impl.EagerInitProcessor; +import org.apache.tuscany.sca.implementation.java.introspect.impl.HeuristicPojoProcessor; +import org.apache.tuscany.sca.implementation.java.introspect.impl.InitProcessor; +import org.apache.tuscany.sca.implementation.java.introspect.impl.PolicyProcessor; +import org.apache.tuscany.sca.implementation.java.introspect.impl.PropertyProcessor; +import org.apache.tuscany.sca.implementation.java.introspect.impl.ReferenceProcessor; +import org.apache.tuscany.sca.implementation.java.introspect.impl.ResourceProcessor; +import org.apache.tuscany.sca.implementation.java.introspect.impl.ScopeProcessor; +import org.apache.tuscany.sca.implementation.java.introspect.impl.ServiceProcessor; +import org.apache.tuscany.sca.implementation.java.xml.JavaImplementationProcessor; +import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; +import org.apache.tuscany.sca.interfacedef.impl.InterfaceContractMapperImpl; +import org.apache.tuscany.sca.interfacedef.java.DefaultJavaInterfaceFactory; +import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory; +import org.apache.tuscany.sca.interfacedef.java.introspect.DefaultJavaInterfaceIntrospectorExtensionPoint; +import org.apache.tuscany.sca.interfacedef.java.introspect.ExtensibleJavaInterfaceIntrospector; +import org.apache.tuscany.sca.interfacedef.java.introspect.JavaInterfaceIntrospector; +import org.apache.tuscany.sca.interfacedef.java.introspect.JavaInterfaceIntrospectorExtensionPoint; +import org.apache.tuscany.sca.interfacedef.java.xml.JavaInterfaceProcessor; +import org.apache.tuscany.sca.policy.DefaultPolicyFactory; +import org.apache.tuscany.sca.policy.PolicyFactory; +import org.springframework.beans.factory.support.DefaultListableBeanFactory; + +/** + * A mini test runtime that uses the SCA assembly model variant implementation + * backed by Spring bean definitions. + * + * @version $Rev$ $Date$ + */ +public class SCADomainContext { + + private DefaultListableBeanFactory beanFactory; + + public SCADomainContext(String... compositeFiles) { + + // Create Spring bean factory + beanFactory = new DefaultListableBeanFactory(); + + // Create SCA assembly and SCA Java factories + AssemblyFactory assemblyFactory = new BeanAssemblyFactory(new DefaultAssemblyFactory(), beanFactory); + SCABindingFactory scaBindingFactory = new DefaultSCABindingFactory(); + PolicyFactory policyFactory = new DefaultPolicyFactory(); + InterfaceContractMapper interfaceContractMapper = new InterfaceContractMapperImpl(); + JavaInterfaceFactory javaFactory = new DefaultJavaInterfaceFactory(); + JavaInterfaceIntrospectorExtensionPoint interfaceVisitors = new DefaultJavaInterfaceIntrospectorExtensionPoint(); + JavaImplementationFactory javaImplementationFactory = new BeanJavaImplementationFactory(beanFactory); + JavaClassIntrospectorExtensionPoint classVisitors = new DefaultJavaClassIntrospectorExtensionPoint(); + + JavaInterfaceIntrospector interfaceIntrospector = new ExtensibleJavaInterfaceIntrospector(javaFactory, interfaceVisitors); + + BaseJavaClassVisitor[] extensions = new BaseJavaClassVisitor[] { + new ConstructorProcessor(assemblyFactory), + new AllowsPassByReferenceProcessor(assemblyFactory), + new ContextProcessor(assemblyFactory), + new ConversationProcessor(assemblyFactory), + new DestroyProcessor(assemblyFactory), + new EagerInitProcessor(assemblyFactory), + new InitProcessor(assemblyFactory), + new PropertyProcessor(assemblyFactory), + new ReferenceProcessor(assemblyFactory, javaFactory, interfaceIntrospector), + new ResourceProcessor(assemblyFactory), + new ScopeProcessor(assemblyFactory), + new ServiceProcessor(assemblyFactory, javaFactory, interfaceIntrospector), + new HeuristicPojoProcessor(assemblyFactory, javaFactory, interfaceIntrospector), + new PolicyProcessor(assemblyFactory, policyFactory) + }; + for (JavaClassVisitor e : extensions) { + classVisitors.addClassVisitor(e); + } + JavaClassIntrospector classIntrospector = new ExtensibleJavaClassIntrospector(classVisitors); + + // Populate ArtifactProcessor registry + DefaultStAXArtifactProcessorExtensionPoint staxProcessors = new DefaultStAXArtifactProcessorExtensionPoint(); + ExtensibleStAXArtifactProcessor staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, XMLInputFactory.newInstance(), XMLOutputFactory.newInstance()); + CompositeProcessor compositeProcessor = new CompositeProcessor(assemblyFactory, policyFactory, + interfaceContractMapper, staxProcessor); + staxProcessors.addArtifactProcessor(compositeProcessor); + staxProcessors.addArtifactProcessor(new ComponentTypeProcessor(assemblyFactory, policyFactory, staxProcessor)); + staxProcessors.addArtifactProcessor(new ConstrainingTypeProcessor(assemblyFactory, policyFactory, staxProcessor)); + staxProcessors.addArtifactProcessor(new JavaInterfaceProcessor(javaFactory, interfaceIntrospector)); + staxProcessors.addArtifactProcessor(new JavaImplementationProcessor(assemblyFactory, policyFactory, javaImplementationFactory, classIntrospector)); + + // Create a resolver + ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); + ModelResolverImpl resolver = new ModelResolverImpl(classLoader); + + try { + + // Read the composite files + List composites = new ArrayList(); + for (String compositeFile: compositeFiles) { + InputStream is = classLoader.getResourceAsStream(compositeFile); + Composite composite = staxProcessor.read(is, Composite.class); + resolver.addModel(composite); + composites.add(composite); + } + + for (Composite composite: composites) { + + // Resolve the composite + compositeProcessor.resolve(composite, resolver); + } + + // Wire the top level component's composite + buildComposite(composites.get(0), assemblyFactory, scaBindingFactory, interfaceContractMapper); + + } catch (ContributionException e) { + throw new RuntimeException(e); + } catch (CompositeBuilderException e) { + throw new RuntimeException(e); + } + } + + private void buildComposite(Composite composite, AssemblyFactory assemblyFactory, + SCABindingFactory scaBindingFactory, InterfaceContractMapper interfaceContractMapper) throws CompositeBuilderException { + + CompositeBuilderMonitor monitor = new CompositeBuilderMonitor() { + + public void problem(Problem problem) { + // Uncommenting the following two lines can be useful to detect + // and troubleshoot SCA assembly XML composite configuration + // problems. + + System.out.println("Composite assembly problem: " + problem.getMessage()); + } + }; + + // Configure and wire the composite + CompositeBuilderImpl compositeUtil = new CompositeBuilderImpl(assemblyFactory, scaBindingFactory, interfaceContractMapper, monitor); + compositeUtil.build(composite); + + } + + public B getService(Class businessInterface, String serviceName) { + Object bean = beanFactory.getBean(serviceName); + return businessInterface.cast(bean); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/implementation/java/impl/BeanBaseJavaImplementationImpl.java b/sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/implementation/java/impl/BeanBaseJavaImplementationImpl.java new file mode 100644 index 0000000000..8a88ba28d9 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/implementation/java/impl/BeanBaseJavaImplementationImpl.java @@ -0,0 +1,182 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.spring.implementation.java.impl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.sca.assembly.ConstrainingType; +import org.apache.tuscany.sca.assembly.Property; +import org.apache.tuscany.sca.assembly.Reference; +import org.apache.tuscany.sca.assembly.Service; +import org.apache.tuscany.sca.implementation.java.BaseJavaImplementation; +import org.apache.tuscany.sca.policy.Intent; +import org.apache.tuscany.sca.policy.PolicySet; +import org.springframework.beans.factory.support.BeanDefinitionRegistry; +import org.springframework.beans.factory.support.RootBeanDefinition; + +/** + * An implementation of the SCA assembly JavaImplementation interface backed by a Spring + * Bean definition. + * + * @version $Rev$ $Date$ + */ +public class BeanBaseJavaImplementationImpl extends RootBeanDefinition implements BaseJavaImplementation, Cloneable { + private static final long serialVersionUID = 1L; + + private List services = new ArrayList(); + private List requiredIntents = new ArrayList(); + private List policySets = new ArrayList(); + private ConstrainingType constrainingType; + private List extensions = new ArrayList(); + private boolean unresolved; + private BeanDefinitionRegistry beanRegistry; + private String uri; + + protected BeanBaseJavaImplementationImpl(BeanDefinitionRegistry beanRegistry) { + this.beanRegistry = beanRegistry; + + // Register this bean definition in the bean registry + //TODO find a better name for bean definitions representing component types + String name = String.valueOf(System.identityHashCode(this)); + this.beanRegistry.registerBeanDefinition(name, this); + } + + @Override + public Object clone() throws CloneNotSupportedException { + BeanBaseJavaImplementationImpl clone = (BeanBaseJavaImplementationImpl)super.clone(); + + clone.getServices().clear(); + for (Service service: getServices()) { + clone.getServices().add((Service)service.clone()); + } + clone.getReferences().clear(); + for (Reference reference: getReferences()) { + clone.getReferences().add((Reference)reference.clone()); + } + clone.getProperties().clear(); + for (Property property: getProperties()) { + clone.getProperties().add((Property)property.clone()); + } + return clone; + } + + public Class getJavaClass() { + return super.getBeanClass(); + } + + public String getName() { + return super.getBeanClassName(); + } + + public void setJavaClass(Class javaClass) { + super.setBeanClass(javaClass); + } + + public void setName(String className) { + super.setBeanClassName(className); + } + + public String getURI() { + return uri; + } + + public void setURI(String uri) { + this.uri = uri; + } + + public ConstrainingType getConstrainingType() { + return constrainingType; + } + + //TODO use a better list implementation + private List properties = new ArrayList() { + private static final long serialVersionUID = 1L; + + // Add a property + 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 + 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 getRequiredIntents() { + return requiredIntents; + } + + public List getPolicySets() { + return policySets; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/implementation/java/impl/BeanJavaImplementationFactory.java b/sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/implementation/java/impl/BeanJavaImplementationFactory.java new file mode 100644 index 0000000000..c9cd0f8892 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/implementation/java/impl/BeanJavaImplementationFactory.java @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.spring.implementation.java.impl; + +import org.apache.tuscany.sca.implementation.java.JavaImplementation; +import org.apache.tuscany.sca.implementation.java.JavaImplementationFactory; +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; + + public BeanJavaImplementationFactory(BeanDefinitionRegistry beanRegistry) { + this.beanRegistry = beanRegistry; + } + + public JavaImplementation createJavaImplementation() { + return new BeanJavaImplementationImpl(beanRegistry); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/implementation/java/impl/BeanJavaImplementationImpl.java b/sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/implementation/java/impl/BeanJavaImplementationImpl.java new file mode 100644 index 0000000000..5d787d2fd2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/implementation/java/impl/BeanJavaImplementationImpl.java @@ -0,0 +1,164 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.spring.implementation.java.impl; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Member; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.tuscany.sca.implementation.java.JavaImplementation; +import org.apache.tuscany.sca.implementation.java.impl.JavaConstructorImpl; +import org.apache.tuscany.sca.implementation.java.impl.JavaElementImpl; +import org.apache.tuscany.sca.implementation.java.impl.JavaResourceImpl; +import org.apache.tuscany.sca.implementation.java.impl.JavaScopeImpl; +import org.springframework.beans.factory.support.BeanDefinitionRegistry; + +/** + * An implementation of the SCA assembly JavaImplementation interface backed by a Spring + * Bean definition. + * + * @version $$Rev$$ $$Date$$ + */ +public class BeanJavaImplementationImpl extends BeanBaseJavaImplementationImpl implements JavaImplementation { + private static final long serialVersionUID = 6792198458193774178L; + + private JavaConstructorImpl constructorDefinition; + private Map constructors = new HashMap(); + private Method initMethod; + private Method destroyMethod; + private final Map resources = new HashMap(); + private final Map propertyMembers = new HashMap(); + private final Map referenceMembers = new HashMap(); + private final Map callbackMembers = new HashMap(); + private Member conversationIDMember; + private boolean eagerInit; + private boolean allowsPassByReference; + private List allowsPassByReferenceMethods = new ArrayList(); + private long maxAge = -1; + private long maxIdleTime = -1; + private JavaScopeImpl scope = JavaScopeImpl.STATELESS; + + protected BeanJavaImplementationImpl(BeanDefinitionRegistry beanRegistry) { + super(beanRegistry); + } + + public JavaConstructorImpl getConstructor() { + return constructorDefinition; + } + + public void setConstructor(JavaConstructorImpl definition) { + this.constructorDefinition = definition; + } + + public Method getInitMethod() { + return initMethod; + } + + public void setInitMethod(Method initMethod) { + this.initMethod = initMethod; + } + + public Method getDestroyMethod() { + return destroyMethod; + } + + public void setDestroyMethod(Method destroyMethod) { + this.destroyMethod = destroyMethod; + } + + public Map getResources() { + return resources; + } + + public Member getConversationIDMember() { + return this.conversationIDMember; + } + + public void setConversationIDMember(Member conversationIDMember) { + this.conversationIDMember = conversationIDMember; + } + + public boolean isAllowsPassByReference() { + return allowsPassByReference; + } + + public void setAllowsPassByReference(boolean allowsPassByReference) { + this.allowsPassByReference = allowsPassByReference; + } + + public List getAllowsPassByReferenceMethods() { + return allowsPassByReferenceMethods; + } + + public boolean isAllowsPassByReference(Method method) { + return allowsPassByReference || allowsPassByReferenceMethods.contains(method); + } + + public Map getConstructors() { + return constructors; + } + + public boolean isEagerInit() { + return eagerInit; + } + + public void setEagerInit(boolean eagerInit) { + this.eagerInit = eagerInit; + } + + public Map getCallbackMembers() { + return callbackMembers; + } + + public Map getPropertyMembers() { + return propertyMembers; + } + + public Map getReferenceMembers() { + return referenceMembers; + } + + public JavaScopeImpl getJavaScope() { + return scope; + } + + public void setJavaScope(JavaScopeImpl scope) { + this.scope = scope; + } + + public long getMaxAge() { + return maxAge; + } + + public void setMaxAge(long maxAge) { + this.maxAge = maxAge; + } + + public long getMaxIdleTime() { + return maxIdleTime; + } + + public void setMaxIdleTime(long maxIdleTime) { + this.maxIdleTime = maxIdleTime; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/implementation/java/impl/BeanJavaInterfaceContractImpl.java b/sca-java-1.x/branches/sca-java-0.91/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/sca-java-1.x/branches/sca-java-0.91/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/sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/implementation/java/impl/BeanJavaInterfaceFactory.java b/sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/implementation/java/impl/BeanJavaInterfaceFactory.java new file mode 100644 index 0000000000..6557d23f27 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/implementation/java/impl/BeanJavaInterfaceFactory.java @@ -0,0 +1,44 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.spring.implementation.java.impl; + +import org.apache.tuscany.sca.interfacedef.java.JavaInterface; +import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceContract; +import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory; + +/** + * 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 { + + public BeanJavaInterfaceFactory() { + } + + public JavaInterface createJavaInterface() { + return new BeanJavaInterfaceImpl(); + } + + public JavaInterfaceContract createJavaInterfaceContract() { + return new BeanJavaInterfaceContractImpl(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/implementation/java/impl/BeanJavaInterfaceImpl.java b/sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/implementation/java/impl/BeanJavaInterfaceImpl.java new file mode 100644 index 0000000000..91cd352724 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/main/java/org/apache/tuscany/sca/core/spring/implementation/java/impl/BeanJavaInterfaceImpl.java @@ -0,0 +1,122 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.spring.implementation.java.impl; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.java.JavaInterface; +import org.apache.tuscany.sca.policy.Intent; + +/** + * An alternate implementation of the SCA Java assembly model JavaInterface + * interface. + * + * @version $Rev$ $Date$ + */ +public class BeanJavaInterfaceImpl implements JavaInterface { + + private String className; + private Class javaClass; + private Class callbackClass; + private boolean conversational; + private boolean remotable; + List requiredIntents = new ArrayList(); + private List extensions = new ArrayList(); + private List operations = new ArrayList(); + private boolean unresolved = false; + + protected BeanJavaInterfaceImpl() { + } + + public String getName() { + if (isUnresolved()) { + return className; + } + else { + return javaClass.getName(); + } + } + + public void setName(String className) { + if (!isUnresolved()) + throw new IllegalStateException(); + this.className = className; + } + + public Class getJavaClass() { + return javaClass; + } + + public void setJavaClass(Class javaClass) { + this.javaClass = javaClass; + } + + public Class getCallbackClass() { + return callbackClass; + } + + public void setCallbackClass(Class callbackClass) { + this.callbackClass = callbackClass; + } + + public boolean isConversational() { + return conversational; + } + + public boolean isRemotable() { + return remotable; + } + + public void setConversational(boolean conversational) { + this.conversational = conversational; + } + + public void setRemotable(boolean local) { + this.remotable = local; + } + + public List getRequiredIntents() { + return requiredIntents; + } + + public List getExtensions() { + return extensions; + } + + public List getOperations() { + return operations; + } + + public boolean isUnresolved() { + return unresolved; + } + + public void setUnresolved(boolean undefined) { + this.unresolved = undefined; + } + + public void setDefaultDataBinding(String dataBinding) { + } + + public boolean isDynamic() { + return false; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/test/java/calculator/AddService.java b/sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/test/java/calculator/AddService.java new file mode 100644 index 0000000000..4eeb30a9c2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/test/java/calculator/AddService.java @@ -0,0 +1,25 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package calculator; + +public interface AddService { + + double add(double n1, double n2); + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/test/java/calculator/AddServiceImpl.java b/sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/test/java/calculator/AddServiceImpl.java new file mode 100644 index 0000000000..ea3e5341d5 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/test/java/calculator/AddServiceImpl.java @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package calculator; + +import org.osoa.sca.annotations.EagerInit; +import org.osoa.sca.annotations.Scope; + +/** + * An implementation of the Add service + */ +@Scope("COMPOSITE") +@EagerInit +public class AddServiceImpl implements AddService { + + public double add(double n1, double n2) { + return n1 + n2; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/test/java/calculator/CalculatorClient.java b/sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/test/java/calculator/CalculatorClient.java new file mode 100644 index 0000000000..56e737e3ab --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/test/java/calculator/CalculatorClient.java @@ -0,0 +1,41 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package calculator; + +import org.apache.tuscany.sca.core.spring.context.SCADomainContext; + +/** + * This client program shows how to create an SCA runtime, start it, locate the + * Calculator service and invoke it. + */ +public class CalculatorClient { + public static void main(String[] args) throws Exception { + + SCADomainContext context = new SCADomainContext("org/apache/tuscany/core/spring/Calculator.composite"); + + CalculatorService calculatorService = context.getService(CalculatorService.class, "CalculatorServiceComponent"); + + // Calculate + System.out.println("3 + 2=" + calculatorService.add(3, 2)); + System.out.println("3 - 2=" + calculatorService.subtract(3, 2)); + System.out.println("3 * 2=" + calculatorService.multiply(3, 2)); + System.out.println("3 / 2=" + calculatorService.divide(3, 2)); + + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/test/java/calculator/CalculatorService.java b/sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/test/java/calculator/CalculatorService.java new file mode 100644 index 0000000000..c89043276e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/test/java/calculator/CalculatorService.java @@ -0,0 +1,34 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package calculator; + +/** + * The Calculator service interface. + */ +public interface CalculatorService { + + double add(double n1, double n2); + + double subtract(double n1, double n2); + + double multiply(double n1, double n2); + + double divide(double n1, double n2); + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/test/java/calculator/CalculatorServiceImpl.java b/sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/test/java/calculator/CalculatorServiceImpl.java new file mode 100644 index 0000000000..11e8974657 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/test/java/calculator/CalculatorServiceImpl.java @@ -0,0 +1,71 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package calculator; + +import org.osoa.sca.annotations.Reference; +import org.osoa.sca.annotations.Scope; + +/** + * An implementation of the Calculator service. + */ +@Scope("COMPOSITE") +public class CalculatorServiceImpl implements CalculatorService { + + private AddService addService; + private SubtractService subtractService; + private MultiplyService multiplyService; + private DivideService divideService; + + @Reference + public void setAddService(AddService addService) { + this.addService = addService; + } + + @Reference + public void setSubtractService(SubtractService subtractService) { + this.subtractService = subtractService; + } + + @Reference + public void setDivideService(DivideService divideService) { + this.divideService = divideService; + } + + @Reference + public void setMultiplyService(MultiplyService multiplyService) { + this.multiplyService = multiplyService; + } + + public double add(double n1, double n2) { + return addService.add(n1, n2); + } + + public double subtract(double n1, double n2) { + return subtractService.subtract(n1, n2); + } + + public double multiply(double n1, double n2) { + return multiplyService.multiply(n1, n2); + } + + public double divide(double n1, double n2) { + return divideService.divide(n1, n2); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/test/java/calculator/DivideService.java b/sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/test/java/calculator/DivideService.java new file mode 100644 index 0000000000..131c5a8014 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/test/java/calculator/DivideService.java @@ -0,0 +1,25 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package calculator; + +public interface DivideService { + + double divide(double n1, double n2); + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/test/java/calculator/DivideServiceImpl.java b/sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/test/java/calculator/DivideServiceImpl.java new file mode 100644 index 0000000000..9c7e96a668 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/test/java/calculator/DivideServiceImpl.java @@ -0,0 +1,33 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package calculator; + +import org.osoa.sca.annotations.Scope; + +/** + * An implementation of the Divide service. + */ +@Scope("COMPOSITE") +public class DivideServiceImpl implements DivideService { + + public double divide(double n1, double n2) { + return n1 / n2; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/test/java/calculator/MultiplyService.java b/sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/test/java/calculator/MultiplyService.java new file mode 100644 index 0000000000..a917896aeb --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/test/java/calculator/MultiplyService.java @@ -0,0 +1,25 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package calculator; + +public interface MultiplyService { + + double multiply(double n1, double n2); + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/test/java/calculator/MultiplyServiceImpl.java b/sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/test/java/calculator/MultiplyServiceImpl.java new file mode 100644 index 0000000000..4892481203 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/test/java/calculator/MultiplyServiceImpl.java @@ -0,0 +1,33 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package calculator; + +import org.osoa.sca.annotations.Scope; + +/** + * An implementation of the Multiply service. + */ +@Scope("COMPOSITE") +public class MultiplyServiceImpl implements MultiplyService { + + public double multiply(double n1, double n2) { + return n1 * n2; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/test/java/calculator/NestedCalculatorClient.java b/sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/test/java/calculator/NestedCalculatorClient.java new file mode 100644 index 0000000000..27430b7f5d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/test/java/calculator/NestedCalculatorClient.java @@ -0,0 +1,44 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package calculator; + +import org.apache.tuscany.sca.core.spring.context.SCADomainContext; + +/** + * This client program shows how to create an SCA runtime, start it, locate the + * Calculator service and invoke it. + */ +public class NestedCalculatorClient { + public static void main(String[] args) throws Exception { + + SCADomainContext context = new SCADomainContext( + "org/apache/tuscany/core/spring/OuterCalculator.composite", + "org/apache/tuscany/core/spring/InnerCalculator.composite", + "org/apache/tuscany/core/spring/InnerOperations.composite"); + + CalculatorService calculatorService = context.getService(CalculatorService.class, "CalculatorServiceComponent/CalculatorServiceComponent"); + + // Calculate + System.out.println("3 + 2=" + calculatorService.add(3, 2)); + System.out.println("3 - 2=" + calculatorService.subtract(3, 2)); + System.out.println("3 * 2=" + calculatorService.multiply(3, 2)); + System.out.println("3 / 2=" + calculatorService.divide(3, 2)); + + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/test/java/calculator/SubtractService.java b/sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/test/java/calculator/SubtractService.java new file mode 100644 index 0000000000..e328f024ea --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/test/java/calculator/SubtractService.java @@ -0,0 +1,25 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package calculator; + +public interface SubtractService { + + double subtract(double n1, double n2); + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/test/java/calculator/SubtractServiceImpl.java b/sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/test/java/calculator/SubtractServiceImpl.java new file mode 100644 index 0000000000..ee1d7c3457 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/test/java/calculator/SubtractServiceImpl.java @@ -0,0 +1,33 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package calculator; + +import org.osoa.sca.annotations.Scope; + +/** + * An implementation of the subtract service. + */ +@Scope("COMPOSITE") +public class SubtractServiceImpl implements SubtractService { + + public double subtract(double n1, double n2) { + return n1 - n2; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/test/java/org/apache/tuscany/sca/core/spring/CalculatorTestCase.java b/sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/test/java/org/apache/tuscany/sca/core/spring/CalculatorTestCase.java new file mode 100644 index 0000000000..97a44258a8 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/test/java/org/apache/tuscany/sca/core/spring/CalculatorTestCase.java @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.spring; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.core.spring.context.SCADomainContext; + +import calculator.CalculatorService; + +/** + * This shows how to test the Calculator service component. + */ +public class CalculatorTestCase extends TestCase { + + private SCADomainContext context; + private CalculatorService calculatorService; + + protected void setUp() throws Exception { + context = new SCADomainContext("org/apache/tuscany/sca/core/spring/Calculator.composite"); + + calculatorService = context.getService(CalculatorService.class, "CalculatorServiceComponent"); + } + + protected void tearDown() throws Exception { + context = null; + calculatorService = null; + } + + 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/sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/test/java/org/apache/tuscany/sca/core/spring/NestedCalculatorTestCase.java b/sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/test/java/org/apache/tuscany/sca/core/spring/NestedCalculatorTestCase.java new file mode 100644 index 0000000000..5ef16a91d8 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/test/java/org/apache/tuscany/sca/core/spring/NestedCalculatorTestCase.java @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.spring; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.core.spring.context.SCADomainContext; + +import calculator.CalculatorService; + +/** + * This shows how to test the Calculator service component. + */ +public class NestedCalculatorTestCase extends TestCase { + + private SCADomainContext context; + private CalculatorService calculatorService; + + 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"); + } + + protected void tearDown() throws Exception { + context = null; + calculatorService = null; + } + + 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/sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/test/resources/org/apache/tuscany/sca/core/spring/Calculator.composite b/sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/test/resources/org/apache/tuscany/sca/core/spring/Calculator.composite new file mode 100644 index 0000000000..6d998ba035 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/test/resources/org/apache/tuscany/sca/core/spring/Calculator.composite @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/test/resources/org/apache/tuscany/sca/core/spring/InnerCalculator.composite b/sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/test/resources/org/apache/tuscany/sca/core/spring/InnerCalculator.composite new file mode 100644 index 0000000000..8b043f2b4f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/test/resources/org/apache/tuscany/sca/core/spring/InnerCalculator.composite @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/test/resources/org/apache/tuscany/sca/core/spring/InnerOperations.composite b/sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/test/resources/org/apache/tuscany/sca/core/spring/InnerOperations.composite new file mode 100644 index 0000000000..d7d1124050 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/test/resources/org/apache/tuscany/sca/core/spring/InnerOperations.composite @@ -0,0 +1,57 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/test/resources/org/apache/tuscany/sca/core/spring/OuterCalculator.composite b/sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/test/resources/org/apache/tuscany/sca/core/spring/OuterCalculator.composite new file mode 100644 index 0000000000..c2b6cced36 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core-spring/src/test/resources/org/apache/tuscany/sca/core/spring/OuterCalculator.composite @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/.checkstyle b/sca-java-1.x/branches/sca-java-0.91/modules/core/.checkstyle new file mode 100644 index 0000000000..3e57539570 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/.checkstyle @@ -0,0 +1,24 @@ + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/.pmd b/sca-java-1.x/branches/sca-java-0.91/modules/core/.pmd new file mode 100644 index 0000000000..ffc4fe2bbb --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/.pmd @@ -0,0 +1,20 @@ + + +true diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/.ruleset b/sca-java-1.x/branches/sca-java-0.91/modules/core/.ruleset new file mode 100644 index 0000000000..ba9b5ce886 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/.ruleset @@ -0,0 +1,190 @@ + + + + PMD Plugin preferences rule set + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/DISCLAIMER b/sca-java-1.x/branches/sca-java-0.91/modules/core/DISCLAIMER new file mode 100644 index 0000000000..d68a410903 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/DISCLAIMER @@ -0,0 +1,8 @@ +Apache Tuscany is an effort undergoing incubation at The Apache Software +Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is +required of all newly accepted projects until a further review indicates that +the infrastructure, communications, and decision making process have stabilized +in a manner consistent with other successful ASF projects. While incubation +status is not necessarily a reflection of the completeness or stability of the +code, it does indicate that the project has yet to be fully endorsed by the ASF. + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/LICENSE b/sca-java-1.x/branches/sca-java-0.91/modules/core/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/NOTICE b/sca-java-1.x/branches/sca-java-0.91/modules/core/NOTICE new file mode 100644 index 0000000000..94481d6cfa --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2007 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/pom.xml b/sca-java-1.x/branches/sca-java-0.91/modules/core/pom.xml new file mode 100644 index 0000000000..66cf94e76a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/pom.xml @@ -0,0 +1,64 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 0.91-incubating-SNAPSHOT + ../pom.xml + + tuscany-core + Apache Tuscany SCA Core Runtime + + + + org.apache.tuscany.sca + tuscany-core-spi + 0.91-incubating-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-contribution + 0.91-incubating-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-interface-java + 0.91-incubating-SNAPSHOT + + + + org.apache.tuscany + commonj-api + 0.91-incubating-SNAPSHOT + + + + org.codehaus.woodstox + wstx-asl + 3.2.0 + runtime + + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/component/CallableReferenceImpl.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/component/CallableReferenceImpl.java new file mode 100644 index 0000000000..f0f0049056 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/component/CallableReferenceImpl.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.component; + +import org.apache.tuscany.sca.factory.ObjectFactory; +import org.osoa.sca.CallableReference; +import org.osoa.sca.Conversation; + +/** + * Base class for implementations of service and callback references. + * + * @version $Rev$ $Date$ + * @param the type of the business interface + */ +public abstract class CallableReferenceImpl implements CallableReference { + private final Class businessInterface; + private final ObjectFactory factory; + + protected CallableReferenceImpl(Class businessInterface, ObjectFactory factory) { + this.businessInterface = businessInterface; + this.factory = factory; + } + + public B getService() { + return factory.getInstance(); + } + + public Class getBusinessInterface() { + return businessInterface; + } + + public boolean isConversational() { + return false; + } + + public Conversation getConversation() { + return null; + } + + public Object getCallbackID() { + return null; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/component/CallbackReferenceImpl.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/component/CallbackReferenceImpl.java new file mode 100644 index 0000000000..45a48730d3 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/component/CallbackReferenceImpl.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.core.component; + +import org.apache.tuscany.sca.factory.ObjectFactory; + +/** + * Default implementation of a callback reference. + * + * @version $Rev$ $Date$ + * @param the type of the business interface + */ +public class CallbackReferenceImpl extends CallableReferenceImpl { + public CallbackReferenceImpl(Class businessInterface, ObjectFactory factory) { + super(businessInterface, factory); + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/component/ComponentContextImpl.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/component/ComponentContextImpl.java new file mode 100644 index 0000000000..abcd17f505 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/component/ComponentContextImpl.java @@ -0,0 +1,93 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.component; + +import org.osoa.sca.CallableReference; +import org.osoa.sca.ComponentContext; +import org.osoa.sca.RequestContext; +import org.osoa.sca.ServiceReference; +import org.osoa.sca.ServiceRuntimeException; + +/** + * Implementation of ComponentContext that delegates to a ComponentContextProvider. + * + * @version $Rev$ $Date$ + */ +public class ComponentContextImpl implements ComponentContext { + private final ComponentContextProvider component; + + public ComponentContextImpl(ComponentContextProvider component) { + this.component = component; + } + + public String getURI() { + try { + return component.getUri().toString(); + } catch (RuntimeException e) { + throw new ServiceRuntimeException(e.getMessage(), e); + } + } + + public > R cast(B target) throws IllegalArgumentException { + try { + return (R) component.cast(target); + } catch (RuntimeException e) { + throw new ServiceRuntimeException(e.getMessage(), e); + } + } + + public B getService(Class businessInterface, String referenceName) { + try { + return component.getService(businessInterface, referenceName); + } catch (RuntimeException e) { + throw new ServiceRuntimeException(e.getMessage(), e); + } + } + + public ServiceReference getServiceReference(Class businessInterface, String referenceName) { + try { + return component.getServiceReference(businessInterface, referenceName); + } catch (RuntimeException e) { + throw new ServiceRuntimeException(e.getMessage(), e); + } + } + + public B getProperty(Class type, String propertyName) { + try { + return component.getProperty(type, propertyName); + } catch (RuntimeException e) { + throw new ServiceRuntimeException(e.getMessage(), e); + } + } + + public ServiceReference createSelfReference(Class businessInterface) { + return getServiceReference(businessInterface, "$self$."); + // FIXME: How to get the ObjectFactory? + // ObjectFactory factory = ((AtomicComponent) component).createObjectFactory(); + // return new ServiceReferenceImpl(businessInterface, factory); + } + + public ServiceReference createSelfReference(Class businessInterface, String serviceName) { + return getServiceReference(businessInterface, "$self$."+serviceName); + } + + public RequestContext getRequestContext() { + return null; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/component/ComponentContextProvider.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/component/ComponentContextProvider.java new file mode 100644 index 0000000000..3999d0d5b4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/component/ComponentContextProvider.java @@ -0,0 +1,44 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.component; + +import java.net.URI; + +import org.osoa.sca.CallableReference; +import org.osoa.sca.ComponentContext; +import org.osoa.sca.ServiceReference; + +/** + * Interface implemented by Component's that want to expose a ComponentContext. + * + * @version $Rev$ $Date$ + */ +public interface ComponentContextProvider { + ComponentContext getComponentContext(); + + URI getUri(); + + B getService(Class businessInterface, String referenceName); + + ServiceReference getServiceReference(Class businessInterface, String referenceName); + + B getProperty(Class type, String propertyName); + + > R cast(B target); +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/component/RequestContextImpl.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/component/RequestContextImpl.java new file mode 100644 index 0000000000..3a219b9cd9 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/component/RequestContextImpl.java @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.component; + +import javax.security.auth.Subject; + +import org.osoa.sca.CallableReference; +import org.osoa.sca.RequestContext; +import org.osoa.sca.ServiceReference; + +/** + * @version $Rev$ $Date$ + */ +public class RequestContextImpl implements RequestContext { + + public RequestContextImpl() { + } + + public Subject getSecuritySubject() { + throw new UnsupportedOperationException(); + } + + public String getServiceName() { + throw new UnsupportedOperationException(); + } + + public ServiceReference getServiceReference() { + throw new UnsupportedOperationException(); + } + + public CB getCallback() { + throw new UnsupportedOperationException(); + } + + public CallableReference getCallbackReference() { + throw new UnsupportedOperationException(); + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/component/ServiceReferenceImpl.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/component/ServiceReferenceImpl.java new file mode 100644 index 0000000000..e268f5750f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/component/ServiceReferenceImpl.java @@ -0,0 +1,51 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.component; + +import org.apache.tuscany.sca.factory.ObjectFactory; +import org.osoa.sca.ServiceReference; + +/** + * Default implementation of a ServiceReference. + * + * @version $Rev$ $Date$ + * @param the type of the business interface + */ +public class ServiceReferenceImpl extends CallableReferenceImpl implements ServiceReference { + public ServiceReferenceImpl(Class businessInterface, ObjectFactory factory) { + super(businessInterface, factory); + } + + public Object getConversationID() { + return null; + } + + public void setConversationID(Object conversationId) throws IllegalStateException { + } + + public void setCallbackID(Object callbackID) { + } + + public Object getCallback() { + return null; + } + + public void setCallback(Object callback) { + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/event/BaseEventPublisher.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/event/BaseEventPublisher.java new file mode 100644 index 0000000000..517e5579a4 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/event/BaseEventPublisher.java @@ -0,0 +1,89 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.event; + +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.CopyOnWriteArrayList; + +import org.apache.tuscany.sca.event.Event; +import org.apache.tuscany.sca.event.EventFilter; +import org.apache.tuscany.sca.event.EventPublisher; +import org.apache.tuscany.sca.event.RuntimeEventListener; +import org.apache.tuscany.sca.event.TrueFilter; + +/** + * Base implementation of an EventPublisher + * + * @version $Rev$ $Date$ + */ +public abstract class BaseEventPublisher implements EventPublisher { + protected static final EventFilter TRUE_FILTER = new TrueFilter(); + protected Map> listeners; + + public void addListener(RuntimeEventListener listener) { + addListener(TRUE_FILTER, listener); + } + + public void removeListener(RuntimeEventListener listener) { + assert listener != null : "Listener cannot be null"; + synchronized (getListeners()) { + for (List currentList : getListeners().values()) { + for (RuntimeEventListener current : currentList) { + if (current == listener) { + currentList.remove(current); + return; + } + } + } + } + } + + public void addListener(EventFilter filter, RuntimeEventListener listener) { + assert listener != null : "Listener cannot be null"; + synchronized (getListeners()) { + List list = getListeners().get(filter); + if (list == null) { + list = new CopyOnWriteArrayList(); + listeners.put(filter, list); + } + list.add(listener); + } + } + + public void publish(Event event) { + assert event != null : "Event object was null"; + for (Map.Entry> entry : getListeners().entrySet()) { + if (entry.getKey().match(event)) { + for (RuntimeEventListener listener : entry.getValue()) { + listener.onEvent(event); + } + } + } + } + + protected Map> getListeners() { + if (listeners == null) { + listeners = new ConcurrentHashMap>(); + } + return listeners; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/event/ComponentStart.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/event/ComponentStart.java new file mode 100644 index 0000000000..8e90c953e5 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/event/ComponentStart.java @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.event; + +import java.net.URI; + +import org.apache.tuscany.sca.event.Event; + +/** + * Propagated when a component starts + * + * @version $$Rev$$ $$Date$$ + */ +public class ComponentStart implements Event { + + private Object source; + private URI uri; + + /** + * Creates a component start event + * + * @param source the source of the event + * @param componentURI the uri of the component being started + */ + public ComponentStart(Object source, URI componentURI) { + this.source = source; + this.uri = componentURI; + } + + public URI getComponentURI() { + return uri; + } + + public Object getSource() { + return source; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/event/ComponentStop.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/event/ComponentStop.java new file mode 100644 index 0000000000..d879182e14 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/event/ComponentStop.java @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.event; + +import java.net.URI; + +import org.apache.tuscany.sca.event.Event; + +/** + * Propagated when a component stops + * + * @version $$Rev$$ $$Date$$ + */ +public class ComponentStop implements Event { + + private Object source; + private URI uri; + + /** + * Creates a component stop event + * + * @param source the source of the event + * @param componentUri the composite component associated the component being stopped + */ + public ComponentStop(Object source, URI componentUri) { + this.source = source; + this.uri = componentUri; + } + + public URI getComponentURI() { + return uri; + } + + public Object getSource() { + return source; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/event/ConversationEnd.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/event/ConversationEnd.java new file mode 100644 index 0000000000..cd14710880 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/event/ConversationEnd.java @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.event; + +import org.apache.tuscany.sca.event.Event; + + + +/** + * Propagated when a conversation is expired + * + * @version $$Rev$$ $$Date$$ + */ +public class ConversationEnd implements Event { + + private Object source; + private Object id; + + /** + * Creates a new event + * + * @param source the source of the event + * @param id the id of the conversation being ended + */ + public ConversationEnd(Object source, Object id) { + this.source = source; + this.id = id; + } + + public Object getSource() { + return source; + } + + public Object getConversationID() { + return id; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/event/ConversationStart.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/event/ConversationStart.java new file mode 100644 index 0000000000..a4cc49204e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/event/ConversationStart.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.event; + +import org.apache.tuscany.sca.event.Event; + + +/** + * Propagated when a conversation has started + * + * @version $$Rev$$ $$Date$$ + */ +public class ConversationStart implements Event { + + private Object source; + private Object id; + + /** + * Creates a new event + * + * @param source the source of the event + * @param id the id of the conversation being started + */ + public ConversationStart(Object source, Object id) { + this.source = source; + this.id = id; + } + + public Object getSource() { + return source; + } + + public Object getConversationID() { + return id; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/event/HttpSessionEnd.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/event/HttpSessionEnd.java new file mode 100644 index 0000000000..4c3fd8b397 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/event/HttpSessionEnd.java @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.event; + +import org.apache.tuscany.sca.event.Event; + + + +/** + * Propagated when an HTTP-based session is expired + * + * @version $$Rev$$ $$Date$$ + */ +public class HttpSessionEnd implements Event { + + private Object source; + private Object id; + + /** + * Creates a new event + * + * @param source the source of the event + * @param id the id of the HTTP session being ended + */ + public HttpSessionEnd(Object source, Object id) { + this.source = source; + this.id = id; + } + + public Object getSource() { + return source; + } + + public Object getSessionID() { + return id; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/event/HttpSessionStart.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/event/HttpSessionStart.java new file mode 100644 index 0000000000..67b922b99c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/event/HttpSessionStart.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.event; + +import org.apache.tuscany.sca.event.Event; + + +/** + * Propagated when an HTTP-based session has started + * + * @version $$Rev$$ $$Date$$ + */ +public class HttpSessionStart implements Event { + + private Object source; + private Object id; + + /** + * Creates a new event + * + * @param source the source of the event + * @param id the id of the HTTP session being started + */ + public HttpSessionStart(Object source, Object id) { + this.source = source; + this.id = id; + } + + public Object getSource() { + return source; + } + + public Object getSessionID() { + return id; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/event/RequestEnd.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/event/RequestEnd.java new file mode 100644 index 0000000000..8b5c512cf2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/event/RequestEnd.java @@ -0,0 +1,45 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.event; + +import org.apache.tuscany.sca.event.Event; + +/** + * Propagated when a request completes or is ended + * + * @version $$Rev$$ $$Date$$ + */ +public class RequestEnd implements Event { + + private Object source; + + /** + * Creates a new event + * + * @param source the source of the event + */ + public RequestEnd(Object source) { + this.source = source; + } + + public Object getSource() { + return source; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/event/RequestStart.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/event/RequestStart.java new file mode 100644 index 0000000000..974563b57c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/event/RequestStart.java @@ -0,0 +1,45 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.event; + +import org.apache.tuscany.sca.event.Event; + +/** + * Propagated when a request is started in the runtime + * + * @version $$Rev$$ $$Date$$ + */ +public class RequestStart implements Event { + + private Object source; + + /** + * Creates a new event + * + * @param source the source of the event + */ + public RequestStart(Object source) { + this.source = source; + } + + public Object getSource() { + return source; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/AbstractInvocationHandler.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/AbstractInvocationHandler.java new file mode 100644 index 0000000000..6c1f38e4c2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/AbstractInvocationHandler.java @@ -0,0 +1,104 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.invocation; + +import java.util.UUID; + +import org.apache.tuscany.sca.interfacedef.ConversationSequence; +import org.apache.tuscany.sca.interfacedef.Interface; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.InvocationChain; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.invocation.MessageFactory; +import org.apache.tuscany.sca.runtime.RuntimeWire; + +/** + * Base class for performing invocations on a wire. Subclasses are responsible for retrieving and supplying the + * appropriate chain, target invoker, and invocation arguments. + * + * @version $Rev$ $Date$ + */ +public abstract class AbstractInvocationHandler { + protected boolean conversational; + private boolean conversationStarted; + private MessageFactory messageFactory; + + protected AbstractInvocationHandler(MessageFactory messageFactory, boolean conversational) { + this.conversational = conversational; + this.messageFactory = messageFactory; + } + + protected Object invoke(InvocationChain chain, Object[] args, RuntimeWire wire) throws Throwable { + + Message msgContext = ThreadMessageContext.getMessageContext(); + Message msg = messageFactory.createMessage(); + if (conversational) { + Object id = msgContext.getConversationID(); + if (id == null) { + String convIdFromThread = createConversationID(); + msg.setConversationID(convIdFromThread); + } + } + + Invoker headInvoker = chain.getHeadInvoker(); + msg.setCorrelationID(msgContext.getCorrelationID()); + Operation operation = chain.getTargetOperation(); + Interface contract = operation.getInterface(); + if (contract != null && contract.isConversational()) { + ConversationSequence sequence = chain.getTargetOperation().getConversationSequence(); + if (sequence == ConversationSequence.CONVERSATION_END) { + msg.setConversationSequence(ConversationSequence.CONVERSATION_END); + conversationStarted = false; + } else if (sequence == ConversationSequence.CONVERSATION_CONTINUE) { + if (conversationStarted) { + msg.setConversationSequence(ConversationSequence.CONVERSATION_CONTINUE); + } else { + conversationStarted = true; + msg.setConversationSequence(ConversationSequence.CONVERSATION_START); + } + } + } + msg.setBody(args); + msg.setFrom(wire.getSource()); + msg.setTo(wire.getTarget()); + ThreadMessageContext.setMessageContext(msg); + try { + // dispatch the wire down the chain and get the response + Message resp = headInvoker.invoke(msg); + Object body = resp.getBody(); + if (resp.isFault()) { + throw (Throwable)body; + } + return body; + } finally { + ThreadMessageContext.setMessageContext(msgContext); + } + } + + /** + * Creates a new conversational id + * + * @return the conversational id + */ + private String createConversationID() { + return UUID.randomUUID().toString(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallbackInterfaceInterceptor.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallbackInterfaceInterceptor.java new file mode 100644 index 0000000000..219dc55536 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallbackInterfaceInterceptor.java @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.invocation; + +import org.apache.tuscany.sca.invocation.Interceptor; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.osoa.sca.NoRegisteredCallbackException; + +/** + * An interceptor applied to the forward direction of a wire that ensures the callback target implements the required + * service contract. This is required as callback targets may be set dynamically by service implementations. + * + * @version $Rev$ $Date$ + */ +public class CallbackInterfaceInterceptor implements Interceptor { + private boolean invokingServiceImplements; + private Invoker next; + + public CallbackInterfaceInterceptor(boolean invokingServiceImplements) { + this.invokingServiceImplements = invokingServiceImplements; + } + + public Message invoke(Message msg) { + // TODO check in the context if a callback object is set, if so invoke next since the setCallback will + // perform the check + if (!invokingServiceImplements) { + throw new NoRegisteredCallbackException("Callback target does not implement the callback interface"); + } + return next.invoke(msg); + } + + public void setNext(Invoker next) { + this.next = next; + } + + public Invoker getNext() { + return next; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallbackWireObjectFactory.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallbackWireObjectFactory.java new file mode 100644 index 0000000000..dae4ed708b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallbackWireObjectFactory.java @@ -0,0 +1,47 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.invocation; + +import java.util.List; + +import org.apache.tuscany.sca.factory.ObjectCreationException; +import org.apache.tuscany.sca.factory.ObjectFactory; +import org.apache.tuscany.sca.runtime.RuntimeWire; + +/** + * Returns proxy instance for a wire callback + * + * @version $Rev$ $Date$ + */ +public class CallbackWireObjectFactory implements ObjectFactory { + private ProxyFactory proxyFactory; + private Class interfaze; + private List wires; + + public CallbackWireObjectFactory(Class interfaze, ProxyFactory proxyService, List wires) { + this.interfaze = interfaze; + this.proxyFactory = proxyService; + this.wires = wires; + } + + public Object getInstance() throws ObjectCreationException { + return proxyFactory.createCallbackProxy(interfaze, wires); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ExtensibleWireProcessor.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ExtensibleWireProcessor.java new file mode 100644 index 0000000000..934f2f7aa0 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ExtensibleWireProcessor.java @@ -0,0 +1,44 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.invocation; + +import org.apache.tuscany.sca.runtime.RuntimeWire; +import org.apache.tuscany.sca.runtime.RuntimeWireProcessor; +import org.apache.tuscany.sca.runtime.RuntimeWireProcessorExtensionPoint; + +/** + * The default implementation of an extensible WireProcessor + * + * @version $Rev$ $Date$ + */ +public class ExtensibleWireProcessor implements RuntimeWireProcessor { + + private RuntimeWireProcessorExtensionPoint processors; + + public ExtensibleWireProcessor(RuntimeWireProcessorExtensionPoint processors) { + this.processors = processors; + } + + public void process(RuntimeWire wire) { + for (RuntimeWireProcessor processor : processors.getWireProcessors()) { + processor.process(wire); + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/InvocationChainImpl.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/InvocationChainImpl.java new file mode 100644 index 0000000000..e04148e374 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/InvocationChainImpl.java @@ -0,0 +1,126 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.invocation; + +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Interceptor; +import org.apache.tuscany.sca.invocation.InvocationChain; +import org.apache.tuscany.sca.invocation.Invoker; + +/** + * Default implementation of an invocation chain + * + * @version $Rev$ $Date$ + */ +public class InvocationChainImpl implements InvocationChain { + private Operation sourceOperation; + private Operation targetOperation; + private Invoker invokerChainHead; + private Invoker invokerChainTail; + + public InvocationChainImpl(Operation operation) { + assert operation != null; + this.targetOperation = operation; + this.sourceOperation = operation; + } + + public InvocationChainImpl(Operation sourceOperation, Operation targetOperation) { + assert sourceOperation != null; + assert targetOperation != null; + this.targetOperation = targetOperation; + this.sourceOperation = sourceOperation; + } + + public Operation getTargetOperation() { + return targetOperation; + } + + public void addInterceptor(Interceptor interceptor) { + if (invokerChainHead == null) { + invokerChainHead = interceptor; + } else { + if (invokerChainHead instanceof Interceptor) { + ((Interceptor)invokerChainTail).setNext(interceptor); + } + } + invokerChainTail = interceptor; + } + + public void addInvoker(Invoker invoker) { + if (invokerChainHead == null) { + invokerChainHead = invoker; + } else { + if (invokerChainTail instanceof Interceptor) { + ((Interceptor)invokerChainTail).setNext(invoker); + } + } + invokerChainTail = invoker; + } + + public Invoker getHeadInvoker() { + return invokerChainHead; + } + + public Invoker getTailInvoker() { + return invokerChainTail; + } + + /** + * @return the sourceOperation + */ + public Operation getSourceOperation() { + return sourceOperation; + } + + /** + * @param sourceOperation the sourceOperation to set + */ + public void setSourceOperation(Operation sourceOperation) { + this.sourceOperation = sourceOperation; + } + + public void addInterceptor(int index, Interceptor interceptor) { + int i = 0; + Invoker next = invokerChainHead; + Invoker prev = null; + while (next != null && i < index) { + prev = next; + if (next instanceof Interceptor) { + next = ((Interceptor)next).getNext(); + i++; + } else { + throw new ArrayIndexOutOfBoundsException(index); + } + } + if (i == index) { + if (prev != null) { + ((Interceptor)prev).setNext(interceptor); + } else { + invokerChainHead = interceptor; + } + interceptor.setNext(next); + if (next == null) { + invokerChainTail = interceptor; + } + } else { + throw new ArrayIndexOutOfBoundsException(index); + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/JDKCallbackInvocationHandler.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/JDKCallbackInvocationHandler.java new file mode 100644 index 0000000000..5a028e6e22 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/JDKCallbackInvocationHandler.java @@ -0,0 +1,95 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.invocation; + +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.HashMap; +import java.util.IdentityHashMap; +import java.util.List; +import java.util.Map; + +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.java.impl.JavaInterfaceUtil; +import org.apache.tuscany.sca.invocation.InvocationChain; +import org.apache.tuscany.sca.invocation.MessageFactory; +import org.apache.tuscany.sca.runtime.EndpointReference; +import org.apache.tuscany.sca.runtime.RuntimeWire; +import org.osoa.sca.NoRegisteredCallbackException; + +/** + * Responsible for dispatching to a callback through a wire.

TODO cache + * target invoker + * + * @version $Rev$ $Date$ + */ +public class JDKCallbackInvocationHandler extends AbstractInvocationHandler implements InvocationHandler { + private static final long serialVersionUID = -3350283555825935609L; + private transient Map wires; + + /** + * Constructor used for deserialization only + */ + public JDKCallbackInvocationHandler(MessageFactory messageFactory) { + super(messageFactory, false); + wires = new HashMap(); + } + + public JDKCallbackInvocationHandler(MessageFactory messageFactory, List wireList) { + super(messageFactory, false); + this.wires = new HashMap(); + for (RuntimeWire wire : wireList) { + wires.put(wire.getSource().getURI(), wire); + } + } + + @SuppressWarnings( {"unchecked"}) + public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + if (method.getParameterTypes().length == 0 && "toString".equals(method.getName())) { + return "[Proxy - " + Integer.toHexString(hashCode()) + "]"; + } else if (method.getDeclaringClass().equals(Object.class) && "equals".equals(method.getName())) { + // TODO implement + throw new UnsupportedOperationException(); + } else if (Object.class.equals(method.getDeclaringClass()) && "hashCode".equals(method.getName())) { + return hashCode(); + // TODO beter hash algorithm + } + EndpointReference from = ThreadMessageContext.getMessageContext().getFrom(); + RuntimeWire wire = wires.get(from.getURI()); + assert wire != null; + List chains = wire.getCallbackInvocationChains(); + IdentityHashMap map = new IdentityHashMap(); + for (InvocationChain chain : chains) { + map.put(chain.getTargetOperation(), chain); + } + Operation operation = JavaInterfaceUtil.findOperation(method, map.keySet()); + InvocationChain chain = map.get(operation); + try { + return invoke(chain, args, wire); + } catch (InvocationTargetException e) { + Throwable t = e.getCause(); + if (t instanceof NoRegisteredCallbackException) { + throw t; + } + throw e; + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/JDKInvocationHandler.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/JDKInvocationHandler.java new file mode 100644 index 0000000000..756e5c545f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/JDKInvocationHandler.java @@ -0,0 +1,115 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.core.invocation; + +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; +import java.lang.reflect.Proxy; +import java.util.List; + +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.InvocationChain; +import org.apache.tuscany.sca.invocation.MessageFactory; +import org.apache.tuscany.sca.runtime.RuntimeWire; + +/** + * @version $Rev$ $Date$ + */ +public class JDKInvocationHandler extends AbstractInvocationHandler implements InvocationHandler { + // private Class proxyInterface; + private RuntimeWire wire; + + public JDKInvocationHandler(MessageFactory messageFactory, Class proxyInterface, RuntimeWire wire) { + super(messageFactory, false); + this.wire = wire; + init(proxyInterface, wire); + } + + private void init(Class interfaze, RuntimeWire wire) { + InterfaceContract contract = wire.getSource().getInterfaceContract(); + this.conversational = contract.getInterface().isConversational(); + } + + public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { + if (method.getParameterTypes().length == 0 && "toString".equals(method.getName())) { + return "[Proxy - " + Integer.toHexString(hashCode()) + "]"; + } else if (method.getDeclaringClass().equals(Object.class) && "equals".equals(method.getName())) { + Object obj = args[0]; + if (obj == null) { + return false; + } + if (!Proxy.isProxyClass(obj.getClass())) { + return false; + } + return equals(Proxy.getInvocationHandler(obj)); + } else if (Object.class.equals(method.getDeclaringClass()) && "hashCode".equals(method.getName())) { + return hashCode(); + } + InvocationChain chain = getInvocationChain(method); + if (chain == null) { + throw new IllegalArgumentException("No matching opeeration is found: " + method); + } + + // send the invocation down the wire + Object result = invoke(chain, args, wire); + + return result; + } + + /** + * Determines if the given operation matches the given method + * + * @return true if the operation matches, false if does not + */ + private static boolean match(Operation operation, Method method) { + Class[] params = method.getParameterTypes(); + DataType> inputType = operation.getInputType(); + List types = inputType.getLogical(); + boolean matched = true; + if (types.size() == params.length && method.getName().equals(operation.getName())) { + for (int i = 0; i < params.length; i++) { + Class clazz = params[i]; + if (!clazz.equals(operation.getInputType().getLogical().get(i).getPhysical())) { + matched = false; + } + } + } else { + matched = false; + } + return matched; + + } + + private InvocationChain getInvocationChain(Method method) { + for (InvocationChain chain : wire.getInvocationChains()) { + Operation operation = chain.getSourceOperation(); + if (operation.isDynamic()) { + operation.setName(method.getName()); + return chain; + } else if (match(operation, method)) { + return chain; + } + } + return null; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/JDKProxyService.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/JDKProxyService.java new file mode 100644 index 0000000000..371f9bedb8 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/JDKProxyService.java @@ -0,0 +1,78 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.invocation; + +import java.lang.reflect.Proxy; +import java.util.List; + +import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; +import org.apache.tuscany.sca.interfacedef.impl.InterfaceContractMapperImpl; +import org.apache.tuscany.sca.invocation.MessageFactory; +import org.apache.tuscany.sca.runtime.RuntimeWire; +import org.osoa.sca.CallableReference; + +/** + * the default implementation of a wire service that uses JDK dynamic proxies + * + * @version $$Rev$$ $$Date: 2007-04-11 18:59:43 -0700 (Wed, 11 Apr + * 2007) $$ + */ +public class JDKProxyService implements ProxyFactory { + protected InterfaceContractMapper contractMapper; + private MessageFactory messageFactory; + + public JDKProxyService() { + this(new MessageFactoryImpl(), new InterfaceContractMapperImpl()); + } + + public JDKProxyService(MessageFactory messageFactory, InterfaceContractMapper mapper) { + this.contractMapper = mapper; + this.messageFactory = messageFactory; + } + + public T createProxy(Class interfaze, RuntimeWire wire) throws ProxyCreationException { + assert interfaze != null; + assert wire != null; + JDKInvocationHandler handler = new JDKInvocationHandler(messageFactory, interfaze, wire); + ClassLoader cl = interfaze.getClassLoader(); + return interfaze.cast(Proxy.newProxyInstance(cl, new Class[] {interfaze}, handler)); + } + + public Object createCallbackProxy(Class interfaze, List wires) throws ProxyCreationException { + ClassLoader cl = interfaze.getClassLoader(); + JDKCallbackInvocationHandler handler = new JDKCallbackInvocationHandler(messageFactory, wires); + return interfaze.cast(Proxy.newProxyInstance(cl, new Class[] {interfaze}, handler)); + } + + public > R cast(B target) throws IllegalArgumentException { + throw new UnsupportedOperationException(); + + // InvocationHandler handler = Proxy.getInvocationHandler(target); + // if (handler instanceof JDKInvocationHandler) { + // // TODO return a ServiceReference + // throw new UnsupportedOperationException(); + // } else if (handler instanceof JDKCallbackInvocationHandler) { + // // TODO return a CallbackReference + // throw new UnsupportedOperationException(); + // } else { + // throw new IllegalArgumentException("Not a Tuscany SCA proxy"); + // } + + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/MessageFactoryImpl.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/MessageFactoryImpl.java new file mode 100644 index 0000000000..6e182a6a14 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/MessageFactoryImpl.java @@ -0,0 +1,36 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.core.invocation; + +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.invocation.MessageFactory; + +/** + * Implementation of MessageFactory. + * + * @version $Rev$ $Date$ + */ +public class MessageFactoryImpl implements MessageFactory { + + public Message createMessage() { + return new MessageImpl(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/MessageImpl.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/MessageImpl.java new file mode 100644 index 0000000000..a1b2963cf5 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/MessageImpl.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.core.invocation; + +import org.apache.tuscany.sca.interfacedef.ConversationSequence; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.runtime.EndpointReference; + +/** + * The default implementation of a message flowed through a wire during an invocation + * + * @version $Rev $Date + */ +public class MessageImpl implements Message { + private Object body; + private Object messageID; + private Object correlationID; + private boolean isFault; + private ConversationSequence conversationSequence; + private String conversationId; + + private EndpointReference from; + private EndpointReference to; + + public MessageImpl(String conversationId, ConversationSequence conversationSequence, Object body) { + this.conversationId = conversationId; + this.conversationSequence = conversationSequence; + this.body = body; + } + + public MessageImpl() { + } + + @SuppressWarnings("unchecked") + public T getBody() { + return (T) body; + } + + public void setBody(T body) { + this.isFault = false; + this.body = body; + } + + public String getConversationID() { + return conversationId; + } + + public void setConversationID(String conversationId) { + this.conversationId = conversationId; + } + + public ConversationSequence getConversationSequence() { + return conversationSequence; + } + + public void setConversationSequence(ConversationSequence conversationSequence) { + this.conversationSequence = conversationSequence; + } + + public Object getMessageID() { + return messageID; + } + + public void setMessageID(Object messageId) { + this.messageID = messageId; + } + + public Object getCorrelationID() { + return correlationID; + } + + public void setCorrelationID(Object correlationId) { + this.correlationID = correlationId; + } + + public boolean isFault() { + return isFault; + } + + public void setFaultBody(Object fault) { + this.isFault = true; + this.body = fault; + } + + public EndpointReference getFrom() { + return from; + } + + public void setFrom(EndpointReference from) { + this.from = from; + } + + public EndpointReference getTo() { + return to; + } + + public void setTo(EndpointReference to) { + this.to = to; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/NoMethodForOperationException.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/NoMethodForOperationException.java new file mode 100644 index 0000000000..cbeedc086d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/NoMethodForOperationException.java @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.invocation; + + +/** + * Thrown when an {@link org.apache.tuscany.sca.factory.model.Operation} cannot be mapped to a method on an interface + * @version $Rev$ $Date$ + */ +public class NoMethodForOperationException extends ProxyCreationException { + private static final long serialVersionUID = 5116536602309483679L; + + public NoMethodForOperationException() { + } + + public NoMethodForOperationException(String message) { + super(message); + } + + public NoMethodForOperationException(String message, Throwable cause) { + super(message, cause); + } + + public NoMethodForOperationException(Throwable cause) { + super(cause); + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/NonBlockingInterceptor.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/NonBlockingInterceptor.java new file mode 100644 index 0000000000..be6f364271 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/NonBlockingInterceptor.java @@ -0,0 +1,174 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.invocation; + +import java.util.LinkedList; + +import org.apache.tuscany.sca.interfacedef.ConversationSequence; +import org.apache.tuscany.sca.invocation.Interceptor; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.runtime.EndpointReference; +import org.apache.tuscany.sca.runtime.RuntimeWire; +import org.apache.tuscany.sca.work.WorkScheduler; +import org.osoa.sca.ServiceRuntimeException; + +/** + * Adds non-blocking behavior to an invocation chain + * + * @version $$Rev$$ $$Date$$ + */ +public class NonBlockingInterceptor implements Interceptor { + + private static final Message RESPONSE = new ImmutableMessage(); + + private WorkScheduler workScheduler; + private Invoker next; + + public NonBlockingInterceptor(WorkScheduler workScheduler) { + this.workScheduler = workScheduler; + } + + public NonBlockingInterceptor(WorkScheduler workScheduler, Interceptor next) { + this.workScheduler = workScheduler; + this.next = next; + } + + public Message invoke(final Message msg) { + // Retrieve conversation id to transfer to new thread + // Notice that we cannot clear the conversation id from the current thread + final String conversationID = ThreadMessageContext.getMessageContext().getConversationID(); + // Schedule the invocation of the next interceptor in a new Work instance + try { + workScheduler.scheduleWork(new Runnable() { + public void run() { + msg.setCorrelationID(null); + // if we got a conversation id, transfer it to new thread + if (conversationID != null) { + msg.setConversationID(conversationID); + } + Message context = ThreadMessageContext.setMessageContext(msg); + try { + next.invoke(msg); + } finally { + ThreadMessageContext.setMessageContext(context); + } + } + }); + } catch (Exception e) { + throw new ServiceRuntimeException(e); + } + return RESPONSE; + } + + public Invoker getNext() { + return next; + } + + public void setNext(Invoker next) { + this.next = next; + } + + /** + * A dummy message passed back on an invocation + */ + private static class ImmutableMessage implements Message { + + public String getConversationID() { + return null; + } + + public RuntimeWire getWire() { + return null; + } + + public void setConversationID(String conversationId) { + throw new UnsupportedOperationException(); + } + + public void setWire(RuntimeWire wire) { + throw new UnsupportedOperationException(); + } + + @SuppressWarnings("unchecked") + public Object getBody() { + return null; + } + + public void setBody(Object body) { + if (body != null) { + throw new UnsupportedOperationException(); + } + } + + public void setCallbackWires(LinkedList wires) { + + } + + public Object getMessageID() { + return null; + } + + public void setMessageID(Object messageId) { + throw new UnsupportedOperationException(); + } + + public Object getCorrelationID() { + return null; + } + + public void setCorrelationID(Object correlationId) { + throw new UnsupportedOperationException(); + } + + public boolean isFault() { + return false; + } + + public void setFaultBody(Object fault) { + throw new UnsupportedOperationException(); + } + + public void setConversationSequence(ConversationSequence sequence) { + throw new UnsupportedOperationException(); + } + + public ConversationSequence getConversationSequence() { + return null; + } + + public EndpointReference getFrom() { + return null; + } + + public EndpointReference getTo() { + return null; + } + + public void setFrom(EndpointReference from) { + throw new UnsupportedOperationException(); + } + + public void setTo(EndpointReference to) { + throw new UnsupportedOperationException(); + } + + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ProxyCreationException.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ProxyCreationException.java new file mode 100644 index 0000000000..4900ae9a7e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ProxyCreationException.java @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.invocation; + +import org.apache.tuscany.sca.factory.ObjectCreationException; + + +/** + * Denotes an error creating a proxy + * + * @version $$Rev$$ $$Date$$ + */ +public class ProxyCreationException extends ObjectCreationException { + private static final long serialVersionUID = 8002454344828513781L; + + public ProxyCreationException() { + super(); + } + + public ProxyCreationException(String message, Throwable cause) { + super(message, cause); + } + + public ProxyCreationException(String message) { + super(message); + } + + public ProxyCreationException(Throwable cause) { + super(cause); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ProxyFactory.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ProxyFactory.java new file mode 100644 index 0000000000..381844ffc5 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ProxyFactory.java @@ -0,0 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.invocation; + +import java.util.List; + +import org.apache.tuscany.sca.runtime.RuntimeWire; +import org.osoa.sca.CallableReference; + +/** + * Creates proxies that implement Java interfaces and invocation handlers for fronting wires + * + * @version $$Rev$$ $$Date$$ + */ + +public interface ProxyFactory { + + /** + * Creates a Java proxy for the given wire + * + * @param interfaze the interface the proxy implements + * @param wire the wire to proxy @return the proxy + * @throws ProxyCreationException + */ + T createProxy(Class interfaze, RuntimeWire wire) throws ProxyCreationException; + + /** + * Creates a Java proxy for the service contract callback + * + * @param interfaze the interface the proxy should implement + * @return the proxy + * @throws ProxyCreationException + */ + Object createCallbackProxy(Class interfaze, List wires) throws ProxyCreationException; + + /** + * Cast a proxy to a CallableReference. + * + * @param target a proxy generated by this implementation + * @return a CallableReference (or subclass) equivalent to this prozy + * @throws IllegalArgumentException if the object supplied is not a proxy + */ + > R cast(B target) throws IllegalArgumentException; + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ThreadMessageContext.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ThreadMessageContext.java new file mode 100644 index 0000000000..52bea91341 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ThreadMessageContext.java @@ -0,0 +1,68 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.invocation; + +import org.apache.tuscany.sca.invocation.Message; + +/** + * Class for tunneling a WorkContext through the invocation of a user class. + * + * @version $Rev$ $Date$ + */ +public final class ThreadMessageContext { + + private static final ThreadLocal CONTEXT = new ThreadLocal() { + protected synchronized Message initialValue() { + return new MessageImpl(); + } + }; + + private ThreadMessageContext() { + } + + /** + * Set the WorkContext for the current thread. + * The current work context is returned and must be restored after the invocation is complete. + * Typical usage would be: + *

+     *   WorkContext old = PojoWorkContextTunnel.setThreadWorkContext(newContext);
+     *   try {
+     *      ... invoke user code ...
+     *   } finally {
+     *     PojoWorkContextTunnel.setThreadWorkContext(old);
+     *   }
+     * 
+ * @param context + * @return the current work context for the thread; this must be restored after the invocation is made + */ + public static Message setMessageContext(Message context) { + Message old = CONTEXT.get(); + CONTEXT.set(context); + return old; + } + + /** + * Returns the WorkContext for the current thread. + * + * @return the WorkContext for the current thread + */ + public static Message getMessageContext() { + return CONTEXT.get(); + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/WireObjectFactory.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/WireObjectFactory.java new file mode 100644 index 0000000000..e6e41e8f85 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/WireObjectFactory.java @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.invocation; + +import org.apache.tuscany.sca.factory.ObjectCreationException; +import org.apache.tuscany.sca.factory.ObjectFactory; +import org.apache.tuscany.sca.runtime.RuntimeWire; + +/** + * Uses a wire to return an object instance + * + * @version $Rev$ $Date$ + */ +public class WireObjectFactory implements ObjectFactory { + private Class interfaze; + private RuntimeWire wire; + private ProxyFactory proxyService; + private boolean optimizable; + + /** + * Constructor. + * + * @param interfaze the interface to inject on the client + * @param wire the backing wire + * @param proxyService the wire service to create the proxy + * @throws NoMethodForOperationException + */ + public WireObjectFactory(Class interfaze, RuntimeWire wire, ProxyFactory proxyService) + throws NoMethodForOperationException { + this.interfaze = interfaze; + this.wire = wire; + this.proxyService = proxyService; + } + + public T getInstance() throws ObjectCreationException { + return interfaze.cast(proxyService.createProxy(interfaze, wire)); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/ActivationException.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/ActivationException.java new file mode 100644 index 0000000000..987a8288b0 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/ActivationException.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.runtime; + + +/** + * Denotes an error starting the runtime + * + * @version $Rev$ $Date$ + */ +public class ActivationException extends Exception { + private static final long serialVersionUID = 8612661660934426123L; + + public ActivationException(String message) { + super(message); + } + + public ActivationException(Throwable cause) { + super(cause); + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/CompositeActivator.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/CompositeActivator.java new file mode 100644 index 0000000000..fc8a8f0a15 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/CompositeActivator.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.runtime; + +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.Composite; + +/** + * Start/stop a composite + * + * @version $Rev$ $Date$ + */ +public interface CompositeActivator { + + /** + * Activate a composite + * @param composite + */ + void activate(Composite composite) throws ActivationException; + + /** + * Stop a composite + * @param composite + */ + void deactivate(Composite composite) throws ActivationException; + + /** + * Start a composite + * @deprecated + * @param composite + */ + void start(Composite composite) throws ActivationException; + + /** + * Stop a composite + * @deprecated + * @param composite + */ + void stop(Composite composite) throws ActivationException; + + /** + * Start a component + * @param component + */ + void start(Component component) throws ActivationException; + + /** + * Stop a composite + * @param composite + */ + void stop(Component component) throws ActivationException; + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/CompositeActivatorImpl.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/CompositeActivatorImpl.java new file mode 100644 index 0000000000..9f5d2ab63d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/CompositeActivatorImpl.java @@ -0,0 +1,655 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.core.runtime; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.ComponentReference; +import org.apache.tuscany.sca.assembly.ComponentService; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.Implementation; +import org.apache.tuscany.sca.assembly.SCABinding; +import org.apache.tuscany.sca.assembly.SCABindingFactory; +import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException; +import org.apache.tuscany.sca.assembly.builder.CompositeBuilderMonitor; +import org.apache.tuscany.sca.assembly.builder.Problem; +import org.apache.tuscany.sca.assembly.builder.impl.CompositeBuilderImpl; +import org.apache.tuscany.sca.core.invocation.InvocationChainImpl; +import org.apache.tuscany.sca.core.invocation.NonBlockingInterceptor; +import org.apache.tuscany.sca.interfacedef.IncompatibleInterfaceContractException; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.InvocationChain; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.provider.BindingProviderFactory; +import org.apache.tuscany.sca.provider.ImplementationProvider; +import org.apache.tuscany.sca.provider.ImplementationProviderFactory; +import org.apache.tuscany.sca.provider.ProviderFactoryExtensionPoint; +import org.apache.tuscany.sca.provider.ReferenceBindingProvider; +import org.apache.tuscany.sca.provider.ServiceBindingProvider; +import org.apache.tuscany.sca.runtime.EndpointReference; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; +import org.apache.tuscany.sca.runtime.RuntimeWire; +import org.apache.tuscany.sca.runtime.RuntimeWireProcessor; +import org.apache.tuscany.sca.scope.ScopeRegistry; +import org.apache.tuscany.sca.scope.ScopedRuntimeComponent; +import org.apache.tuscany.sca.work.WorkScheduler; + +/** + * @version $Rev$ $Date$ + */ +public class CompositeActivatorImpl implements CompositeActivator { + + private final AssemblyFactory assemblyFactory; + private final SCABindingFactory scaBindingFactory; + private final InterfaceContractMapper interfaceContractMapper; + private final ScopeRegistry scopeRegistry; + private final WorkScheduler workScheduler; + private final RuntimeWireProcessor wireProcessor; + private final ProviderFactoryExtensionPoint providerFactories; + + /** + * @param assemblyFactory + * @param interfaceContractMapper + * @param workContext + * @param workScheduler + * @param wirePostProcessorRegistry + */ + public CompositeActivatorImpl(AssemblyFactory assemblyFactory, + SCABindingFactory scaBindingFactory, + InterfaceContractMapper interfaceContractMapper, + ScopeRegistry scopeRegistry, + WorkScheduler workScheduler, + RuntimeWireProcessor wireProcessor, + ProviderFactoryExtensionPoint providerFactories) { + super(); + this.assemblyFactory = assemblyFactory; + this.scaBindingFactory = scaBindingFactory; + this.interfaceContractMapper = interfaceContractMapper; + this.scopeRegistry = scopeRegistry; + this.workScheduler = workScheduler; + this.wireProcessor = wireProcessor; + this.providerFactories = providerFactories; + } + + /** + * Configure a composite + * + * @param composite + * @throws IncompatibleInterfaceContractException + */ + @SuppressWarnings("unchecked") + protected void configureComposite(Composite composite) throws IncompatibleInterfaceContractException { + for (Component component : composite.getComponents()) { + + for (ComponentService service : component.getServices()) { + for (Binding binding : service.getBindings()) { + BindingProviderFactory providerFactory = (BindingProviderFactory)providerFactories + .getProviderFactory(binding.getClass()); + if (providerFactory != null) { + ServiceBindingProvider bindingProvider = providerFactory + .createServiceBindingProvider((RuntimeComponent)component, + (RuntimeComponentService)service, + binding); + if (bindingProvider != null) { + ((RuntimeComponentService)service).setBindingProvider(binding, bindingProvider); + } + } else { + throw new IllegalStateException("Provider factory not found for class: " + binding.getClass() + .getName()); + } + } + } + for (ComponentReference reference : component.getReferences()) { + for (Binding binding : reference.getBindings()) { + BindingProviderFactory providerFactory = (BindingProviderFactory)providerFactories + .getProviderFactory(binding.getClass()); + if (providerFactory != null) { + ReferenceBindingProvider bindingProvider = providerFactory + .createReferenceBindingProvider((RuntimeComponent)component, + (RuntimeComponentReference)reference, + binding); + if (bindingProvider != null) { + ((RuntimeComponentReference)reference).setBindingProvider(binding, bindingProvider); + } + } else { + throw new IllegalStateException("Provider factory not found for class: " + binding.getClass() + .getName()); + } + } + } + + Implementation implementation = component.getImplementation(); + if (implementation instanceof Composite) { + configureComposite((Composite)implementation); + } else if (implementation != null) { + ImplementationProviderFactory providerFactory = (ImplementationProviderFactory)providerFactories + .getProviderFactory(implementation.getClass()); + if (providerFactory != null) { + ImplementationProvider implementationProvider = providerFactory + .createImplementationProvider((RuntimeComponent)component, implementation); + if (implementationProvider != null) { + ((RuntimeComponent)component).setImplementationProvider(implementationProvider); + } + } else { + throw new IllegalStateException("Provider factory not found for class: " + implementation + .getClass().getName()); + } + setScopeContainer(component); + } + } + } + + /** + * Start a composite + */ + protected void startComposite(Composite composite) { + for (Component component : composite.getComponents()) { + startComponent(component); + } + } + + /** + * Stop a composite + */ + public void stopComposite(Composite composite) { + for (Component component : composite.getComponents()) { + stopComponent(component); + + } + + } + + /** + * Start a component + */ + public void startComponent(Component component) { + + for (ComponentService service : component.getServices()) { + for (Binding binding : service.getBindings()) { + ServiceBindingProvider bindingProvider = ((RuntimeComponentService)service) + .getBindingProvider(binding); + if (bindingProvider != null) { + bindingProvider.start(); + } + } + } + for (ComponentReference reference : component.getReferences()) { + for (Binding binding : reference.getBindings()) { + ReferenceBindingProvider bindingProvider = ((RuntimeComponentReference)reference) + .getBindingProvider(binding); + if (bindingProvider != null) { + try { + bindingProvider.start(); + } catch (RuntimeException e) { + // TODO: [rfeng] Ignore the self reference if a runtime exception happens + if (!reference.getName().startsWith("$self$.")) { + throw e; + } + } + } + } + } + + Implementation implementation = component.getImplementation(); + if (implementation instanceof Composite) { + startComposite((Composite)implementation); + } else { + ImplementationProvider implementationProvider = ((RuntimeComponent)component) + .getImplementationProvider(); + if (implementationProvider != null) { + implementationProvider.start(); + } + } + + if (component instanceof ScopedRuntimeComponent) { + ScopedRuntimeComponent runtimeComponent = (ScopedRuntimeComponent)component; + if (runtimeComponent.getScopeContainer() != null) { + runtimeComponent.getScopeContainer().start(); + } + } + + } + + /** + * Stop a component + */ + public void stopComponent(Component component) { + for (ComponentService service : component.getServices()) { + for (Binding binding : service.getBindings()) { + ServiceBindingProvider bindingProvider = ((RuntimeComponentService)service) + .getBindingProvider(binding); + if (bindingProvider != null) { + bindingProvider.stop(); + } + } + } + for (ComponentReference reference : component.getReferences()) { + for (Binding binding : reference.getBindings()) { + ReferenceBindingProvider bindingProvider = ((RuntimeComponentReference)reference) + .getBindingProvider(binding); + if (bindingProvider != null) { + bindingProvider.stop(); + } + } + } + Implementation implementation = component.getImplementation(); + if (implementation instanceof Composite) { + stopComposite((Composite)implementation); + } else { + ImplementationProvider implementationProvider = ((RuntimeComponent)component) + .getImplementationProvider(); + if (implementationProvider != null) { + implementationProvider.stop(); + } + } + + if (component instanceof ScopedRuntimeComponent) { + ScopedRuntimeComponent runtimeComponent = (ScopedRuntimeComponent)component; + if (runtimeComponent.getScopeContainer() != null) { + runtimeComponent.getScopeContainer().stop(); + } + } + + } + + + /** + * Create runtime wires for the composite + * + * @param composite + * @throws IncompatibleInterfaceContractException + */ + protected void createRuntimeWires(Composite composite) throws IncompatibleInterfaceContractException { + for (Component component : composite.getComponents()) { + Implementation implementation = component.getImplementation(); + if (implementation instanceof Composite) { + // Recursively create runtime wires + createRuntimeWires((Composite)implementation); + } else { + // Create outbound wires for the component references + for (ComponentReference reference : component.getReferences()) { + for (Binding binding : reference.getBindings()) { + createWires(component, reference, binding); + } + } + // Create inbound wires for the component services + for (ComponentService service : component.getServices()) { + for (Binding binding : service.getBindings()) { + createWires(component, service, binding); + } + } + } + } + } + + /** + * Get the effective interface contract for a reference binding + * + * @param reference + * @param binding + * @return + */ + private InterfaceContract getInterfaceContract(ComponentReference reference, Binding binding) { + InterfaceContract interfaceContract = reference.getInterfaceContract(); + ReferenceBindingProvider provider = ((RuntimeComponentReference)reference).getBindingProvider(binding); + if (provider != null) { + InterfaceContract bindingContract = provider.getBindingInterfaceContract(); + if (bindingContract != null) { + interfaceContract = bindingContract; + } + } + return interfaceContract; + } + + /** + * Create the runtime wires for a reference binding + * + * @param component + * @param reference + * @param binding + */ + private void createWires(Component component, ComponentReference reference, Binding binding) { + if (!(reference instanceof RuntimeComponentReference)) { + return; + } + RuntimeComponentReference runtimeRef = (RuntimeComponentReference)reference; + InterfaceContract bindingContract = getInterfaceContract(reference, binding); + + if (!(binding instanceof SCABinding)) { + InterfaceContract sourceContract = reference.getInterfaceContract(); + + // Component Reference --> External Service + EndpointReference wireSource = new EndpointReferenceImpl((RuntimeComponent)component, + (RuntimeComponentReference)reference, binding, + sourceContract); + + EndpointReference wireTarget = new EndpointReferenceImpl(null, null, binding, bindingContract); + RuntimeWire wire = new RuntimeWireImpl(wireSource, wireTarget); + + for (Operation operation : sourceContract.getInterface().getOperations()) { + Operation targetOperation = interfaceContractMapper.map(bindingContract.getInterface(), operation); + InvocationChain chain = new InvocationChainImpl(operation, targetOperation); + if (operation.isNonBlocking()) { + chain.addInterceptor(new NonBlockingInterceptor(workScheduler)); + } + addBindingInterceptor(component, reference, binding, chain, operation, false); + wire.getInvocationChains().add(chain); + } + if (sourceContract.getCallbackInterface() != null) { + for (Operation operation : sourceContract.getCallbackInterface().getOperations()) { + Operation targetOperation = interfaceContractMapper.map(bindingContract.getCallbackInterface(), + operation); + InvocationChain chain = new InvocationChainImpl(operation, targetOperation); + if (operation.isNonBlocking()) { + chain.addInterceptor(new NonBlockingInterceptor(workScheduler)); + } + addBindingInterceptor(component, reference, binding, chain, operation, true); + wire.getCallbackInvocationChains().add(chain); + } + } + runtimeRef.getRuntimeWires().add(wire); + wireProcessor.process(wire); + // TODO: For non-SCA binding, how do we deal with targets? For now, assuming targets only apply to SCABinding + return; + } + for (ComponentService service : reference.getTargets()) { + Component target = null; + SCABinding scaBinding = service.getBinding(SCABinding.class); + if (scaBinding != null) { + target = scaBinding.getComponent(); + } + + // FIXME: [rfeng] Ignore unresolved services + if (service.isUnresolved()) { + continue; + } + + // FIXME: [rfeng] We might need a better way to get the impl interface contract + InterfaceContract targetContract = service.getService().getInterfaceContract(); + + EndpointReference wireSource = new EndpointReferenceImpl((RuntimeComponent)component, + (RuntimeComponentReference)reference, binding, + bindingContract); + + EndpointReference wireTarget = new EndpointReferenceImpl((RuntimeComponent)target, + (RuntimeComponentService)service, binding, + targetContract); + + RuntimeWire wire = new RuntimeWireImpl(wireSource, wireTarget); + + for (Operation operation : bindingContract.getInterface().getOperations()) { + Operation targetOperation = interfaceContractMapper.map(targetContract.getInterface(), operation); + InvocationChain chain = new InvocationChainImpl(operation, targetOperation); + if (operation.isNonBlocking()) { + chain.addInterceptor(new NonBlockingInterceptor(workScheduler)); + } + addBindingInterceptor(component, reference, binding, chain, operation, false); + if (target != null) { + addImplementationInterceptor(target, service, chain, targetOperation, false); + } + wire.getInvocationChains().add(chain); + } + if (bindingContract.getCallbackInterface() != null) { + if (reference.getName().startsWith("$self$.")) { + // No callback is needed + continue; + } + for (Operation operation : bindingContract.getCallbackInterface().getOperations()) { + Operation targetOperation = interfaceContractMapper.map(targetContract.getCallbackInterface(), + operation); + InvocationChain chain = new InvocationChainImpl(operation, targetOperation); + if (operation.isNonBlocking()) { + chain.addInterceptor(new NonBlockingInterceptor(workScheduler)); + } + addBindingInterceptor(component, reference, binding, chain, operation, true); + addImplementationInterceptor(component, null, chain, targetOperation, true); + wire.getCallbackInvocationChains().add(chain); + } + } + + runtimeRef.getRuntimeWires().add(wire); + if (!wire.getCallbackInvocationChains().isEmpty()) { + if (wire.getTarget().getContract() != null) { + ((RuntimeComponentService) wire.getTarget().getContract()).getCallbackWires().add(wire); + } + } + wireProcessor.process(wire); + } + } + + /** + * Get the effective interface contract for the service binding + * + * @param service + * @param binding + * @return + */ + private InterfaceContract getInterfaceContract(ComponentService service, Binding binding) { + InterfaceContract interfaceContract = service.getInterfaceContract(); + + ServiceBindingProvider provider = ((RuntimeComponentService)service).getBindingProvider(binding); + if (provider != null) { + InterfaceContract bindingContract = provider.getBindingInterfaceContract(); + if (bindingContract != null) { + interfaceContract = bindingContract; + } + } + return interfaceContract; + } + + /** + * Create runtime wires for a service binding + * + * @param component + * @param service + * @param binding + */ + private void createWires(Component component, ComponentService service, Binding binding) { + if (!(service instanceof RuntimeComponentService)) { + return; + } + RuntimeComponentService runtimeService = (RuntimeComponentService)service; + + // FIXME: [rfeng] We might need a better way to get the impl interface contract + InterfaceContract targetContract = service.getService().getInterfaceContract(); + + InterfaceContract sourceContract = getInterfaceContract(service, binding); + + EndpointReference wireSource = new EndpointReferenceImpl(null, null, binding, sourceContract); + + EndpointReference wireTarget = new EndpointReferenceImpl((RuntimeComponent)component, + (RuntimeComponentService)service, binding, + targetContract); + + RuntimeWire wire = new RuntimeWireImpl(wireSource, wireTarget); + + for (Operation operation : sourceContract.getInterface().getOperations()) { + Operation targetOperation = interfaceContractMapper.map(targetContract.getInterface(), operation); + InvocationChain chain = new InvocationChainImpl(operation, targetOperation); + /* lresende */ + if (operation.isNonBlocking()) { + chain.addInterceptor(new NonBlockingInterceptor(workScheduler)); + } + + addImplementationInterceptor(component, service, chain, targetOperation, false); + wire.getInvocationChains().add(chain); + } + // if (sourceContract.getCallbackInterface() != null) { + // for (Operation operation : + // sourceContract.getCallbackInterface().getOperations()) { + // Operation targetOperation = + // interfaceContractMapper.map(targetContract.getCallbackInterface(), + // operation); + // InvocationChain chain = new InvocationChainImpl(operation, + // targetOperation); + // if (operation.isNonBlocking()) { + // chain.addInterceptor(new NonBlockingInterceptor(workScheduler, + // workContext)); + // } + // addImplementationInterceptor(component, service, chain, operation, + // true); + // wire.getCallbackInvocationChains().add(chain); + // } + // } + + runtimeService.getRuntimeWires().add(wire); + wireProcessor.process(wire); + } + + /** + * Add the interceptor for a component implementation + * + * @param component + * @param service + * @param chain + * @param operation + * @param isCallback + */ + private void addImplementationInterceptor(Component component, + ComponentService service, + InvocationChain chain, + Operation operation, + boolean isCallback) { + ImplementationProvider provider = ((RuntimeComponent)component).getImplementationProvider(); + if (provider != null) { + Invoker invoker = null; + if (!isCallback) { + invoker = provider.createInvoker((RuntimeComponentService)service, operation); + } else { + invoker = provider.createCallbackInvoker(operation); + } + chain.addInvoker(invoker); + } + } + + /** + * Add the interceptor for a binding + * + * @param component + * @param reference + * @param binding + * @param chain + * @param operation + * @param isCallback + */ + private void addBindingInterceptor(Component component, + ComponentReference reference, + Binding binding, + InvocationChain chain, + Operation operation, + boolean isCallback) { + try { + ReferenceBindingProvider provider = ((RuntimeComponentReference)reference).getBindingProvider(binding); + if (provider != null) { + Invoker invoker = provider.createInvoker(operation, isCallback); + if (invoker != null) { + chain.addInvoker(invoker); + } + } + } catch (RuntimeException e) { + // TODO: [rfeng] Ignore the self reference if a runtime exception happens + if (!reference.getName().startsWith("$self$.")) { + throw e; + } + } + } + + private void setScopeContainer(Component component) { + if (!(component instanceof ScopedRuntimeComponent)) { + return; + } + ScopedRuntimeComponent runtimeComponent = (ScopedRuntimeComponent)component; + runtimeComponent.setScopeContainer(scopeRegistry.getScopeContainer(runtimeComponent)); + } + + protected void buildComposite(Composite composite) throws CompositeBuilderException { + + CompositeBuilderMonitor monitor = new CompositeBuilderMonitor() { + + public void problem(Problem problem) { + // Uncommenting the following two lines can be useful to detect + // and troubleshoot SCA assembly XML composite configuration + // problems. + + System.out.println("Composite assembly problem: " + problem.getMessage()); + } + }; + + CompositeBuilderImpl builder = new CompositeBuilderImpl(assemblyFactory, scaBindingFactory, interfaceContractMapper, monitor); + + builder.build(composite); + + // if (!problems.isEmpty()) { + // throw new VariantRuntimeException(new RuntimeException("Problems in + // the composite...")); + // } + } + + public void activate(Composite composite) throws ActivationException { + try { + buildComposite(composite); + configureComposite(composite); + createRuntimeWires(composite); + } catch (Exception e) { + throw new ActivationException(e); + } + } + + public void deactivate(Composite composite) throws ActivationException { + } + + public void start(Composite composite) throws ActivationException { + try { + startComposite(composite); + } catch (Exception e) { + throw new ActivationException(e); + } + } + + public void stop(Composite composite) throws ActivationException { + try{ + stopComposite(composite); + } catch(Exception e) { + throw new ActivationException(e); + } + } + + public void start(Component component) throws ActivationException { + try { + startComponent(component); + } catch (Exception e) { + throw new ActivationException(e); + } + + } + + public void stop(Component component) throws ActivationException { + try{ + stopComponent(component); + } catch(Exception e) { + throw new ActivationException(e); + } + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/EndpointReferenceImpl.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/EndpointReferenceImpl.java new file mode 100644 index 0000000000..233f81ccae --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/EndpointReferenceImpl.java @@ -0,0 +1,128 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.core.runtime; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.Contract; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.runtime.EndpointReference; +import org.apache.tuscany.sca.runtime.RuntimeComponent; + +/** + * @version $Rev$ $Date$ + */ +public class EndpointReferenceImpl implements EndpointReference { + private RuntimeComponent component; + private Contract contract; + private Binding binding; + private InterfaceContract interfaceContract; + private String uri; + + /** + * @param component + * @param contract + * @param binding + * @param interfaceContract + */ + public EndpointReferenceImpl(RuntimeComponent component, + Contract contract, + Binding binding, + InterfaceContract interfaceContract) { + super(); + this.component = component; + this.contract = contract; + this.binding = binding; + this.interfaceContract = interfaceContract; + this.uri = binding.getURI(); + } + + /** + * @param uri + */ + public EndpointReferenceImpl(String uri) { + super(); + this.uri = uri; + } + + public Binding getBinding() { + return binding; + } + + public void setBinding(Binding binding) { + this.binding = binding; + } + + public RuntimeComponent getComponent() { + return component; + } + + public void setComponent(RuntimeComponent component) { + this.component = component; + } + + public Contract getContract() { + return contract; + } + + public void setContract(Contract contract) { + this.contract = contract; + } + + public InterfaceContract getInterfaceContract() { + return interfaceContract; + } + + public void setInterfaceContract(InterfaceContract interfaceContract) { + this.interfaceContract = interfaceContract; + } + + public String getURI() { + return uri; + } + + public void setURI(String uri) { + this.uri = uri; + } + + @Override + public int hashCode() { + final int PRIME = 31; + int result = 1; + result = PRIME * result + ((uri == null) ? 0 : uri.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + final EndpointReferenceImpl other = (EndpointReferenceImpl)obj; + if (uri == null) { + if (other.uri != null) + return false; + } else if (!uri.equals(other.uri)) + return false; + return true; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/RuntimeAssemblyFactory.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/RuntimeAssemblyFactory.java new file mode 100644 index 0000000000..ec0cdadde6 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/RuntimeAssemblyFactory.java @@ -0,0 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.core.runtime; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.Component; +import org.apache.tuscany.sca.assembly.ComponentReference; +import org.apache.tuscany.sca.assembly.ComponentService; +import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory; +import org.apache.tuscany.sca.core.invocation.ProxyFactory; +import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; + +/** + * @version $Rev$ $Date$ + */ +public class RuntimeAssemblyFactory extends DefaultAssemblyFactory implements AssemblyFactory { + private final ProxyFactory proxyFactory; + private final InterfaceContractMapper interfaceContractMapper; + + /** + * @param proxyFactory + */ + public RuntimeAssemblyFactory(InterfaceContractMapper interfaceContractMapper, ProxyFactory proxyFactory) { + super(); + this.proxyFactory = proxyFactory; + this.interfaceContractMapper = interfaceContractMapper; + } + + @Override + public Component createComponent() { + return new RuntimeComponentImpl(proxyFactory); + } + + @Override + public ComponentReference createComponentReference() { + return new RuntimeComponentReferenceImpl(interfaceContractMapper); + } + + @Override + public ComponentService createComponentService() { + return new RuntimeComponentServiceImpl(interfaceContractMapper); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/RuntimeComponentImpl.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/RuntimeComponentImpl.java new file mode 100644 index 0000000000..aacce904b5 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/RuntimeComponentImpl.java @@ -0,0 +1,128 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.core.runtime; + +import java.util.List; + +import org.apache.tuscany.sca.assembly.ComponentReference; +import org.apache.tuscany.sca.assembly.Property; +import org.apache.tuscany.sca.assembly.impl.ComponentImpl; +import org.apache.tuscany.sca.core.component.ServiceReferenceImpl; +import org.apache.tuscany.sca.core.invocation.ProxyFactory; +import org.apache.tuscany.sca.core.invocation.WireObjectFactory; +import org.apache.tuscany.sca.provider.ImplementationProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.apache.tuscany.sca.runtime.RuntimeWire; +import org.apache.tuscany.sca.scope.ScopeContainer; +import org.apache.tuscany.sca.scope.ScopedRuntimeComponent; +import org.osoa.sca.CallableReference; +import org.osoa.sca.RequestContext; +import org.osoa.sca.ServiceReference; + +/** + * @version $Rev$ $Date$ + */ +public class RuntimeComponentImpl extends ComponentImpl implements RuntimeComponent, ScopedRuntimeComponent { + public static final String SELF_REFERENCE_PREFIX = "$self$."; + protected ImplementationProvider implementationProvider; + protected ProxyFactory proxyService; + protected ScopeContainer scopeContainer; + + /** + * @param proxyService + */ + public RuntimeComponentImpl(ProxyFactory proxyService) { + super(); + this.proxyService = proxyService; + } + + public ServiceReference createSelfReference(Class businessInterface) { + return getServiceReference(businessInterface, SELF_REFERENCE_PREFIX); + } + + public ServiceReference createSelfReference(Class businessInterface, String serviceName) { + return getServiceReference(businessInterface, SELF_REFERENCE_PREFIX + serviceName); + } + + public B getProperty(Class type, String propertyName) { + for (Property p : getProperties()) { + if (p.getName().equals(propertyName)) { + // FIXME: Need to use the property object factory to create the + // instance + return null; + } + } + return null; + } + + public RequestContext getRequestContext() { + return null; + } + + public B getService(Class businessInterface, String referenceName) { + List refs = getReferences(); + for (ComponentReference ref : refs) { + if (ref.getName().equals(referenceName)) { + RuntimeComponentReference attachPoint = (RuntimeComponentReference)ref; + RuntimeWire wire = attachPoint.getRuntimeWires().get(0); + return proxyService.createProxy(businessInterface, wire); + } + } + return null; + } + + public ServiceReference getServiceReference(Class businessInterface, String referenceName) { + List references = getReferences(); + for (ComponentReference reference : references) { + if (reference.getName().equals(referenceName) || referenceName.equals("$self$.") + && reference.getName().startsWith(referenceName)) { + RuntimeComponentReference attachPoint = (RuntimeComponentReference)reference; + RuntimeWire wire = attachPoint.getRuntimeWires().get(0); + WireObjectFactory factory = new WireObjectFactory(businessInterface, wire, proxyService); + return new ServiceReferenceImpl(businessInterface, factory); + } + } + return null; + + } + + @SuppressWarnings("unchecked") + public > R cast(B target) throws IllegalArgumentException { + Object ref = proxyService.cast(target); + return (R)ref; + } + + public ImplementationProvider getImplementationProvider() { + return implementationProvider; + } + + public void setImplementationProvider(ImplementationProvider provider) { + this.implementationProvider = provider; + } + + public ScopeContainer getScopeContainer() { + return scopeContainer; + } + + public void setScopeContainer(ScopeContainer scopeContainer) { + this.scopeContainer = scopeContainer; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/RuntimeComponentReferenceImpl.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/RuntimeComponentReferenceImpl.java new file mode 100644 index 0000000000..128ae29b81 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/RuntimeComponentReferenceImpl.java @@ -0,0 +1,86 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.core.runtime; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.impl.ComponentReferenceImpl; +import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.InvocationChain; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.provider.ReferenceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.apache.tuscany.sca.runtime.RuntimeWire; + +public class RuntimeComponentReferenceImpl extends ComponentReferenceImpl implements RuntimeComponentReference { + private List wires = new ArrayList(); + private Map bindingProviders = new HashMap(); + private InterfaceContractMapper mapper; + + public RuntimeComponentReferenceImpl(InterfaceContractMapper mapper) { + super(); + this.mapper = mapper; + } + + public void addRuntimeWire(RuntimeWire wire) { + wires.add(wire); + } + + public List getRuntimeWires() { + return wires; + } + + public RuntimeWire getRuntimeWire(Binding binding) { + for (RuntimeWire wire : wires) { + if (wire.getSource().getBinding() == binding) { + return wire; + } + } + return null; + } + + public ReferenceBindingProvider getBindingProvider(Binding binding) { + return bindingProviders.get(binding); + } + + public void setBindingProvider(Binding binding, ReferenceBindingProvider bindingProvider) { + bindingProviders.put(binding, bindingProvider); + } + + public Invoker getInvoker(Binding binding, Operation operation) { + RuntimeWire wire = getRuntimeWire(binding); + if (wire == null) { + return null; + } + for (InvocationChain chain : wire.getInvocationChains()) { + Operation op = chain.getSourceOperation(); + if (mapper.isCompatible(operation, op, op.getInterface().isRemotable())) { + return chain.getHeadInvoker(); + } + } + return null; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/RuntimeComponentServiceImpl.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/RuntimeComponentServiceImpl.java new file mode 100644 index 0000000000..0bb8e2c457 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/RuntimeComponentServiceImpl.java @@ -0,0 +1,109 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.core.runtime; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.assembly.impl.ComponentServiceImpl; +import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.InvocationChain; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.provider.ServiceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; +import org.apache.tuscany.sca.runtime.RuntimeWire; + +public class RuntimeComponentServiceImpl extends ComponentServiceImpl implements RuntimeComponentService { + private InterfaceContractMapper mapper; + + public RuntimeComponentServiceImpl(InterfaceContractMapper mapper) { + super(); + this.mapper = mapper; + } + + private List wires = new ArrayList(); + private List callbackWires = new ArrayList(); + private Map bindingProviders = new HashMap(); + + public void addRuntimeWire(RuntimeWire wire) { + wires.add(wire); + } + + public List getRuntimeWires() { + return wires; + } + + public RuntimeWire getRuntimeWire(Binding binding) { + for (RuntimeWire wire : wires) { + if (wire.getTarget().getBinding() == binding) { + return wire; + } + } + return null; + } + + public List getCallbackWires() { + return callbackWires; + } + + public void addCallbackWire(RuntimeWire callbackWire) { + this.callbackWires.add(callbackWire); + } + + public ServiceBindingProvider getBindingProvider(Binding binding) { + return bindingProviders.get(binding); + } + + public void setBindingProvider(Binding binding, ServiceBindingProvider bindingProvider) { + bindingProviders.put(binding, bindingProvider); + } + + public Invoker getInvoker(Binding binding, Operation operation) { + RuntimeWire wire = getRuntimeWire(binding); + if (wire == null) { + return null; + } + for (InvocationChain chain : wire.getInvocationChains()) { + Operation op = chain.getTargetOperation(); + if (mapper.isCompatible(operation, op, op.getInterface().isRemotable())) { + return chain.getHeadInvoker(); + } + } + return null; + } + + public Invoker getCallbackInvoker(Binding binding, Operation operation) { + for (RuntimeWire wire : callbackWires) { + if (wire.getTarget().getBinding() == binding) { + for (InvocationChain chain : wire.getCallbackInvocationChains()) { + Operation op = chain.getSourceOperation(); + if (mapper.isCompatible(operation, op, op.getInterface().isRemotable())) { + return chain.getHeadInvoker(); + } + } + } + } + return null; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/RuntimeSCABindingProvider.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/RuntimeSCABindingProvider.java new file mode 100644 index 0000000000..ad055731f3 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/RuntimeSCABindingProvider.java @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.core.runtime; + +import org.apache.tuscany.sca.assembly.SCABinding; +import org.apache.tuscany.sca.interfacedef.InterfaceContract; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.provider.ReferenceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; + +/** + * @version $Rev$ $Date$ + */ +public class RuntimeSCABindingProvider implements ReferenceBindingProvider { + + private RuntimeComponentReference reference; + + public RuntimeSCABindingProvider(RuntimeComponent component, RuntimeComponentReference reference, SCABinding binding) { + this.reference = reference; + } + + public InterfaceContract getBindingInterfaceContract() { + return reference.getInterfaceContract(); + } + + public Invoker createInvoker(Operation operation, boolean isCallback) { + return null; + } + + public void start() { + } + + public void stop() { + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/RuntimeSCABindingProviderFactory.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/RuntimeSCABindingProviderFactory.java new file mode 100644 index 0000000000..06b7b3d40e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/RuntimeSCABindingProviderFactory.java @@ -0,0 +1,51 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.core.runtime; + +import org.apache.tuscany.sca.assembly.SCABinding; +import org.apache.tuscany.sca.provider.BindingProviderFactory; +import org.apache.tuscany.sca.provider.ReferenceBindingProvider; +import org.apache.tuscany.sca.provider.ServiceBindingProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.runtime.RuntimeComponentReference; +import org.apache.tuscany.sca.runtime.RuntimeComponentService; + +/** + * @version $Rev$ $Date$ + */ +public class RuntimeSCABindingProviderFactory implements BindingProviderFactory { + + public ReferenceBindingProvider createReferenceBindingProvider(RuntimeComponent component, + RuntimeComponentReference reference, + SCABinding binding) { + return new RuntimeSCABindingProvider(component, reference, binding); + } + + public ServiceBindingProvider createServiceBindingProvider(RuntimeComponent component, + RuntimeComponentService service, + SCABinding binding) { + return null; + } + + public Class getModelType() { + return SCABinding.class; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/RuntimeWireImpl.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/RuntimeWireImpl.java new file mode 100644 index 0000000000..cdf7ec01c0 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/runtime/RuntimeWireImpl.java @@ -0,0 +1,66 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.core.runtime; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.sca.invocation.InvocationChain; +import org.apache.tuscany.sca.runtime.EndpointReference; +import org.apache.tuscany.sca.runtime.RuntimeWire; + +/** + * @version $Rev$ $Date$ + */ +public class RuntimeWireImpl implements RuntimeWire { + private EndpointReference wireSource; + private EndpointReference wireTarget; + + private final List chains = new ArrayList(); + private final List callbackChains = new ArrayList(); + + /** + * @param source + * @param target + */ + public RuntimeWireImpl(EndpointReference source, + EndpointReference target) { + super(); + this.wireSource = source; + this.wireTarget = target; + } + + public List getCallbackInvocationChains() { + return callbackChains; + } + + public List getInvocationChains() { + return chains; + } + + public EndpointReference getSource() { + return wireSource; + } + + public EndpointReference getTarget() { + return wireTarget; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/AbstractScopeContainer.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/AbstractScopeContainer.java new file mode 100644 index 0000000000..1d776b729c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/AbstractScopeContainer.java @@ -0,0 +1,146 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.scope; + +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +import org.apache.tuscany.sca.event.Event; +import org.apache.tuscany.sca.provider.ImplementationProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.scope.AbstractLifecycle; +import org.apache.tuscany.sca.scope.InstanceWrapper; +import org.apache.tuscany.sca.scope.PersistenceException; +import org.apache.tuscany.sca.scope.Scope; +import org.apache.tuscany.sca.scope.ScopeContainer; +import org.apache.tuscany.sca.scope.ScopedImplementationProvider; +import org.apache.tuscany.sca.scope.TargetDestructionException; +import org.apache.tuscany.sca.scope.TargetResolutionException; + +/** + * Implements functionality common to scope contexts. + * + * @version $Rev$ $Date$ + */ +public abstract class AbstractScopeContainer extends AbstractLifecycle implements ScopeContainer { + protected Map> wrappers = new ConcurrentHashMap>(); + protected final Scope scope; + + protected RuntimeComponent component; + + public AbstractScopeContainer(Scope scope, RuntimeComponent component) { + this.scope = scope; + this.component = component; + } + + protected void checkInit() { + if (getLifecycleState() != RUNNING) { + throw new IllegalStateException("Scope container not running [" + getLifecycleState() + "]"); + } + } + + /** + * Creates a new physical instance of a component, wrapped in an + * InstanceWrapper. + * + * @param component the component whose instance should be created + * @return a wrapped instance that has been injected but not yet started + * @throws TargetResolutionException if there was a problem creating the + * instance + */ + protected InstanceWrapper createInstanceWrapper() throws TargetResolutionException { + ImplementationProvider implementationProvider = component.getImplementationProvider(); + if (implementationProvider instanceof ScopedImplementationProvider) { + return ((ScopedImplementationProvider)implementationProvider).createInstanceWrapper(); + } + return null; + } + + public InstanceWrapper getAssociatedWrapper(KEY contextId) throws TargetResolutionException { + return null; + } + + public Scope getScope() { + return scope; + } + + public InstanceWrapper getWrapper(KEY contextId) throws TargetResolutionException { + return wrappers.get(contextId); + } + + public void onEvent(Event event) { + } + + protected boolean isEagerInit() { + ImplementationProvider implementationProvider = ((RuntimeComponent)component).getImplementationProvider(); + if (implementationProvider instanceof ScopedImplementationProvider) { + return ((ScopedImplementationProvider)implementationProvider).isEagerInit(); + } + return false; + } + + public void remove() throws PersistenceException { + throw new UnsupportedOperationException("Scope does not support persistence"); + } + + public void returnWrapper(InstanceWrapper wrapper, KEY contextId) throws TargetDestructionException { + } + + public synchronized void start() { + int lifecycleState = getLifecycleState(); + if (lifecycleState != UNINITIALIZED && lifecycleState != STOPPED) { + throw new IllegalStateException("Scope must be in UNINITIALIZED or STOPPED state [" + lifecycleState + "]"); + } + setLifecycleState(RUNNING); + } + + public void startContext(KEY contextId) { + if(isEagerInit()) { + try { + getWrapper(contextId); + } catch (TargetResolutionException e) { + // + } + } + } + + public synchronized void stop() { + int lifecycleState = getLifecycleState(); + if (lifecycleState != RUNNING) { + throw new IllegalStateException("Scope in wrong state [" + lifecycleState + "]"); + } + setLifecycleState(STOPPED); + } + + public void stopContext(KEY contextId) { + wrappers.remove(contextId); + } + + public String toString() { + return "In state [" + super.toString() + ']'; + } + + public RuntimeComponent getComponent() { + return component; + } + + public void setComponent(RuntimeComponent component) { + this.component = component; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/CompositeScopeContainer.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/CompositeScopeContainer.java new file mode 100644 index 0000000000..520d3ab48c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/CompositeScopeContainer.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.scope; + +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.scope.InstanceWrapper; +import org.apache.tuscany.sca.scope.Scope; +import org.apache.tuscany.sca.scope.TargetNotFoundException; +import org.apache.tuscany.sca.scope.TargetResolutionException; + +/** + * A scope context which manages atomic component instances keyed by composite + * + * @version $Rev$ $Date$ + */ +public class CompositeScopeContainer extends AbstractScopeContainer { + private InstanceWrapper wrapper; + + public CompositeScopeContainer(RuntimeComponent component) { + super(Scope.COMPOSITE, component); + } + + public synchronized void stop() { + super.stop(); + wrapper = null; + } + + public InstanceWrapper getWrapper(KEY contextId) throws TargetResolutionException { + if (wrapper == null) { + wrapper = createInstanceWrapper(); + wrapper.start(); + } + return wrapper; + } + + public InstanceWrapper getAssociatedWrapper(KEY contextId) throws TargetResolutionException { + if (wrapper == null) { + throw new TargetNotFoundException(component.getURI()); + } + return wrapper; + } + + @Override + public synchronized void start() { + super.start(); + if(isEagerInit()) { + try { + getWrapper(null); + } catch (TargetResolutionException e) { + throw new IllegalStateException(e); + } + } + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/CompositeScopeContainerFactory.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/CompositeScopeContainerFactory.java new file mode 100644 index 0000000000..7078903b8b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/CompositeScopeContainerFactory.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.core.scope; + +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.scope.Scope; +import org.apache.tuscany.sca.scope.ScopeContainer; +import org.apache.tuscany.sca.scope.ScopeContainerFactory; + +/** + * @version $Rev$ $Date$ + */ +public class CompositeScopeContainerFactory implements ScopeContainerFactory { + + public ScopeContainer createScopeContainer(RuntimeComponent component) { + return new CompositeScopeContainer(component); + } + + public Scope getScope() { + return Scope.COMPOSITE; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ConversationalScopeContainer.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ConversationalScopeContainer.java new file mode 100644 index 0000000000..61f7d51c29 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ConversationalScopeContainer.java @@ -0,0 +1,182 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.scope; + +import org.apache.tuscany.sca.core.invocation.ThreadMessageContext; +import org.apache.tuscany.sca.event.Event; +import org.apache.tuscany.sca.event.RuntimeEventListener; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.scope.InstanceWrapper; +import org.apache.tuscany.sca.scope.PersistenceException; +import org.apache.tuscany.sca.scope.Scope; +import org.apache.tuscany.sca.scope.ScopeContainer; +import org.apache.tuscany.sca.scope.TargetDestructionException; +import org.apache.tuscany.sca.scope.TargetResolutionException; +import org.apache.tuscany.sca.store.Store; +import org.apache.tuscany.sca.store.StoreExpirationEvent; + +/** + * A scope context which manages atomic component instances keyed on a + * conversation session + * + * @version $Rev: 452655 $ $Date: 2006-10-03 18:09:02 -0400 (Tue, 03 Oct 2006) $ + */ +public class ConversationalScopeContainer extends AbstractScopeContainer implements ScopeContainer { + private final Store nonDurableStore; + + public ConversationalScopeContainer(Store store, RuntimeComponent component) { + super(Scope.CONVERSATION, component); + this.nonDurableStore = store; + if (store != null) { + store.addListener(new ExpirationListener()); + } + } + + public void onEvent(Event event) { + checkInit(); + } + + public synchronized void start() { + if (lifecycleState != UNINITIALIZED && lifecycleState != STOPPED) { + throw new IllegalStateException("Scope must be in UNINITIALIZED or STOPPED state [" + lifecycleState + "]"); + } + lifecycleState = RUNNING; + } + + public synchronized void stop() { + lifecycleState = STOPPED; + } + + public void persistNew(RuntimeComponent component, String id, Object instance, long expiration) + throws PersistenceException { + // try { + // nonDurableStore.insertRecord(component, id, instance, expiration); + // } catch (StoreWriteException e) { + // throw new PersistenceException(e); + // } + } + + public void persist(RuntimeComponent component, String id, Object instance, long expiration) + throws PersistenceException { + // try { + // nonDurableStore.updateRecord(component, id, instance, expiration); + // } catch (StoreWriteException e) { + // throw new PersistenceException(e); + // } + } + + public void remove(RuntimeComponent component) throws PersistenceException { + // String conversationId = getConversationId(); + // try { + // workContext.setCurrentAtomicComponent(component); + // // FIXME this should be an InstanceWrapper and shouldn't we stop it? + // Object instance = nonDurableStore.readRecord(component, + // conversationId); + // if (instance != null) { + // nonDurableStore.removeRecord(component, conversationId); + // } + // } catch (StoreReadException e) { + // throw new PersistenceException(e); + // } catch (StoreWriteException e) { + // throw new PersistenceException(e); + // } + } + + protected InstanceWrapper getInstanceWrapper(RuntimeComponent component, boolean create) + throws TargetResolutionException { + throw new UnsupportedOperationException("To be implemented"); + // String conversationId = getConversationId(); + // try { + // workContext.setCurrentAtomicComponent(component); + // InstanceWrapper wrapper = (InstanceWrapper) + // nonDurableStore.readRecord(component, conversationId); + // if (wrapper != null) { + // if (component.getMaxIdleTime() > 0) { + // // update expiration + // long expire = System.currentTimeMillis() + + // component.getMaxIdleTime(); + // nonDurableStore.updateRecord(component, conversationId, wrapper, + // expire); + // } + // } else if (create) { + // // FIXME should the store really be persisting the wrappers + // wrapper = component.createInstanceWrapper(); + // wrapper.start(); + // long expire = calculateExpiration(component); + // nonDurableStore.insertRecord(component, conversationId, wrapper, + // expire); + // } + // return wrapper; + // } catch (StoreReadException e) { + // throw new TargetResolutionException("Error retrieving target + // instance", e); + // } catch (StoreWriteException e) { + // throw new TargetResolutionException("Error persisting target + // instance", e); + // } finally { + // workContext.setCurrentAtomicComponent(null); + // } + } + + /** + * Returns the conversation id associated with the current invocation + * context + * + * @return the conversation id + */ + private String getConversationId() { + String conversationId = ThreadMessageContext.getMessageContext().getConversationID(); + assert conversationId != null; + return conversationId; + } + + // private long calculateExpiration(RuntimeComponent component) { + // if (component.getMaxAge() > 0) { + // long now = System.currentTimeMillis(); + // return now + component.getMaxAge(); + // } else if (component.getMaxIdleTime() > 0) { + // long now = System.currentTimeMillis(); + // return now + component.getMaxIdleTime(); + // } else { + // return Store.DEFAULT_EXPIRATION_OFFSET; + // } + // } + + /** + * Receives expiration events from the store and notifies the corresponding + * atomic component + */ + private static class ExpirationListener implements RuntimeEventListener { + + public ExpirationListener() { + } + + public void onEvent(Event event) { + if (event instanceof StoreExpirationEvent) { + StoreExpirationEvent expiration = (StoreExpirationEvent)event; + InstanceWrapper wrapper = (InstanceWrapper)expiration.getInstance(); + try { + wrapper.stop(); + } catch (TargetDestructionException e) { + // monitor.destructionError(e); + } + } + } + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ConversationalScopeContainerFactory.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ConversationalScopeContainerFactory.java new file mode 100644 index 0000000000..4fdda90bc2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ConversationalScopeContainerFactory.java @@ -0,0 +1,47 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.core.scope; + +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.scope.Scope; +import org.apache.tuscany.sca.scope.ScopeContainer; +import org.apache.tuscany.sca.scope.ScopeContainerFactory; +import org.apache.tuscany.sca.store.Store; + +/** + * @version $Rev$ $Date$ + */ +public class ConversationalScopeContainerFactory implements ScopeContainerFactory { + private Store store; + + public ConversationalScopeContainerFactory(Store store) { + super(); + this.store = store; + } + + public ScopeContainer createScopeContainer(RuntimeComponent component) { + return new ConversationalScopeContainer(store, component); + } + + public Scope getScope() { + return Scope.CONVERSATION; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/HttpSessionScopeContainer.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/HttpSessionScopeContainer.java new file mode 100644 index 0000000000..bcbf3cdf3c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/HttpSessionScopeContainer.java @@ -0,0 +1,81 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.scope; + +import org.apache.tuscany.sca.core.event.HttpSessionEnd; +import org.apache.tuscany.sca.event.Event; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.scope.InstanceWrapper; +import org.apache.tuscany.sca.scope.Scope; +import org.apache.tuscany.sca.scope.TargetResolutionException; + +/** + * A scope context which manages atomic component instances keyed on HTTP + * session + * + * @version $Rev$ $Date$ + */ +public class HttpSessionScopeContainer extends AbstractScopeContainer { + + public HttpSessionScopeContainer(RuntimeComponent component) { + super(Scope.SESSION, component); + } + + public void onEvent(Event event) { + checkInit(); + if (event instanceof HttpSessionEnd) { + Object key = ((HttpSessionEnd)event).getSessionID(); + // FIXME: Remove the session id + } + } + + public synchronized void start() { + if (lifecycleState != UNINITIALIZED && lifecycleState != STOPPED) { + throw new IllegalStateException("Scope must be in UNINITIALIZED or STOPPED state [" + lifecycleState + "]"); + } + lifecycleState = RUNNING; + } + + public synchronized void stop() { + lifecycleState = STOPPED; + } + + protected InstanceWrapper getInstanceWrapper(boolean create) throws TargetResolutionException { +// Object key = workContext.getIdentifier(Scope.SESSION); + // FIXME: Need to fix this + Object key ="http-session-id"; + assert key != null : "HTTP session key not bound in work context"; + InstanceWrapper ctx = wrappers.get(key); + if (ctx == null && !create) { + return null; + } + if (ctx == null) { + ctx = super.createInstanceWrapper(); + ctx.start(); + wrappers.put(key, ctx); + } + return ctx; + } + + @Override + public InstanceWrapper getWrapper(Object contextId) throws TargetResolutionException { + return getInstanceWrapper(true); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/HttpSessionScopeContainerFactory.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/HttpSessionScopeContainerFactory.java new file mode 100644 index 0000000000..e275bb56b9 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/HttpSessionScopeContainerFactory.java @@ -0,0 +1,44 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.core.scope; + +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.scope.Scope; +import org.apache.tuscany.sca.scope.ScopeContainer; +import org.apache.tuscany.sca.scope.ScopeContainerFactory; + +/** + * @version $Rev$ $Date$ + */ +public class HttpSessionScopeContainerFactory implements ScopeContainerFactory { + + public HttpSessionScopeContainerFactory() { + super(); + } + + public ScopeContainer createScopeContainer(RuntimeComponent component) { + return new HttpSessionScopeContainer(component); + } + + public Scope getScope() { + return Scope.SESSION; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/RequestScopeContainer.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/RequestScopeContainer.java new file mode 100644 index 0000000000..aaafb4603c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/RequestScopeContainer.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.core.scope; + +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +import org.apache.tuscany.sca.core.event.RequestEnd; +import org.apache.tuscany.sca.event.Event; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.scope.InstanceWrapper; +import org.apache.tuscany.sca.scope.Scope; +import org.apache.tuscany.sca.scope.TargetResolutionException; + +/** + * A scope context which manages atomic component instances keyed on the current + * request context + * + * @version $Rev$ $Date$ + */ +public class RequestScopeContainer extends AbstractScopeContainer { + private final Map contexts; + + public RequestScopeContainer(RuntimeComponent component) { + super(Scope.REQUEST, component); + contexts = new ConcurrentHashMap(); + } + + public void onEvent(Event event) { + checkInit(); + if (event instanceof RequestEnd) { + // shutdownInstances(Thread.currentThread()); + } + } + + public synchronized void start() { + if (lifecycleState != UNINITIALIZED && lifecycleState != STOPPED) { + throw new IllegalStateException("Scope must be in UNINITIALIZED or STOPPED state [" + lifecycleState + "]"); + } + lifecycleState = RUNNING; + } + + public synchronized void stop() { + contexts.clear(); + // synchronized (destroyQueues) { + // destroyQueues.clear(); + // } + lifecycleState = STOPPED; + } + + protected InstanceWrapper getInstanceWrapper(boolean create) throws TargetResolutionException { + InstanceWrapper ctx = wrappers.get(Thread.currentThread()); + if (ctx == null && !create) { + return null; + } + if (ctx == null) { + ctx = super.createInstanceWrapper(); + ctx.start(); + wrappers.put(Thread.currentThread(), ctx); + } + return ctx; + } + + @Override + public InstanceWrapper getWrapper(Thread contextId) throws TargetResolutionException { + return getInstanceWrapper(true); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/RequestScopeContainerFactory.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/RequestScopeContainerFactory.java new file mode 100644 index 0000000000..3851637220 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/RequestScopeContainerFactory.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.core.scope; + +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.scope.Scope; +import org.apache.tuscany.sca.scope.ScopeContainer; +import org.apache.tuscany.sca.scope.ScopeContainerFactory; + +/** + * @version $Rev$ $Date$ + */ +public class RequestScopeContainerFactory implements ScopeContainerFactory { + + public ScopeContainer createScopeContainer(RuntimeComponent component) { + return new RequestScopeContainer(component); + } + + public Scope getScope() { + return Scope.REQUEST; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ScopeRegistryImpl.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ScopeRegistryImpl.java new file mode 100644 index 0000000000..774c1edf37 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ScopeRegistryImpl.java @@ -0,0 +1,68 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.scope; + +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +import org.apache.tuscany.sca.provider.ImplementationProvider; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.scope.Scope; +import org.apache.tuscany.sca.scope.ScopeContainer; +import org.apache.tuscany.sca.scope.ScopeContainerFactory; +import org.apache.tuscany.sca.scope.ScopeRegistry; +import org.apache.tuscany.sca.scope.ScopedImplementationProvider; +import org.apache.tuscany.sca.scope.ScopedRuntimeComponent; + +/** + * The default implementation of a scope registry + * + * @version $Rev$ $Date$ + */ +public class ScopeRegistryImpl implements ScopeRegistry { + private final Map scopeCache = new ConcurrentHashMap(); + + public void register(ScopeContainerFactory factory) { + scopeCache.put(factory.getScope(), factory); + } + + public ScopeContainer getScopeContainer(RuntimeComponent runtimeComponent) { + if (!(runtimeComponent instanceof ScopedRuntimeComponent)) { + return null; + } + ScopedRuntimeComponent component = (ScopedRuntimeComponent)runtimeComponent; + if (component.getScopeContainer() != null) { + return component.getScopeContainer(); + } + ImplementationProvider implementationProvider = component.getImplementationProvider(); + if (implementationProvider instanceof ScopedImplementationProvider) { + ScopedImplementationProvider provider = (ScopedImplementationProvider)implementationProvider; + Scope scope = provider.getScope(); + if (scope == null) { + scope = Scope.STATELESS; + } + ScopeContainerFactory factory = scopeCache.get(scope); + ScopeContainer container = factory.createScopeContainer(component); + component.setScopeContainer(container); + return container; + } + return null; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/StatelessScopeContainer.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/StatelessScopeContainer.java new file mode 100644 index 0000000000..dd481fa062 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/StatelessScopeContainer.java @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.scope; + +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.scope.InstanceWrapper; +import org.apache.tuscany.sca.scope.Scope; +import org.apache.tuscany.sca.scope.TargetDestructionException; +import org.apache.tuscany.sca.scope.TargetResolutionException; + +/** + * A scope context which manages stateless atomic component instances in a non-pooled fashion. + * + * @version $Rev$ $Date$ + */ +public class StatelessScopeContainer extends AbstractScopeContainer { + + public StatelessScopeContainer(RuntimeComponent component) { + super(Scope.STATELESS, component); + } + + public InstanceWrapper getWrapper(KEY contextId) + throws TargetResolutionException { + InstanceWrapper ctx = createInstanceWrapper(); + ctx.start(); + return ctx; + } + + public InstanceWrapper getAssociatedWrapper(KEY contextId) + throws TargetResolutionException { + throw new UnsupportedOperationException(); + } + + public void returnWrapper(InstanceWrapper wrapper, KEY contextId) + throws TargetDestructionException { + wrapper.stop(); + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/StatelessScopeContainerFactory.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/StatelessScopeContainerFactory.java new file mode 100644 index 0000000000..e0eff710e9 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/StatelessScopeContainerFactory.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.core.scope; + +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.scope.Scope; +import org.apache.tuscany.sca.scope.ScopeContainer; +import org.apache.tuscany.sca.scope.ScopeContainerFactory; + +/** + * @version $Rev$ $Date$ + */ +public class StatelessScopeContainerFactory implements ScopeContainerFactory { + + public ScopeContainer createScopeContainer(RuntimeComponent component) { + return new StatelessScopeContainer(component); + } + + public Scope getScope() { + return Scope.STATELESS; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/store/MemoryStore.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/store/MemoryStore.java new file mode 100644 index 0000000000..5b838116c5 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/store/MemoryStore.java @@ -0,0 +1,195 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.store; + +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; + +import org.apache.tuscany.sca.core.event.BaseEventPublisher; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.store.DuplicateRecordException; +import org.apache.tuscany.sca.store.RecoveryListener; +import org.apache.tuscany.sca.store.Store; +import org.apache.tuscany.sca.store.StoreExpirationEvent; +import org.apache.tuscany.sca.store.StoreMonitor; +import org.apache.tuscany.sca.store.StoreWriteException; +import org.osoa.sca.annotations.Destroy; +import org.osoa.sca.annotations.EagerInit; +import org.osoa.sca.annotations.Init; +import org.osoa.sca.annotations.Property; +import org.osoa.sca.annotations.Service; + +/** + * Implements a non-durable, non-transactional store using a simple in-memory map + * + * @version $Rev$ $Date$ + */ +@Service(Store.class) +@EagerInit +public class MemoryStore extends BaseEventPublisher implements Store { + private Map> store; + // TODO integrate with a core threading scheme + private ScheduledExecutorService scheduler; + private long reaperInterval = 300000; + private StoreMonitor monitor; + private long defaultExpirationOffset = 600000; // 10 minutes + + public MemoryStore(StoreMonitor monitor) { + this.monitor = monitor; + this.store = new ConcurrentHashMap>(); + this.scheduler = Executors.newSingleThreadScheduledExecutor(); + } + + /** + * Returns the maximum default expiration offset for records in the store + * + * @return the maximum default expiration offset for records in the store + */ + public long getDefaultExpirationOffset() { + return defaultExpirationOffset; + } + + /** + * Sets the maximum default expiration offset for records in the store + */ + @Property + public void setDefaultExpirationOffset(long defaultExpirationOffset) { + this.defaultExpirationOffset = defaultExpirationOffset; + } + + /** + * Sets the interval for expired entry scanning to be performed + */ + @Property + public void setReaperInterval(long reaperInterval) { + this.reaperInterval = reaperInterval; + } + + public long getReaperInterval() { + return reaperInterval; + } + + @Init + public void init() { + scheduler.scheduleWithFixedDelay(new Reaper(), reaperInterval, reaperInterval, TimeUnit.MILLISECONDS); + monitor.start("In-memory store started"); + } + + @Destroy + public void destroy() { + scheduler.shutdown(); + monitor.stop("In-memory store stopped"); + } + + public void insertRecord(RuntimeComponent owner, String id, Object object, long expiration) throws StoreWriteException { + Map map = store.get(owner); + if (map == null) { + map = new ConcurrentHashMap(); + store.put(owner, map); + } + if (map.containsKey(id)) { + throw new DuplicateRecordException("Duplicate record: " + owner.getURI() +" : " + id); + } + map.put(id, new Record(object, expiration)); + } + + public void updateRecord(RuntimeComponent owner, String id, Object object, long expiration) throws StoreWriteException { + Map map = store.get(owner); + if (map == null) { + throw new StoreWriteException("Record not found: " + owner.getURI() +" : " + id); + } + Record record = map.get(id); + if (record == null) { + throw new StoreWriteException("Record not found: " + owner.getURI() +" : " + id); + } + record.data = object; + } + + public Object readRecord(RuntimeComponent owner, String id) { + Map map = store.get(owner); + if (map == null) { + return null; + } + Record record = map.get(id); + if (record != null) { + return record.data; + } + return null; + } + + public void removeRecords() { + store.clear(); + } + + public void removeRecord(RuntimeComponent owner, String id) throws StoreWriteException { + Map map = store.get(owner); + if (map == null) { + throw new StoreWriteException("Owner not found: " + owner.getURI() +" : " + id); + } + if (map.remove(id) == null) { + throw new StoreWriteException("Owner not found: " + owner.getURI() +" : " + id); + } + } + + public void recover(RecoveryListener listener) { + throw new UnsupportedOperationException(); + } + + private class Record { + private Object data; + private long expiration = NEVER; + + public Record(Object data, long expiration) { + this.data = data; + this.expiration = expiration; + } + + public Object getData() { + return data; + } + + public long getExpiration() { + return expiration; + } + } + + private class Reaper implements Runnable { + + public void run() { + long now = System.currentTimeMillis(); + for (Map.Entry> entries : store.entrySet()) { + for (Map.Entry entry : entries.getValue().entrySet()) { + final long expiration = entry.getValue().expiration; + if (expiration != NEVER && now >= expiration) { + RuntimeComponent owner = entries.getKey(); + Object instance = entry.getValue().getData(); + // notify listeners of the expiration + StoreExpirationEvent event = new StoreExpirationEvent(this, owner, instance); + publish(event); + entries.getValue().remove(entry.getKey()); + } + } + } + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/util/IOHelper.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/util/IOHelper.java new file mode 100644 index 0000000000..2058397fb0 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/util/IOHelper.java @@ -0,0 +1,182 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.core.util; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.JarURLConnection; +import java.net.URL; +import java.util.jar.JarFile; + +public class IOHelper { + /** + * The default buffer size to use. + */ + private static final int DEFAULT_BUFFER_SIZE = 1024 * 4; + + protected IOHelper() { + + } + + /** + * Unconditionally close an InputStream. + *

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

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

+ * This method buffers the input internally, so there is no need to use a + * BufferedInputStream. + * + * @param input the InputStream to read from + * @param output the OutputStream to write to + * @return the number of bytes copied + * @throws NullPointerException if the input or output is null + * @throws IOException if an I/O error occurs + * @since Commons IO 1.1 + */ + public static int copy(InputStream input, OutputStream output) throws IOException { + byte[] buffer = new byte[DEFAULT_BUFFER_SIZE]; + int count = 0; + int n = 0; + while (-1 != (n = input.read(buffer))) { // NOPMD + output.write(buffer, 0, n); + count += n; + } + return count; + } + + public static InputStream getInputStream(URL url) throws IOException { + return new SafeURLInputStream(url); + } + + /** + * This class is a workaround for URL stream issue as illustrated below. + * InputStream is=url.getInputStream(); is.close(); // This line doesn't close + * the JAR file if the URL is a jar entry like "jar:file:/a.jar!/my.composite" We + * also need to turn off the JarFile cache. + * + * @see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4950148 + * + * @version $Rev$ $Date$ + */ + public static class SafeURLInputStream extends InputStream { + private JarFile jarFile; + private InputStream is; + + public SafeURLInputStream(URL url) throws IOException { + String protocol = url.getProtocol(); + if (protocol != null && (protocol.equals("jar"))) { + JarURLConnection connection = (JarURLConnection)url.openConnection(); + // We cannot use cache + connection.setUseCaches(false); + try { + is = connection.getInputStream(); + } catch (IOException e) { + throw e; + } + jarFile = connection.getJarFile(); + } else { + is = url.openStream(); + } + } + + public SafeURLInputStream(JarURLConnection connection) throws IOException { + // We cannot use cache + connection.setUseCaches(false); + is = connection.getInputStream(); + jarFile = connection.getJarFile(); + } + + public int available() throws IOException { + return is.available(); + } + + public void close() throws IOException { + is.close(); + // We need to close the JAR file + if (jarFile != null) { + jarFile.close(); + } + } + + public synchronized void mark(int readlimit) { + is.mark(readlimit); + } + + public boolean markSupported() { + return is.markSupported(); + } + + public int read() throws IOException { + return is.read(); + } + + public int read(byte[] b, int off, int len) throws IOException { + return is.read(b, off, len); + } + + public int read(byte[] b) throws IOException { + return is.read(b); + } + + public synchronized void reset() throws IOException { + is.reset(); + } + + public long skip(long n) throws IOException { + return is.skip(n); + } + } +} \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/work/Jsr237Work.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/work/Jsr237Work.java new file mode 100644 index 0000000000..6fe883157f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/work/Jsr237Work.java @@ -0,0 +1,63 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.core.work; + +/* + * JCA work wrapper. + */ +public class Jsr237Work implements commonj.work.Work { + + // Work that is being executed. + private T work; + + /* + * Initializes the work instance. + */ + public Jsr237Work(T work) { + this.work = work; + } + + /* + * Returns the completed work. + */ + public T getWork() { + return work; + } + + /* + * Release the work. + */ + public void release() { + } + + /* + * Work attributes are not daemon. + */ + public boolean isDaemon() { + return false; + } + + /* + * Runs the work. + */ + public void run() { + work.run(); + } +} \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/work/Jsr237WorkScheduler.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/work/Jsr237WorkScheduler.java new file mode 100644 index 0000000000..c8a5dd7afe --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/work/Jsr237WorkScheduler.java @@ -0,0 +1,167 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.work; + +import org.apache.tuscany.sca.work.NotificationListener; +import org.apache.tuscany.sca.work.WorkScheduler; +import org.apache.tuscany.sca.work.WorkSchedulerException; + +import commonj.work.WorkEvent; +import commonj.work.WorkException; +import commonj.work.WorkListener; +import commonj.work.WorkManager; +import commonj.work.WorkRejectedException; + +/** + * A work scheduler implementation based on a JSR 237 work manager. + *

+ *

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

+ */ +public class Jsr237WorkScheduler implements WorkScheduler { + + /** + * Underlying JSR-237 work manager + */ + private WorkManager jsr237WorkManager; + + /** + * Initializes the JSR 237 work manager. + * + * @param jsr237WorkManager JSR 237 work manager. + */ + public Jsr237WorkScheduler(WorkManager jsr237WorkManager) { + if (jsr237WorkManager == null) { + throw new IllegalArgumentException("Work manager cannot be null"); + } + this.jsr237WorkManager = jsr237WorkManager; + } + + /** + * Schedules a unit of work for future execution. The notification listener is used to register interest in + * callbacks regarding the status of the work. + * + * @param work The unit of work that needs to be asynchronously executed. + */ + public void scheduleWork(T work) { + scheduleWork(work, null); + } + + /** + * Schedules a unit of work for future execution. The notification listener is used to register interest in + * callbacks regarding the status of the work. + * + * @param work The unit of work that needs to be asynchronously executed. + * @param listener Notification listener for callbacks. + */ + public void scheduleWork(T work, NotificationListener listener) { + + if (work == null) { + throw new IllegalArgumentException("Work cannot be null"); + } + + Jsr237Work jsr237Work = new Jsr237Work(work); + try { + if (listener == null) { + jsr237WorkManager.schedule(jsr237Work); + } else { + Jsr237WorkListener jsr237WorkListener = new Jsr237WorkListener(listener, work); + jsr237WorkManager.schedule(jsr237Work, jsr237WorkListener); + } + } catch (WorkRejectedException ex) { + if (listener != null) { + listener.workRejected(work); + } else { + throw new WorkSchedulerException(ex); + } + } catch (WorkException ex) { + throw new WorkSchedulerException(ex); + } + + } + + /* + * Worklistener for keeping track of work status callbacks. + * + */ + private class Jsr237WorkListener implements WorkListener { + + // Notification listener + private NotificationListener listener; + + // Work + private T work; + + /* + * Initializes the notification listener. + */ + public Jsr237WorkListener(NotificationListener listener, T work) { + this.listener = listener; + this.work = work; + } + + /* + * Callback when the work is accepted. + */ + public void workAccepted(WorkEvent workEvent) { + T work = getWork(); + listener.workAccepted(work); + } + + /* + * Callback when the work is rejected. + */ + public void workRejected(WorkEvent workEvent) { + T work = getWork(); + listener.workRejected(work); + } + + /* + * Callback when the work is started. + */ + public void workStarted(WorkEvent workEvent) { + T work = getWork(); + listener.workStarted(work); + } + + /* + * Callback when the work is completed. + */ + public void workCompleted(WorkEvent workEvent) { + T work = getWork(); + Exception exception = workEvent.getException(); + if (exception != null) { + listener.workFailed(work, exception); + } else { + listener.workCompleted(work); + } + } + + /* + * Gets the underlying work from the work event. + */ + private T getWork() { + return work; + } + + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/work/ThreadPoolWorkManager.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/work/ThreadPoolWorkManager.java new file mode 100644 index 0000000000..0bc6f1b336 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/work/ThreadPoolWorkManager.java @@ -0,0 +1,220 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.work; + +import java.rmi.server.UID; +import java.util.Collection; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.RejectedExecutionException; + +import org.osoa.sca.annotations.Destroy; +import org.osoa.sca.annotations.Property; + +import commonj.work.Work; +import commonj.work.WorkEvent; +import commonj.work.WorkException; +import commonj.work.WorkItem; +import commonj.work.WorkListener; +import commonj.work.WorkManager; +import commonj.work.WorkRejectedException; + +/** + * A thread-pool based implementation for the JSR-237 work manager. + *

+ *

+ * This implementation supports only local work. + *

+ * TODO Elaborate the implementation.

+ */ +public class ThreadPoolWorkManager implements WorkManager { + + // Map of work items currently handled by the work manager + private Map workItems = new ConcurrentHashMap(); + + // Thread-pool + private ExecutorService executor; + + /** + * Initializes the thread-pool. + * + * @param threadPoolSize Thread-pool size. + */ + public ThreadPoolWorkManager(@Property(name = "poolSize") int threadPoolSize) { + executor = Executors.newFixedThreadPool(threadPoolSize); + } + + /** + * Schedules a unit of work asynchronously. + * + * @param work Work that needs to be scheduled. + * @return Work Work item representing the asynchronous work + */ + public WorkItem schedule(Work work) throws WorkException { + return schedule(work, null); + } + + /** + * Schedules a unit of work asynchronously. + * + * @param work Work that needs to be scheduled. + * @param workListener Work listener for callbacks. + * @return Work Work item representing the asynchronous work + */ + public WorkItem schedule(Work work, WorkListener workListener) throws WorkRejectedException { + + WorkItemImpl workItem = new WorkItemImpl(new UID().toString(), work); + if (workListener != null) { + workItems.put(workItem, workListener); + } + workAccepted(workItem, work); + if (scheduleWork(work, workItem)) { + return workItem; + } else { + workItem.setStatus(WorkEvent.WORK_REJECTED); + if (workListener != null) { + workListener.workRejected(new WorkEventImpl(workItem)); + } + throw new WorkRejectedException("Unable to schedule work"); + } + } + + /** + * Wait for all the specified units of work to finish. + * + * @param works Units of the work that need to finish. + * @param timeout Timeout for waiting for the units of work to finish. + */ + public boolean waitForAll(Collection works, long timeout) { + throw new UnsupportedOperationException("waitForAll not supported"); + } + + /** + * Wait for any of the specified units of work to finish. + * + * @param works Units of the work that need to finish. + * @param timeout Timeout for waiting for the units of work to finish. + */ + public Collection waitForAny(Collection works, long timeout) { + throw new UnsupportedOperationException("waitForAny not supported"); + } + + /** + * Method provided for subclasses to indicate a work accptance. + * + * @param workItem Work item representing the work that was accepted. + * @param work Work that was accepted. + */ + private void workAccepted(final WorkItemImpl workItem, final Work work) { + WorkListener listener = workItems.get(workItem); + if (listener != null) { + workItem.setStatus(WorkEvent.WORK_ACCEPTED); + WorkEvent event = new WorkEventImpl(workItem); + listener.workAccepted(event); + } + } + + /* + * Method to indicate a work start. + */ + private void workStarted(final WorkItemImpl workItem, final Work work) { + WorkListener listener = workItems.get(workItem); + if (listener != null) { + workItem.setStatus(WorkEvent.WORK_STARTED); + WorkEvent event = new WorkEventImpl(workItem); + listener.workStarted(event); + } + } + + /* + * Method to indicate a work completion. + */ + private void workCompleted(final WorkItemImpl workItem, final Work work) { + workCompleted(workItem, work, null); + } + + /* + * Method to indicate a work completion. + */ + private void workCompleted(final WorkItemImpl workItem, final Work work, final WorkException exception) { + WorkListener listener = workItems.get(workItem); + if (listener != null) { + workItem.setStatus(WorkEvent.WORK_COMPLETED); + workItem.setResult(work); + workItem.setException(exception); + WorkEvent event = new WorkEventImpl(workItem); + listener.workCompleted(event); + workItems.remove(workItem); + } + } + + /* + * Schedules the work using the threadpool. + */ + private boolean scheduleWork(final Work work, final WorkItemImpl workItem) { + try { + executor.execute(new DecoratingWork(workItem, work)); + return true; + } catch (RejectedExecutionException ex) { + return false; + } + } + + /* + * Class that decorates the original worker so that it can get callbacks when work is done. + */ + private final class DecoratingWork implements Runnable { + + // Work item for this work. + private WorkItemImpl workItem; + + // The original work. + private Work decoratedWork; + + /* + * Initializes the work item and underlying work. + */ + private DecoratingWork(final WorkItemImpl workItem, final Work decoratedWork) { + this.workItem = workItem; + this.decoratedWork = decoratedWork; + } + + /* + * Overrides the run method. + */ + public void run() { + workStarted(workItem, decoratedWork); + try { + decoratedWork.run(); + workCompleted(workItem, decoratedWork); + } catch (Throwable th) { + workCompleted(workItem, decoratedWork, new WorkException(th.getMessage(), th)); + } + } + + } + + @Destroy + public void destroy() { + executor.shutdown(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/work/WorkEventImpl.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/work/WorkEventImpl.java new file mode 100644 index 0000000000..62ebeea1fb --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/work/WorkEventImpl.java @@ -0,0 +1,74 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.work; + + +import commonj.work.WorkEvent; +import commonj.work.WorkException; +import commonj.work.WorkItem; + +/** + * Default immutable implementation of the WorkEvent class. + */ +class WorkEventImpl implements WorkEvent { + + // Work item for this event + private WorkItem workItem; + + // Exception if something has gone wrong + private WorkException exception; + + /** + * Instantiates the event. + * + * @param workItem Work item for this event. + */ + public WorkEventImpl(final WorkItemImpl workItem) { + this.workItem = workItem; + this.exception = workItem.getException(); + } + + /** + * Returns the work type based on whether the work was accepted, started, + * rejected or completed. + * + * @return Work type. + */ + public int getType() { + return workItem.getStatus(); + } + + /** + * Returns the work item associated with this work type. + * + * @return Work item. + */ + public WorkItem getWorkItem() { + return workItem; + } + + /** + * Returns the exception if the work completed with an exception. + * + * @return Work exception. + */ + public WorkException getException() { + return exception; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/work/WorkItemImpl.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/work/WorkItemImpl.java new file mode 100644 index 0000000000..fae3f1aae3 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/core/work/WorkItemImpl.java @@ -0,0 +1,166 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.work; + +import commonj.work.Work; +import commonj.work.WorkException; +import commonj.work.WorkItem; + +/** + * An identity based immutable implementation of the WorkItem + * interface. + * + */ +class WorkItemImpl implements WorkItem { + + // Id scoped for the VM + private String id; + + // Status + private int status = -1; + + // Result + private Work result; + + // Original work + private Work originalWork; + + // Exception + private WorkException exception; + + /** + * Instantiates an id for this item. + * + * @param id of this work event. + */ + protected WorkItemImpl(final String id, final Work orginalWork) { + this.id = id; + this.originalWork = orginalWork; + } + + /** + * Returns the id. + * + * @return Id of this item. + */ + public String getId() { + return id; + } + + /** + * Returns the original work. + * + * @return Original work. + */ + public Work getOriginalWork() { + return originalWork; + } + + /** + * Returns the work result if the work completed. + * + * @return Work. + * @throws WorkException If the work completed with an exception. + */ + public Work getResult() throws WorkException { + return result; + } + + /** + * Sets the result. + * + * @param result Result. + */ + protected void setResult(final Work result) { + this.result = result; + } + + /** + * Returns the exception if work completed with an exception. + * + * @return Work exception. + */ + protected WorkException getException() { + return exception; + } + + /** + * Sets the exception. + * + * @param exception Exception. + */ + protected void setException(final WorkException exception) { + this.exception = exception; + } + + /** + * Returns the work type based on whether the work was accepted, started, + * rejected or completed. + * + * @return Work status. + */ + public int getStatus() { + return status; + } + + /** + * Sets the status. + * + * @param status Status. + */ + protected void setStatus(final int status) { + this.status = status; + } + + /** + * @see Object#hashCode() + */ + public int hashCode() { + return id.hashCode(); + } + + /** + * Indicates whether some other object is "equal to" this one. + * + * @param obj Object to be compared. + * @return true if this object is the same as the obj argument; false + * otherwise.. + */ + public boolean equals(final Object obj) { + return (obj != null) && (obj.getClass() == WorkItemImpl.class) && ((WorkItemImpl) obj).id.equals(id); + } + + /** + * Compares this object with the specified object for order. Returns a + * negative integer, zero, or a positive integer as this object is less + * than, equal to, or greater than the specified object. + * + * @param o Object to be compared. + * @return A negative integer, zero, or a positive integer as this object + * is less than, equal to, or greater than the specified object. + * @throws ClassCastException needs better documentation. + */ + public int compareTo(final Object o) { + if (o.getClass() != WorkItemImpl.class) { + throw new ClassCastException(o.getClass().getName()); + } else { + return ((WorkItemImpl) o).getId().compareTo(getId()); + } + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/factory/ObjectCreationException.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/factory/ObjectCreationException.java new file mode 100644 index 0000000000..3432c61c76 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/factory/ObjectCreationException.java @@ -0,0 +1,47 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.factory; + + +/** + * Denotes an error creating a new object instance + * + * @version $Rev$ $Date$ + */ +public class ObjectCreationException extends RuntimeException { + private static final long serialVersionUID = -6423113430265944499L; + + public ObjectCreationException() { + super(); + } + + public ObjectCreationException(String message, Throwable cause) { + super(message, cause); + } + + public ObjectCreationException(String message) { + super(message); + } + + public ObjectCreationException(Throwable cause) { + super(cause); + } + +} + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/factory/ObjectFactory.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/factory/ObjectFactory.java new file mode 100644 index 0000000000..c5e0dad4e7 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/factory/ObjectFactory.java @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.factory; + +/** + * Implementations create new instances of a particular type + * + * @version $Rev$ $Date$ + */ +public interface ObjectFactory { + + /** + * Return a instance of the type that this factory creates. + * + * @return a instance from this factory + */ + T getInstance() throws ObjectCreationException; + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/factory/SingletonObjectFactory.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/factory/SingletonObjectFactory.java new file mode 100644 index 0000000000..074a1121c9 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/factory/SingletonObjectFactory.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.factory; + + +/** + * Implementation of ObjectFactory that returns a single instance, typically an immutable type. + * + * @version $Rev$ $Date$ + */ +public class SingletonObjectFactory implements ObjectFactory { + private final T instance; + + public SingletonObjectFactory(T instance) { + this.instance = instance; + } + + public T getInstance() { + return instance; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/scope/AbstractLifecycle.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/scope/AbstractLifecycle.java new file mode 100644 index 0000000000..e5f88d91c6 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/scope/AbstractLifecycle.java @@ -0,0 +1,77 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.scope; + +/** + * Base class providing a simple implementation of Lifecycle. + * + * @version $Rev$ $Date$ + */ +public abstract class AbstractLifecycle implements Lifecycle { + protected volatile int lifecycleState = UNINITIALIZED; + + public int getLifecycleState() { + return lifecycleState; + } + + /** + * Set the current state of the Lifecycle. + * + * @param lifecycleState the new state + */ + protected void setLifecycleState(int lifecycleState) { + this.lifecycleState = lifecycleState; + } + + public void start() { + setLifecycleState(RUNNING); + } + + public void stop() { + setLifecycleState(STOPPED); + } + + /** + * Returns the current lifecycle as a String (for example, "RUNNING"). + * + * @return the current lifecycle as a String + */ + public String toString() { + switch (lifecycleState) { + case Lifecycle.CONFIG_ERROR: + return "CONFIG_ERROR"; + case Lifecycle.ERROR: + return "ERROR"; + case Lifecycle.INITIALIZING: + return "INITIALIZING"; + case Lifecycle.INITIALIZED: + return "INITIALIZED"; + case Lifecycle.RUNNING: + return "RUNNING"; + case Lifecycle.STOPPING: + return "STOPPING"; + case Lifecycle.STOPPED: + return "STOPPED"; + case Lifecycle.UNINITIALIZED: + return "UNINITIALIZED"; + default: + return "UNKNOWN"; + } + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/scope/CoreRuntimeException.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/scope/CoreRuntimeException.java new file mode 100644 index 0000000000..ac3e51a982 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/scope/CoreRuntimeException.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.scope; + + +/** + * The root exception for the runtime package. Exceptions occurring in the runtime are generally non-recoverable + * + * @version $Rev$ $Date$ + */ +public abstract class CoreRuntimeException extends RuntimeException { + + public CoreRuntimeException() { + super(); + } + + public CoreRuntimeException(String message, Throwable cause) { + super(message, cause); + } + + public CoreRuntimeException(String message) { + super(message); + } + + public CoreRuntimeException(Throwable cause) { + super(cause); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/scope/InstanceWrapper.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/scope/InstanceWrapper.java new file mode 100644 index 0000000000..a952e2e72b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/scope/InstanceWrapper.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.scope; + + +/** + * Provides lifecycle management for an implementation instance associated with + * a component for use by the component's associated {@link org.apache.tuscany.sca.scope.ScopeContainer} + * + * @version $Rev$ $Date$ + */ +public interface InstanceWrapper { + + /** + * @return + */ + T getInstance(); + + /** + * @throws TargetInitializationException + */ + void start() throws TargetInitializationException; + + /** + * @throws TargetDestructionException + */ + void stop() throws TargetDestructionException; + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/scope/Lifecycle.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/scope/Lifecycle.java new file mode 100644 index 0000000000..02075cad01 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/scope/Lifecycle.java @@ -0,0 +1,69 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.scope; + +/** + * Implementations adhere to runtime lifecycle semantics + * + * @version $Rev$ $Date$ + */ +public interface Lifecycle { + /* A configuration error state */ + int CONFIG_ERROR = -1; + /* Has not been initialized */ + int UNINITIALIZED = 0; + /* In the process of being configured and initialized */ + int INITIALIZING = 1; + /* Instantiated and configured */ + int INITIALIZED = 2; + /* Configured and initialized */ + int RUNNING = 4; + /* In the process of being shutdown */ + int STOPPING = 5; + /* Has been shutdown and removed from the composite */ + int STOPPED = 6; + /* In an error state */ + int ERROR = 7; + + /** + * Returns the lifecycle state + * + * @see #UNINITIALIZED + * @see #INITIALIZING + * @see #INITIALIZED + * @see #RUNNING + * @see #STOPPING + * @see #STOPPED + */ + int getLifecycleState(); + + /** + * Starts the Lifecycle. + * + * @throws CoreRuntimeException + */ + void start() throws CoreRuntimeException; + + /** + * Stops the Lifecycle. + * + * @throws CoreRuntimeException + */ + void stop() throws CoreRuntimeException; +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/scope/PersistenceException.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/scope/PersistenceException.java new file mode 100644 index 0000000000..54fba1ee03 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/scope/PersistenceException.java @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.scope; + +/** + * Raised when an error persisting a component implementation instance is encountered + * + * @version $Rev$ $Date$ + */ +public class PersistenceException extends Exception { + private static final long serialVersionUID = -908468170919651248L; + + public PersistenceException() { + } + + public PersistenceException(String message) { + super(message); + } + + public PersistenceException(String message, Throwable cause) { + super(message, cause); + } + + public PersistenceException(Throwable cause) { + super(cause); + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/scope/Scope.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/scope/Scope.java new file mode 100644 index 0000000000..9b3f208cb3 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/scope/Scope.java @@ -0,0 +1,63 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.scope; + +/** + * The default implementation scopes supported by assemblies. + * + * @version $Rev$ $Date$ + */ +public class Scope { + public static final Scope STATELESS = new Scope("STATELESS"); + public static final Scope REQUEST = new Scope("REQUEST"); + public static final Scope SESSION = new Scope("SESSION"); + public static final Scope CONVERSATION = new Scope("CONVERSATION"); + public static final Scope COMPOSITE = new Scope("COMPOSITE"); + public static final Scope SYSTEM = new Scope("SYSTEM"); + public static final Scope UNDEFINED = new Scope("UNDEFINED"); + + private String scope; + + public Scope(String scope) { + this.scope = scope.toUpperCase().intern(); + } + + public String getScope() { + return scope; + } + + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + final Scope scope1 = (Scope) o; + return !(scope != null ? scope != scope1.scope.intern() : scope1.scope != null); + } + + public int hashCode() { + return scope != null ? scope.hashCode() : 0; + } + + public String toString() { + return scope; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/scope/ScopeContainer.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/scope/ScopeContainer.java new file mode 100644 index 0000000000..30482fae90 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/scope/ScopeContainer.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.scope; + +import org.apache.tuscany.sca.event.RuntimeEventListener; +import org.apache.tuscany.sca.runtime.RuntimeComponent; + + +/** + * Manages the lifecycle and visibility of instances associated with a an {@link RuntimeComponent}. + * + * @version $Rev$ $Date$ + * @param the type of IDs that this container uses to identify its contexts. + * For example, for COMPOSITE scope this could be the URI of the composite component, + * or for HTTP Session scope it might be the HTTP session ID. + */ +public interface ScopeContainer extends Lifecycle, RuntimeEventListener { + + /** + * Returns the Scope that this container supports. + * + * @return the Scope that this container supports + */ + Scope getScope(); + + /** + * Start a new context with the supplied ID. + * + * @param contextId an ID that uniquely identifies the context. + */ + void startContext(KEY contextId); + + /** + * Stop the context with the supplied ID. + * + * @param contextId an ID that uniquely identifies the context. + */ + void stopContext(KEY contextId); + + /** + * Returns an instance wrapper associated with the current scope context, creating one if necessary + * @param contextId the id for the scope context + * + * @return the wrapper for the target instance + * @throws TargetResolutionException if there was a problem instantiating the target instance + */ + InstanceWrapper getWrapper(KEY contextId) throws TargetResolutionException; + + /** + * Returns an implementation instance associated with the current scope context. + * If no instance is found, a {@link TargetNotFoundException} is thrown. + * @param contextId the id for the scope context + * + * @return the wrapper for the target instance + * @throws TargetResolutionException if there was a problem instantiating the target instance + */ + InstanceWrapper getAssociatedWrapper(KEY contextId) + throws TargetResolutionException; + + /** + * Return a wrapper after use (for example, after invoking the instance). + * @param wrapper the wrapper for the target instance being returned + * @param contextId the id for the scope context + * + * @throws TargetDestructionException if there was a problem returning the target instance + */ + void returnWrapper(InstanceWrapper wrapper, KEY contextId) + throws TargetDestructionException; + + /** + * Removes a component implementation instance associated with the current context from persistent storage + * + * @param component the owning component + * @throws PersistenceException if there was a problem removing the instance + */ + void remove() throws PersistenceException; +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/scope/ScopeContainerFactory.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/scope/ScopeContainerFactory.java new file mode 100644 index 0000000000..b6acae7382 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/scope/ScopeContainerFactory.java @@ -0,0 +1,32 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.scope; + +import org.apache.tuscany.sca.runtime.RuntimeComponent; + +/** + * Factory to create ScopeContainer for components + * + * @version $Rev$ $Date$ + */ +public interface ScopeContainerFactory { + ScopeContainer createScopeContainer(RuntimeComponent component); + Scope getScope(); +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/scope/ScopeIdentifier.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/scope/ScopeIdentifier.java new file mode 100644 index 0000000000..77e7d76842 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/scope/ScopeIdentifier.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.scope; + +/** + * Implementations enable lazy retrieval of a scope id associated with a request, i.e. an id (and presumably a context) + * do not have to be generated if the scope is never accessed. Identifiers are associated with the current request + * thread and keyed on scope type. + * + * @version $Rev$ $Date$ + * @see org.apache.tuscany.sca.factory.component.WorkContext + */ +public interface ScopeIdentifier { + + /** + * Returns the scope id for the request. + */ + Object getIdentifier(); +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/scope/ScopeNotFoundException.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/scope/ScopeNotFoundException.java new file mode 100644 index 0000000000..40a251c6f2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/scope/ScopeNotFoundException.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.scope; + +/** + * @version $Rev$ $Date$ + */ +public class ScopeNotFoundException extends Exception { + + private static final long serialVersionUID = -3447306764458851441L; + + public ScopeNotFoundException(String scope) { + super("Scope not found: " + scope); + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/scope/ScopeRegistry.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/scope/ScopeRegistry.java new file mode 100644 index 0000000000..f3319ee093 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/scope/ScopeRegistry.java @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.scope; + +import org.apache.tuscany.sca.runtime.RuntimeComponent; + + +/** + * Manages {@link ScopeContainer}s in the runtime + * + * @version $$Rev$$ $$Date$$ + */ +public interface ScopeRegistry { + + /** + * Returns the scope container for the given scope or null if one not found + * + * @param scope the scope + * @return the scope container for the given scope or null if one not found + */ + ScopeContainer getScopeContainer(RuntimeComponent component); + + /** + * @param factory + */ + void register(ScopeContainerFactory factory); +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/scope/ScopedImplementationProvider.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/scope/ScopedImplementationProvider.java new file mode 100644 index 0000000000..8b9c50b070 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/scope/ScopedImplementationProvider.java @@ -0,0 +1,64 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.scope; + +import org.apache.tuscany.sca.provider.ImplementationProvider; + +/** + * A component implementation can implement this interface to provide scope + * management for the components + * + * @version $Rev$ $Date$ + */ +public interface ScopedImplementationProvider extends ImplementationProvider { + /** + * Get the scope for the component implementation + * + * @return The scope for the component implementation, if null is returned, + * STATELESS will be used + */ + Scope getScope(); + + /** + * Indicate if the component needs to be eagerly initialized + * + * @return true if the component is marked to be eagerly initialized, false + * otherwise + */ + boolean isEagerInit(); + + /** + * @return the maxAge + */ + long getMaxAge(); + + /** + * @return the maxIdleTime + */ + long getMaxIdleTime(); + + /** + * Create a wrapper for the component instance for the scope management + * + * @return A wrapper for the component instance + */ + InstanceWrapper createInstanceWrapper(); + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/scope/ScopedRuntimeComponent.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/scope/ScopedRuntimeComponent.java new file mode 100644 index 0000000000..6c33683bde --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/scope/ScopedRuntimeComponent.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.scope; + +import org.apache.tuscany.sca.runtime.RuntimeComponent; + +/** + * Scoped runtime component + * + * @version $Rev$ $Date$ + */ +public interface ScopedRuntimeComponent extends RuntimeComponent { + /** + * Set the associated scope container + * @param scopeContainer + */ + void setScopeContainer(ScopeContainer scopeContainer); + /** + * Get the assoicated scope container + * @return + */ + ScopeContainer getScopeContainer(); +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/scope/TargetDestructionException.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/scope/TargetDestructionException.java new file mode 100644 index 0000000000..6b251295f5 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/scope/TargetDestructionException.java @@ -0,0 +1,44 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.scope; + +/** + * Denotes an error destroying a target + * + * @version $Rev$ $Date$ + */ +public class TargetDestructionException extends TargetResolutionException { + private static final long serialVersionUID = -6126684147851674709L; + + public TargetDestructionException() { + super(); + } + + public TargetDestructionException(String message, Throwable cause) { + super(message, cause); + } + + public TargetDestructionException(String message) { + super(message); + } + + public TargetDestructionException(Throwable cause) { + super(cause); + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/scope/TargetInitializationException.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/scope/TargetInitializationException.java new file mode 100644 index 0000000000..17cd21967f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/scope/TargetInitializationException.java @@ -0,0 +1,44 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.scope; + +/** + * Denotes an error initializing a target + * + * @version $Rev$ $Date$ + */ +public class TargetInitializationException extends TargetResolutionException { + private static final long serialVersionUID = -6228778208649752698L; + + public TargetInitializationException() { + super(); + } + + public TargetInitializationException(String message, Throwable cause) { + super(message, cause); + } + + public TargetInitializationException(String message) { + super(message); + } + + public TargetInitializationException(Throwable cause) { + super(cause); + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/scope/TargetInvocationException.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/scope/TargetInvocationException.java new file mode 100644 index 0000000000..f9bfa0a788 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/scope/TargetInvocationException.java @@ -0,0 +1,45 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.scope; + +/** + * Raised when an error is encountered during a target invocation + * + * @version $Rev$ $Date$ + */ +public class TargetInvocationException extends Exception { + + private static final long serialVersionUID = -6553427708442761743L; + + public TargetInvocationException() { + super(); + } + + public TargetInvocationException(String message, Throwable cause) { + super(message, cause); + } + + public TargetInvocationException(String message) { + super(message); + } + + public TargetInvocationException(Throwable cause) { + super(cause); + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/scope/TargetInvokerCreationException.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/scope/TargetInvokerCreationException.java new file mode 100644 index 0000000000..a20d030ee8 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/scope/TargetInvokerCreationException.java @@ -0,0 +1,44 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.scope; + +/** + * Denotes an error creating a target invoker + * + * @version $Rev$ $Date$ + * @Deprecated + */ +public abstract class TargetInvokerCreationException extends Exception { + + public TargetInvokerCreationException() { + super(); + } + + public TargetInvokerCreationException(String message, Throwable cause) { + super(message, cause); + } + + public TargetInvokerCreationException(String message) { + super(message); + } + + public TargetInvokerCreationException(Throwable cause) { + super(cause); + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/scope/TargetNotFoundException.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/scope/TargetNotFoundException.java new file mode 100644 index 0000000000..4dd63f58f0 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/scope/TargetNotFoundException.java @@ -0,0 +1,44 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.scope; + +/** + * Thrown when a target of an operation cannot be found + * + * @version $$Rev$$ $$Date$$ + */ +public class TargetNotFoundException extends TargetResolutionException { + private static final long serialVersionUID = 5541830480658471186L; + + public TargetNotFoundException() { + super(); + } + + public TargetNotFoundException(String message, Throwable cause) { + super(message, cause); + } + + public TargetNotFoundException(String message) { + super(message); + } + + public TargetNotFoundException(Throwable cause) { + super(cause); + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/scope/TargetResolutionException.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/scope/TargetResolutionException.java new file mode 100644 index 0000000000..284ab8b6c7 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/main/java/org/apache/tuscany/sca/scope/TargetResolutionException.java @@ -0,0 +1,44 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.scope; + +/** + * Denotes an error retrieving a target instance + * + * @version $Rev$ $Date$ + */ +public class TargetResolutionException extends Exception { + private static final long serialVersionUID = 2912513650522019405L; + + public TargetResolutionException() { + super(); + } + + public TargetResolutionException(String message, Throwable cause) { + super(message, cause); + } + + public TargetResolutionException(String message) { + super(message); + } + + public TargetResolutionException(Throwable cause) { + super(cause); + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/DefaultExtensionPointRegistryTestCase.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/DefaultExtensionPointRegistryTestCase.java new file mode 100644 index 0000000000..40a146e129 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/DefaultExtensionPointRegistryTestCase.java @@ -0,0 +1,51 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.core; + +import junit.framework.TestCase; + +public class DefaultExtensionPointRegistryTestCase extends TestCase { + private ExtensionPointRegistry registry; + + protected void setUp() throws Exception { + super.setUp(); + registry = new DefaultExtensionPointRegistry(); + } + + public void testRegistry() { + MyRegistry service = new MyREgistryImpl(); + registry.addExtensionPoint(service); + assertSame(service, registry.getExtensionPoint(MyRegistry.class)); + registry.removeExtensionPoint(service); + assertNull(registry.getExtensionPoint(MyRegistry.class)); + } + + private static interface MyRegistry { + void doSomething(); + } + + private static class MyREgistryImpl implements MyRegistry { + + public void doSomething() { + } + + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/event/BaseEventPublisherTestCase.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/event/BaseEventPublisherTestCase.java new file mode 100644 index 0000000000..d2050523eb --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/event/BaseEventPublisherTestCase.java @@ -0,0 +1,98 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.event; + + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.event.Event; +import org.apache.tuscany.sca.event.EventFilter; +import org.apache.tuscany.sca.event.EventPublisher; +import org.apache.tuscany.sca.event.RuntimeEventListener; +import org.apache.tuscany.sca.event.TrueFilter; +import org.easymock.EasyMock; + +/** + * @version $Rev$ $Date$ + */ +public class BaseEventPublisherTestCase extends TestCase { + EventPublisher publisher; + + public void testFireListener() { + Event event = new TestEvent(); + RuntimeEventListener listener = EasyMock.createMock(RuntimeEventListener.class); + listener.onEvent(EasyMock.same(event)); + EasyMock.expectLastCall(); + EasyMock.replay(listener); + publisher.addListener(listener); + publisher.publish(event); + EasyMock.verify(listener); + } + + public void testRemoveListener() { + Event event = new TestEvent(); + RuntimeEventListener listener = EasyMock.createMock(RuntimeEventListener.class); + EasyMock.replay(listener); + publisher.addListener(listener); + publisher.removeListener(listener); + publisher.publish(event); + EasyMock.verify(listener); + } + + public void testFalseFilterListener() { + Event event = new TestEvent(); + RuntimeEventListener listener = EasyMock.createMock(RuntimeEventListener.class); + EasyMock.replay(listener); + publisher.addListener(new FalseFilter(), listener); + publisher.publish(event); + EasyMock.verify(listener); + } + + public void testTrueFilterListener() { + Event event = new TestEvent(); + RuntimeEventListener listener = EasyMock.createMock(RuntimeEventListener.class); + listener.onEvent(EasyMock.same(event)); + EasyMock.expectLastCall(); + EasyMock.replay(listener); + publisher.addListener(new TrueFilter(), listener); + publisher.publish(event); + EasyMock.verify(listener); + } + + protected void setUp() throws Exception { + super.setUp(); + publisher = new BaseEventPublisher() { + }; + } + + private class TestEvent implements Event { + public Object getSource() { + return null; + } + } + + private class FalseFilter implements EventFilter { + + public boolean match(Event event) { + return false; + } + } + + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/event/EventTestCase.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/event/EventTestCase.java new file mode 100644 index 0000000000..bf95d640c5 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/event/EventTestCase.java @@ -0,0 +1,69 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.event; + +import java.net.URI; + +import junit.framework.TestCase; + +/** + * @version $Rev$ $Date$ + */ +public class EventTestCase extends TestCase { + private URI uri = URI.create("foo"); + + public void testCompositeStart() { + ComponentStart event = new ComponentStart(this, uri); + assertEquals(uri, event.getComponentURI()); + } + + public void testCompositeStop() { + ComponentStop event = new ComponentStop(this, uri); + assertEquals(uri, event.getComponentURI()); + } + + public void testHttpSessionStart() { + Object id = new Object(); + HttpSessionStart event = new HttpSessionStart(this, id); + assertEquals(this, event.getSource()); + assertEquals(id, event.getSessionID()); + } + + public void testHttpSessionEnd() { + Object id = new Object(); + HttpSessionEnd event = new HttpSessionEnd(this, id); + assertEquals(this, event.getSource()); + assertEquals(id, event.getSessionID()); + } + + public void testRequestStart() { + RequestStart event = new RequestStart(this); + assertEquals(this, event.getSource()); + } + + public void testReequestEnd() { + RequestEnd event = new RequestEnd(this); + assertEquals(this, event.getSource()); + } + + + protected void setUp() throws Exception { + super.setUp(); + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/AsyncTarget.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/AsyncTarget.java new file mode 100644 index 0000000000..c30e19de88 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/AsyncTarget.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.core.mock.component; + +import org.osoa.sca.annotations.OneWay; + +/** + * @version $Rev$ $Date$ + */ +public interface AsyncTarget { + @OneWay + void invoke(); + + int getCount(); +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/BadContextPojo.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/BadContextPojo.java new file mode 100644 index 0000000000..f9ae94f152 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/BadContextPojo.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.core.mock.component; + +import org.osoa.sca.annotations.Context; + +public class BadContextPojo { + + @Context + String context; + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/BadNamePojo.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/BadNamePojo.java new file mode 100644 index 0000000000..c4074484b9 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/BadNamePojo.java @@ -0,0 +1,26 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.mock.component; + +import org.osoa.sca.annotations.ComponentName; + +public class BadNamePojo { + @ComponentName + private int name; +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/BasicInterface.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/BasicInterface.java new file mode 100644 index 0000000000..ca305b9ef0 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/BasicInterface.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.core.mock.component; + +/** + * @version $Rev$ $Date$ + */ +public interface BasicInterface { + String returnsProperty(); + + BasicInterface returnsReference(); + + int returnsInt(); +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/BasicInterfaceImpl.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/BasicInterfaceImpl.java new file mode 100644 index 0000000000..ea32d1f6b9 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/BasicInterfaceImpl.java @@ -0,0 +1,66 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.mock.component; + +import org.osoa.sca.annotations.Property; +import org.osoa.sca.annotations.Reference; + +/** + * @version $Rev$ $Date$ + */ +public class BasicInterfaceImpl implements BasicInterface { + + @Property + public String publicProperty; + + @Reference (required = false) + public BasicInterface publicReference; + + @Property + protected String protectedProperty; + + @Reference (required = false) + protected BasicInterface protectedReference; + + private String privateProperty; + + private BasicInterface privateReference; + + @Property + public void setPrivateProperty(String privateProperty) { + this.privateProperty = privateProperty; + } + + @Reference (required = false) + public void setPrivateReference(BasicInterface privateReference) { + this.privateReference = privateReference; + } + + public String returnsProperty() { + return privateProperty; + } + + public BasicInterface returnsReference() { + return privateReference; + } + + public int returnsInt() { + return 0; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/CompositeScopeComponent.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/CompositeScopeComponent.java new file mode 100644 index 0000000000..6d320df145 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/CompositeScopeComponent.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.core.mock.component; + +import org.osoa.sca.annotations.Scope; + +/** + * @version $Rev$ $Date$ + */ +@Scope("COMPOSITE") +public interface CompositeScopeComponent { + + //public boolean isInit(); +} + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/CompositeScopeComponentImpl.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/CompositeScopeComponentImpl.java new file mode 100644 index 0000000000..9ff289a502 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/CompositeScopeComponentImpl.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.mock.component; + +import org.osoa.sca.annotations.Scope; + + +/** + * @version $Rev$ $Date$ + */ +@Scope("COMPOSITE") +public class CompositeScopeComponentImpl implements + CompositeScopeComponent { + + private String foo; + + public void setFoo(String foo) { + this.foo = foo; + } + + public String getFoo() { + return foo; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/CompositeScopeDestroyOnlyComponent.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/CompositeScopeDestroyOnlyComponent.java new file mode 100644 index 0000000000..832055a084 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/CompositeScopeDestroyOnlyComponent.java @@ -0,0 +1,36 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.mock.component; + +import org.osoa.sca.annotations.Destroy; + +public class CompositeScopeDestroyOnlyComponent extends CompositeScopeComponentImpl { + + boolean destroyed; + + public boolean isDestroyed() { + return destroyed; + } + + @Destroy + public void destroy() { + destroyed = true; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/CompositeScopeInitDestroyComponent.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/CompositeScopeInitDestroyComponent.java new file mode 100644 index 0000000000..e8b76e13c0 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/CompositeScopeInitDestroyComponent.java @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.mock.component; + +import org.osoa.sca.annotations.Destroy; + +public class CompositeScopeInitDestroyComponent extends CompositeScopeInitOnlyComponent { + + boolean destroyed; + + public boolean isDestroyed() { + return destroyed; + } + + @Destroy + public void destroy() { + if (destroyed) { + throw new AssertionError("Destroy called more than once"); + } + destroyed = true; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/CompositeScopeInitOnlyComponent.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/CompositeScopeInitOnlyComponent.java new file mode 100644 index 0000000000..057580be7a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/CompositeScopeInitOnlyComponent.java @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.mock.component; + +import org.osoa.sca.annotations.Init; + +public class CompositeScopeInitOnlyComponent extends CompositeScopeComponentImpl { + + private boolean initialized; + // this value tests to ensure introspection can find the init() method even + // if a field is named the same. Ultimately, this should be in the introspection tests + private boolean init; + + public boolean isInitialized() { + return initialized; + } + + @Init + public void init() { + if (initialized) { + throw new AssertionError("Init called more than once"); + } + initialized = true; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/ConversationalScopeComponent.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/ConversationalScopeComponent.java new file mode 100644 index 0000000000..79f48a57c5 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/ConversationalScopeComponent.java @@ -0,0 +1,29 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.mock.component; + +import org.osoa.sca.annotations.Scope; + +/** + * @version $Rev: 430937 $ $Date: 2006-08-11 21:17:56 -0400 (Fri, 11 Aug 2006) $ + */ +@Scope("CONVERSATION") +public interface ConversationalScopeComponent { + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/ConversationalScopeComponentImpl.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/ConversationalScopeComponentImpl.java new file mode 100644 index 0000000000..5b42d92191 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/ConversationalScopeComponentImpl.java @@ -0,0 +1,29 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.mock.component; + +import org.osoa.sca.annotations.Scope; + +/** + * @version $Rev: 430937 $ $Date: 2006-08-11 21:17:56 -0400 (Fri, 11 Aug 2006) $ + */ +@Scope("CONVERSATION") +public class ConversationalScopeComponentImpl implements ConversationalScopeComponent { + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/ConversationalScopeDestroyOnlyComponent.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/ConversationalScopeDestroyOnlyComponent.java new file mode 100644 index 0000000000..c64556e754 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/ConversationalScopeDestroyOnlyComponent.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.mock.component; + +import org.osoa.sca.annotations.Destroy; +import org.osoa.sca.annotations.Scope; + +@Scope("CONVERSATION") +public class ConversationalScopeDestroyOnlyComponent extends ConversationalScopeComponentImpl { + + boolean destroyed; + + public boolean isDestroyed() { + return destroyed; + } + + @Destroy + public void destroy() { + destroyed = true; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/ConversationalScopeInitDestroyComponent.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/ConversationalScopeInitDestroyComponent.java new file mode 100644 index 0000000000..6f930ef750 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/ConversationalScopeInitDestroyComponent.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.mock.component; + +import org.osoa.sca.annotations.Destroy; +import org.osoa.sca.annotations.Scope; + +@Scope("CONVERSATION") +public class ConversationalScopeInitDestroyComponent + extends ConversationalScopeInitOnlyComponent { + + private boolean destroyed; + + public boolean isDestroyed() { + return destroyed; + } + + @Destroy + public void destroy() { + destroyed = true; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/ConversationalScopeInitOnlyComponent.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/ConversationalScopeInitOnlyComponent.java new file mode 100644 index 0000000000..70733f4d99 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/ConversationalScopeInitOnlyComponent.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.mock.component; + +import org.osoa.sca.annotations.Init; +import org.osoa.sca.annotations.Scope; + +@Scope("CONVERSATION") +public class ConversationalScopeInitOnlyComponent + extends ConversationalScopeComponentImpl { + + private boolean initialized; + + public boolean isInitialized() { + return initialized; + } + + @Init + public void init() { + initialized = true; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/OrderException.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/OrderException.java new file mode 100644 index 0000000000..4bb9cde958 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/OrderException.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.mock.component; + +public class OrderException extends Exception { + + public OrderException() { + super(); + } + + public OrderException(String message) { + super(message); + } + + public OrderException(String message, Throwable cause) { + super(message, cause); + } + + public OrderException(Throwable cause) { + super(cause); + } + +} + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/OrderedDependentPojo.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/OrderedDependentPojo.java new file mode 100644 index 0000000000..df59029884 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/OrderedDependentPojo.java @@ -0,0 +1,29 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.mock.component; + +/** + * @version $$Rev$$ $$Date$$ + */ +public interface OrderedDependentPojo extends OrderedInitPojo { + + OrderedInitPojo getPojo(); + + void setPojo(OrderedInitPojo pojo); +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/OrderedDependentPojoImpl.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/OrderedDependentPojoImpl.java new file mode 100644 index 0000000000..1b51c2772d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/OrderedDependentPojoImpl.java @@ -0,0 +1,36 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.mock.component; + +/** + * @version $$Rev$$ $$Date$$ + */ +public class OrderedDependentPojoImpl extends OrderedInitPojoImpl implements OrderedDependentPojo { + + private OrderedInitPojo pojo; + + public OrderedInitPojo getPojo() { + return pojo; + } + + public void setPojo(OrderedInitPojo pojo) { + this.pojo = pojo; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/OrderedEagerInitPojo.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/OrderedEagerInitPojo.java new file mode 100644 index 0000000000..139086bf0d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/OrderedEagerInitPojo.java @@ -0,0 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.mock.component; + +import org.osoa.sca.annotations.Destroy; +import org.osoa.sca.annotations.EagerInit; +import org.osoa.sca.annotations.Init; +import org.osoa.sca.annotations.Scope; + +@Scope("COMPOSITE") +@EagerInit +public class OrderedEagerInitPojo { + + private static final Object LOCK = new Object(); + private static int numberInstantied; + private int initOrder; + + @Init + public void init() { + synchronized (LOCK) { + ++numberInstantied; + initOrder = numberInstantied; + } + } + + @Destroy + public void destroy() throws OrderException { + synchronized (LOCK) { + if (initOrder != numberInstantied) { + throw new OrderException("Instance shutdown done out of order"); + } + --numberInstantied; + } + } + + public int getNumberInstantiated() { + return numberInstantied; + } + + public int getInitOrder() { + return initOrder; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/OrderedInitPojo.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/OrderedInitPojo.java new file mode 100644 index 0000000000..1c3615fcd0 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/OrderedInitPojo.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.core.mock.component; + +/** + * @version $$Rev$$ $$Date$$ + */ +public interface OrderedInitPojo { + int getNumberInstantiated(); + + int getInitOrder(); +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/OrderedInitPojoImpl.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/OrderedInitPojoImpl.java new file mode 100644 index 0000000000..b65ead9b19 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/OrderedInitPojoImpl.java @@ -0,0 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.mock.component; + +import org.osoa.sca.annotations.Destroy; +import org.osoa.sca.annotations.Init; +import org.osoa.sca.annotations.Scope; + +@Scope("COMPOSITE") +public class OrderedInitPojoImpl implements OrderedInitPojo { + + private static final Object LOCK = new Object(); + private static int numberInstantied; + private int initOrder; + + public OrderedInitPojoImpl() { + } + + @Init + public void init() { + synchronized (LOCK) { + ++numberInstantied; + initOrder = numberInstantied; + } + } + + @Destroy + public void destroy() throws OrderException { + synchronized (LOCK) { + if (initOrder != numberInstantied) { + throw new OrderException("Instance shutdown done out of order"); + } + --numberInstantied; + } + } + + public int getNumberInstantiated() { + return numberInstantied; + } + + public int getInitOrder() { + return initOrder; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/OtherTarget.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/OtherTarget.java new file mode 100644 index 0000000000..963c31a4ca --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/OtherTarget.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.core.mock.component; + +/** + * Implementations are used in wiring tests + * + * @version $Rev$ $Date$ + */ +public interface OtherTarget { + + String getString(); + + void setString(String val); +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/OtherTargetImpl.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/OtherTargetImpl.java new file mode 100644 index 0000000000..91ccc9e772 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/OtherTargetImpl.java @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.mock.component; + +/** + * A target used for testing wires with a different source and target interface + * + * @version $Rev$ $Date$ + */ +public class OtherTargetImpl implements OtherTarget { + + private String theString; + + public String getString() { + return theString; + } + + public void setString(String val) { + theString = val; + } + + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/RequestScopeComponent.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/RequestScopeComponent.java new file mode 100644 index 0000000000..7d03c4372d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/RequestScopeComponent.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.core.mock.component; + +import org.osoa.sca.annotations.Scope; + +/** + * @version $Rev$ $Date$ + */ +@Scope("REQUEST") +public interface RequestScopeComponent { + +} + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/RequestScopeDestroyOnlyComponent.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/RequestScopeDestroyOnlyComponent.java new file mode 100644 index 0000000000..f94f071086 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/RequestScopeDestroyOnlyComponent.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.mock.component; + +import org.osoa.sca.annotations.Destroy; +import org.osoa.sca.annotations.Scope; + +@Scope("REQUEST") +public class RequestScopeDestroyOnlyComponent extends SessionScopeComponentImpl { + + boolean destroyed; + + public boolean isDestroyed() { + return destroyed; + } + + @Destroy + public void destroy() { + destroyed = true; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/RequestScopeInitDestroyComponent.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/RequestScopeInitDestroyComponent.java new file mode 100644 index 0000000000..f2de2d9afa --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/RequestScopeInitDestroyComponent.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.mock.component; + +import org.osoa.sca.annotations.Destroy; +import org.osoa.sca.annotations.Scope; + +@Scope("REQUEST") +public class RequestScopeInitDestroyComponent extends SessionScopeInitOnlyComponent { + + boolean destroyed; + + public boolean isDestroyed() { + return destroyed; + } + + @Destroy + public void destroy() { + destroyed = true; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/RequestScopeInitOnlyComponent.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/RequestScopeInitOnlyComponent.java new file mode 100644 index 0000000000..9bcef40834 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/RequestScopeInitOnlyComponent.java @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.mock.component; + +import org.osoa.sca.annotations.Init; +import org.osoa.sca.annotations.Scope; + +@Scope("REQUEST") +public class RequestScopeInitOnlyComponent extends SessionScopeComponentImpl { + + private boolean initialized; + + public boolean isInitialized() { + return initialized; + } + + @Init + public void init() { + initialized = true; + } + + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/SessionScopeComponent.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/SessionScopeComponent.java new file mode 100644 index 0000000000..8318333feb --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/SessionScopeComponent.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.core.mock.component; + +import org.osoa.sca.annotations.Scope; + +/** + * @version $Rev$ $Date$ + */ +@Scope("SESSION") +public interface SessionScopeComponent { + +} + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/SessionScopeComponentImpl.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/SessionScopeComponentImpl.java new file mode 100644 index 0000000000..0494d587aa --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/SessionScopeComponentImpl.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.core.mock.component; + +import org.osoa.sca.annotations.Scope; + +/** + * @version $Rev$ $Date$ + */ +@Scope("SESSION") +public class SessionScopeComponentImpl implements + SessionScopeComponent { + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/SessionScopeInitDestroyComponent.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/SessionScopeInitDestroyComponent.java new file mode 100644 index 0000000000..fdc11a80af --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/SessionScopeInitDestroyComponent.java @@ -0,0 +1,36 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.mock.component; + +import org.osoa.sca.annotations.Destroy; + +public class SessionScopeInitDestroyComponent extends SessionScopeInitOnlyComponent { + + private boolean destroyed; + + public boolean isDestroyed() { + return destroyed; + } + + @Destroy + public void destroy() { + destroyed = true; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/SessionScopeInitOnlyComponent.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/SessionScopeInitOnlyComponent.java new file mode 100644 index 0000000000..4e849895f8 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/SessionScopeInitOnlyComponent.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.mock.component; + +import org.osoa.sca.annotations.Init; + +public class SessionScopeInitOnlyComponent extends SessionScopeComponentImpl { + + private boolean initialized; + + public boolean isInitialized() { + return initialized; + } + + @Init + public void init() { + initialized = true; + } + + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/SimpleTarget.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/SimpleTarget.java new file mode 100644 index 0000000000..44eb94260e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/SimpleTarget.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.core.mock.component; + +public interface SimpleTarget { + + String hello(String message) throws Exception; + + String goodbye(String message) throws Exception; + + String echo(String message) throws Exception; + +} + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/SimpleTargetImpl.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/SimpleTargetImpl.java new file mode 100644 index 0000000000..662b21116a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/SimpleTargetImpl.java @@ -0,0 +1,41 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.mock.component; + +public class SimpleTargetImpl implements SimpleTarget { + + public SimpleTargetImpl() { + super(); + } + + public String hello(String message) throws Exception { + return message; + } + + public String goodbye(String message) throws Exception { + return message; + } + + public String echo(String message) throws Exception { + return message; + } + + +} + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/Source.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/Source.java new file mode 100644 index 0000000000..aa3b5be528 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/Source.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.mock.component; + +import java.util.List; + +/** + * Implementations are used in wiring tests + * + * @version $Rev$ $Date$ + */ +public interface Source { + + Target getTarget(); + + List getTargets(); + + List getTargetsThroughField(); + +} + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/SourceImpl.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/SourceImpl.java new file mode 100644 index 0000000000..81e39a9fe9 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/SourceImpl.java @@ -0,0 +1,63 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.mock.component; + +import java.util.List; + +/** + * Mock system component implementation used in wiring tests + * + * @version $Rev$ $Date$ + */ +public class SourceImpl implements Source { + + private Target target; + private List targets; + private List targetsThroughField; + private Target[] targetsArray; + + public void setTarget(Target target) { + this.target = target; + } + + public Target getTarget() { + return target; + } + + public List getTargets() { + return targets; + } + + public void setTargets(List targets) { + this.targets = targets; + } + + public List getTargetsThroughField() { + return targetsThroughField; + } + + public Target[] getArrayOfTargets() { + return targetsArray; + } + + public void setArrayOfTargets(Target[] targets) { + targetsArray = targets; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/StatelessComponent.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/StatelessComponent.java new file mode 100644 index 0000000000..89d0be7a53 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/StatelessComponent.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.core.mock.component; + +import org.osoa.sca.annotations.Scope; + +/** + * @version $Rev$ $Date$ + */ +@Scope("STATELESS") +public interface StatelessComponent { + +} + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/StatelessComponentImpl.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/StatelessComponentImpl.java new file mode 100644 index 0000000000..28eb28e76d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/StatelessComponentImpl.java @@ -0,0 +1,27 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.mock.component; + +/** + * @version $Rev$ $Date$ + */ +public class StatelessComponentImpl implements + StatelessComponent { + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/Target.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/Target.java new file mode 100644 index 0000000000..5e85ed48b0 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/Target.java @@ -0,0 +1,32 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.mock.component; + +/** + * Implementations are used in wiring tests + * + * @version $Rev$ $Date$ + */ +public interface Target { + + String getString(); + + void setString(String val); +} + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/TargetImpl.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/TargetImpl.java new file mode 100644 index 0000000000..169b38a8d0 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/mock/component/TargetImpl.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.mock.component; + +/** + * Mock system component implementation used in wiring tests + * + * @version $Rev$ $Date$ + */ +public class TargetImpl implements Target { + + private String theString; + + public String getString() { + return theString; + } + + public void setString(String val) { + theString = val; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/scope/AbstractScopeContainerTestCase.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/scope/AbstractScopeContainerTestCase.java new file mode 100644 index 0000000000..5be8fe21b3 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/scope/AbstractScopeContainerTestCase.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.scope; + +import java.net.URI; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.assembly.Implementation; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.scope.InstanceWrapper; +import org.apache.tuscany.sca.scope.ScopeContainer; +import org.apache.tuscany.sca.scope.ScopedImplementationProvider; +import org.easymock.EasyMock; +import org.easymock.IMocksControl; + +/** + * @version $Rev$ $Date$ + */ +public abstract class AbstractScopeContainerTestCase extends TestCase { + protected IMocksControl control; + protected ScopeContainer scopeContainer; + protected URI groupId; + protected KEY contextId; + protected RuntimeComponent component; + protected ScopedImplementation implementation; + protected InstanceWrapper wrapper; + + @SuppressWarnings("unchecked") + protected void setUp() throws Exception { + super.setUp(); + control = EasyMock.createStrictControl(); + component = control.createMock(RuntimeComponent.class); + wrapper = control.createMock(InstanceWrapper.class); + implementation = control.createMock(ScopedImplementation.class); + EasyMock.expect(component.getImplementation()).andReturn(implementation).anyTimes(); + } + + protected void preRegisterComponent() throws Exception { + scopeContainer.start(); + EasyMock.expect(implementation.isEagerInit()).andStubReturn(false); + } + + protected void expectCreateWrapper() throws Exception { + EasyMock.expect(implementation.createInstanceWrapper()).andReturn(wrapper); + wrapper.start(); + } + + protected static interface ScopedImplementation extends ScopedImplementationProvider, Implementation { + + } + + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/store/MemoryStoreTestCase.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/store/MemoryStoreTestCase.java new file mode 100644 index 0000000000..2f5c182f45 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/store/MemoryStoreTestCase.java @@ -0,0 +1,165 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.store; + +import java.util.UUID; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.event.RuntimeEventListener; +import org.apache.tuscany.sca.runtime.RuntimeComponent; +import org.apache.tuscany.sca.store.DuplicateRecordException; +import org.apache.tuscany.sca.store.Store; +import org.apache.tuscany.sca.store.StoreExpirationEvent; +import org.apache.tuscany.sca.store.StoreMonitor; +import org.easymock.EasyMock; +import org.easymock.IAnswer; + +/** + * @version $Rev$ $Date$ + */ +public class MemoryStoreTestCase extends TestCase { + private StoreMonitor monitor; + + public void testEviction() throws Exception { + MemoryStore store = new MemoryStore(monitor); + store.setReaperInterval(10); + store.init(); + RuntimeComponent component = EasyMock.createNiceMock(RuntimeComponent.class); + EasyMock.replay(component); + String id = UUID.randomUUID().toString(); + Object value = new Object(); + store.insertRecord(component, id, value, 1); + Thread.sleep(200); + assertNull(store.readRecord(component, id)); + store.destroy(); + } + + public void testNotifyOnEviction() throws Exception { + final CountDownLatch latch = new CountDownLatch(1); + RuntimeEventListener listener = EasyMock.createMock(RuntimeEventListener.class); + listener.onEvent(EasyMock.isA(StoreExpirationEvent.class)); + EasyMock.expectLastCall().andStubAnswer(new IAnswer() { + public Object answer() throws Throwable { + latch.countDown(); + return null; + } + }); + EasyMock.replay(listener); + MemoryStore store = new MemoryStore(monitor); + store.addListener(listener); + store.setReaperInterval(10); + store.init(); + RuntimeComponent component = EasyMock.createNiceMock(RuntimeComponent.class); + EasyMock.replay(component); + String id = UUID.randomUUID().toString(); + Object value = new Object(); + store.insertRecord(component, id, value, 1); + if (!latch.await(1000, TimeUnit.MILLISECONDS)) { + // failed to notify listener + fail(); + } + EasyMock.verify(listener); + } + + public void testNoEviction() throws Exception { + MemoryStore store = new MemoryStore(monitor); + store.setReaperInterval(10); + store.init(); + RuntimeComponent component = EasyMock.createNiceMock(RuntimeComponent.class); + EasyMock.replay(component); + String id = UUID.randomUUID().toString(); + Object value = new Object(); + store.insertRecord(component, id, value, Store.NEVER); + Thread.sleep(100); + assertNotNull(store.readRecord(component, id)); + store.destroy(); + } + + public void testInsertRecord() throws Exception { + MemoryStore store = new MemoryStore(monitor); + store.setReaperInterval(10); + store.init(); + RuntimeComponent component = EasyMock.createNiceMock(RuntimeComponent.class); + EasyMock.replay(component); + String id = UUID.randomUUID().toString(); + Object value = new Object(); + store.insertRecord(component, id, value, Store.NEVER); + store.destroy(); + } + + public void testInsertAlreadyExists() throws Exception { + MemoryStore store = new MemoryStore(monitor); + store.setReaperInterval(10); + store.init(); + RuntimeComponent component = EasyMock.createMock(RuntimeComponent.class); + EasyMock.expect(component.getURI()).andReturn("component"); + EasyMock.replay(component); + String id = UUID.randomUUID().toString(); + Object value = new Object(); + store.insertRecord(component, id, value, Store.NEVER); + try { + store.insertRecord(component, id, value, Store.NEVER); + fail(); + } catch (DuplicateRecordException e) { + //expected + } + store.destroy(); + } + + public void testUpdateRecord() throws Exception { + MemoryStore store = new MemoryStore(monitor); + store.setReaperInterval(10); + store.init(); + RuntimeComponent component = EasyMock.createNiceMock(RuntimeComponent.class); + EasyMock.replay(component); + String id = UUID.randomUUID().toString(); + Object value = new Object(); + Object newValue = new Object(); + + store.insertRecord(component, id, value, Store.NEVER); + store.updateRecord(component, id, newValue, 1L); + assertEquals(newValue, store.readRecord(component, id)); + store.destroy(); + } + + public void testDeleteRecord() throws Exception { + MemoryStore store = new MemoryStore(monitor); + store.setReaperInterval(10); + store.init(); + RuntimeComponent component = EasyMock.createNiceMock(RuntimeComponent.class); + EasyMock.replay(component); + String id = UUID.randomUUID().toString(); + Object value = new Object(); + + store.insertRecord(component, id, value, Store.NEVER); + store.removeRecord(component, id); + assertNull(store.readRecord(component, id)); + store.destroy(); + } + + protected void setUp() throws Exception { + super.setUp(); + monitor = EasyMock.createNiceMock(StoreMonitor.class); + EasyMock.replay(monitor); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/wire/CallbackInterfaceInterceptorTestCase.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/wire/CallbackInterfaceInterceptorTestCase.java new file mode 100644 index 0000000000..58503fd852 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/wire/CallbackInterfaceInterceptorTestCase.java @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.wire; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.core.invocation.CallbackInterfaceInterceptor; +import org.apache.tuscany.sca.core.invocation.MessageFactoryImpl; +import org.apache.tuscany.sca.invocation.Interceptor; +import org.apache.tuscany.sca.invocation.Message; +import org.easymock.EasyMock; +import org.osoa.sca.NoRegisteredCallbackException; + +/** + * @version $Rev$ $Date$ + */ +public class CallbackInterfaceInterceptorTestCase extends TestCase { + + public void testImplements() { + CallbackInterfaceInterceptor interceptor = new CallbackInterfaceInterceptor(true); + Interceptor next = EasyMock.createMock(Interceptor.class); + EasyMock.expect(next.invoke(EasyMock.isA(Message.class))).andReturn(null); + EasyMock.replay(next); + interceptor.setNext(next); + interceptor.invoke(new MessageFactoryImpl().createMessage()); + EasyMock.verify(next); + } + + public void testDoesNotImplement() { + CallbackInterfaceInterceptor interceptor = new CallbackInterfaceInterceptor(false); + try { + interceptor.invoke(new MessageFactoryImpl().createMessage()); + fail(); + } catch (NoRegisteredCallbackException e) { + // expected + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/wire/InvocationChainImplTestCase.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/wire/InvocationChainImplTestCase.java new file mode 100644 index 0000000000..83f7bdd887 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/wire/InvocationChainImplTestCase.java @@ -0,0 +1,66 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.wire; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.core.invocation.InvocationChainImpl; +import org.apache.tuscany.sca.interfacedef.impl.OperationImpl; +import org.apache.tuscany.sca.invocation.Interceptor; +import org.apache.tuscany.sca.invocation.InvocationChain; +import org.apache.tuscany.sca.invocation.Invoker; +import org.apache.tuscany.sca.invocation.Message; + +/** + * @version $Rev$ $Date$ + */ +public class InvocationChainImplTestCase extends TestCase { + + public void testInsertAtEnd() throws Exception { + InvocationChain chain = new InvocationChainImpl(new OperationImpl("foo")); + Interceptor inter2 = new MockInterceptor(); + Interceptor inter1 = new MockInterceptor(); + chain.addInterceptor(inter1); + chain.addInterceptor(inter2); + Interceptor head = (Interceptor)chain.getHeadInvoker(); + assertEquals(inter1, head); + assertEquals(inter2, head.getNext()); + assertEquals(inter2, chain.getTailInvoker()); + + } + + private class MockInterceptor implements Interceptor { + + private Invoker next; + + public Message invoke(Message msg) { + return null; + } + + public void setNext(Invoker next) { + this.next = next; + } + + public Invoker getNext() { + return next; + } + + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/wire/NonBlockingInterceptorTestCase.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/wire/NonBlockingInterceptorTestCase.java new file mode 100644 index 0000000000..c5f93edeb6 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/core/wire/NonBlockingInterceptorTestCase.java @@ -0,0 +1,72 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.core.wire; + +import static org.easymock.EasyMock.createMock; +import static org.easymock.EasyMock.expectLastCall; +import static org.easymock.EasyMock.getCurrentArguments; +import static org.easymock.EasyMock.isA; +import static org.easymock.EasyMock.replay; +import static org.easymock.EasyMock.verify; +import junit.framework.TestCase; + +import org.apache.tuscany.sca.core.invocation.NonBlockingInterceptor; +import org.apache.tuscany.sca.core.invocation.ThreadMessageContext; +import org.apache.tuscany.sca.invocation.Interceptor; +import org.apache.tuscany.sca.invocation.Message; +import org.apache.tuscany.sca.work.WorkScheduler; +import org.easymock.EasyMock; +import org.easymock.IAnswer; + +/** + * @version $Rev$ $Date$ + */ +public class NonBlockingInterceptorTestCase extends TestCase { + + public void testInvoke() throws Exception { + WorkScheduler scheduler = createMock(WorkScheduler.class); + scheduler.scheduleWork(isA(Runnable.class)); + expectLastCall().andStubAnswer(new IAnswer() { + public Object answer() throws Throwable { + Runnable runnable = (Runnable) getCurrentArguments()[0]; + runnable.run(); + return null; + } + }); + replay(scheduler); + Message context = createMock(Message.class); + String convID = "convID"; + EasyMock.expect(context.getConversationID()).andReturn(convID); + EasyMock.replay(context); + ThreadMessageContext.setMessageContext(context); + Message msg = createMock(Message.class); + msg.setCorrelationID(null); + msg.setConversationID(convID); + Interceptor next = EasyMock.createMock(Interceptor.class); + EasyMock.expect(next.invoke(EasyMock.eq(msg))).andReturn(msg); + EasyMock.replay(next); + EasyMock.replay(msg); + Interceptor interceptor = new NonBlockingInterceptor(scheduler, next); + interceptor.invoke(msg); + verify(context); + verify(next); + verify(msg); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/factory/AssertionTestCase.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/factory/AssertionTestCase.java new file mode 100644 index 0000000000..77d0e01dc9 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/factory/AssertionTestCase.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.factory; + +import junit.framework.TestCase; + +/** + * @version $Rev$ $Date$ + */ +public class AssertionTestCase extends TestCase { + /** + * test case that confirms that JRE assertions are enabled + */ + public void testAssertionsAreEnabled() { + try { + assert false; + fail("assertions are not enabled"); + } catch (AssertionError e) { + // ok + } + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/factory/SingletonObjectFactoryTestCase.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/factory/SingletonObjectFactoryTestCase.java new file mode 100644 index 0000000000..4d38c447ea --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/factory/SingletonObjectFactoryTestCase.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.factory; + +import junit.framework.TestCase; + +/** + * @version $Rev$ $Date$ + */ +public class SingletonObjectFactoryTestCase extends TestCase { + + public void testSingleton() throws Exception { + Object o = new Object(); + SingletonObjectFactory factory = new SingletonObjectFactory(o); + assertEquals(o, factory.getInstance()); + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/scope/ScopeTestCase.java b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/scope/ScopeTestCase.java new file mode 100644 index 0000000000..1b95c6ff63 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/core/src/test/java/org/apache/tuscany/sca/scope/ScopeTestCase.java @@ -0,0 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.scope; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.scope.Scope; + +/** + * @version $Rev$ $Date$ + */ +public class ScopeTestCase extends TestCase { + + public void testEquals() throws Exception { + Scope scope = new Scope("COMPOSITE"); + assertTrue(scope.equals(Scope.COMPOSITE)); + } + + public void testEqualsNew() throws Exception { + Scope foo = new Scope("foo"); + Scope foo2 = new Scope("FOO"); + assertTrue(foo.equals(foo2)); + } + + public void testNotEquals() throws Exception { + Scope foo = new Scope("BAR"); + Scope foo2 = new Scope("FOO"); + assertFalse(foo.equals(foo2)); + } + + public void testNotEqualsDifferent() throws Exception { + Scope foo = new Scope("FOO"); + assertFalse(foo.equals(new Bar("FOO"))); + } + + public class Bar { + String scope; + + public Bar(String scope) { + this.scope = scope; + } + } + + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/.ruleset b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/.ruleset new file mode 100644 index 0000000000..27b9ab847c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/.ruleset @@ -0,0 +1,191 @@ + + + + + PMD Plugin preferences rule set + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/DISCLAIMER b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/DISCLAIMER new file mode 100644 index 0000000000..d68a410903 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/DISCLAIMER @@ -0,0 +1,8 @@ +Apache Tuscany is an effort undergoing incubation at The Apache Software +Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is +required of all newly accepted projects until a further review indicates that +the infrastructure, communications, and decision making process have stabilized +in a manner consistent with other successful ASF projects. While incubation +status is not necessarily a reflection of the completeness or stability of the +code, it does indicate that the project has yet to be fully endorsed by the ASF. + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/LICENSE b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/NOTICE b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/NOTICE new file mode 100644 index 0000000000..94481d6cfa --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2007 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/pom.xml b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/pom.xml new file mode 100755 index 0000000000..0b1211c2da --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/pom.xml @@ -0,0 +1,91 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 0.91-incubating-SNAPSHOT + ../pom.xml + + tuscany-databinding-axiom + Apache Tuscany Data Binding for Axiom + + + + org.apache.tuscany.sca + tuscany-core-spi + 0.91-incubating-SNAPSHOT + + + org.apache.tuscany.sca + tuscany-databinding + 0.91-incubating-SNAPSHOT + + + + stax + stax-api + 1.0.1 + + + + org.apache.ws.commons.axiom + axiom-api + + + xerces + xercesImpl + + + 1.2.4 + + + + xerces + xercesImpl + 2.8.1 + runtime + + + + org.apache.ws.commons.axiom + axiom-impl + 1.2.4 + runtime + + + + commons-logging + commons-logging + 1.1 + runtime + + + + org.codehaus.woodstox + wstx-asl + 3.2.0 + runtime + + + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/AxiomDataBinding.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/AxiomDataBinding.java new file mode 100644 index 0000000000..72fc90d187 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/AxiomDataBinding.java @@ -0,0 +1,64 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.databinding.axiom; + +import org.apache.axiom.om.OMElement; +import org.apache.tuscany.sca.databinding.ExceptionHandler; +import org.apache.tuscany.sca.databinding.WrapperHandler; +import org.apache.tuscany.sca.databinding.impl.BaseDataBinding; + +/** + * DataBinding for AXIOM + */ +public class AxiomDataBinding extends BaseDataBinding { + + public static final String NAME = OMElement.class.getName(); + public static final String[] ALIASES = new String[] {"axiom"}; + + public AxiomDataBinding() { + super(NAME, ALIASES, OMElement.class); + } + + /** + * @see org.apache.tuscany.sca.databinding.impl.BaseDataBinding#getWrapperHandler() + */ + @Override + public WrapperHandler getWrapperHandler() { + return new OMElementWrapperHandler(); + } + + public Object copy(Object source) { + if ( OMElement.class.isAssignableFrom(source.getClass()) ) { + try { + OMElement sourceElement = (OMElement)source; + return sourceElement.cloneOMElement(); + } catch ( Exception e ) { + throw new IllegalArgumentException(e); + } + } + return super.copy(source); + } + + @Override + public ExceptionHandler getExceptionHandler() { + return new AxiomExceptionHandler(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/AxiomExceptionHandler.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/AxiomExceptionHandler.java new file mode 100644 index 0000000000..dd4553fc6a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/AxiomExceptionHandler.java @@ -0,0 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.databinding.axiom; + +import org.apache.axiom.om.OMElement; +import org.apache.tuscany.sca.databinding.ExceptionHandler; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; +import org.apache.tuscany.sca.interfacedef.util.FaultException; +import org.apache.tuscany.sca.interfacedef.util.XMLType; + +/** + * AXIOM implementation of ExceptionHandler + * + * @version $Rev$ $Date$ + */ +public class AxiomExceptionHandler implements ExceptionHandler { + + public Exception createException(DataType exceptionType, String message, Object faultInfo, Throwable cause) { + return new FaultException(message, (OMElement)faultInfo, cause); + } + + public Object getFaultInfo(Exception exception) { + if (exception == null) { + return null; + } + FaultException faultException = (FaultException)exception; + return faultException.getFaultInfo(); + + } + + public DataType getFaultType(DataType exceptionType) { + if (FaultException.class == exceptionType.getPhysical()) { + XMLType type = XMLType.UNKNOWN; + if(exceptionType.getLogical() instanceof XMLType) { + type = (XMLType) exceptionType.getLogical(); + } + DataType faultType = new DataTypeImpl(AxiomDataBinding.NAME, OMElement.class, type); + return faultType; + } else { + return null; + } + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/AxiomHelper.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/AxiomHelper.java new file mode 100644 index 0000000000..28141cd144 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/AxiomHelper.java @@ -0,0 +1,64 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.databinding.axiom; + +import javax.xml.namespace.QName; + +import org.apache.axiom.om.OMAbstractFactory; +import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.OMFactory; +import org.apache.axiom.om.OMNamespace; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.util.XMLType; + +/** + * Helper for AXIOM + * + * @version $Rev$ $Date$ + */ +public class AxiomHelper { + + private AxiomHelper() { + } + + /** + * @param context + * @param element + */ + public static void adjustElementName(TransformationContext context, OMElement element) { + if (context != null) { + DataType dataType = context.getTargetDataType(); + Object logical = dataType == null ? null : dataType.getLogical(); + if (!(logical instanceof XMLType)) { + return; + } + XMLType xmlType = (XMLType)logical; + if (xmlType.isElement() && !xmlType.getElementName().equals(element.getQName())) { + // TODO: Throw expection or switch to the new Element + OMFactory factory = OMAbstractFactory.getOMFactory(); + QName name = xmlType.getElementName(); + OMNamespace namespace = factory.createOMNamespace(name.getNamespaceURI(), name.getPrefix()); + element.setNamespace(namespace); + element.setLocalName(name.getLocalPart()); + } + } + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/OMElement2Object.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/OMElement2Object.java new file mode 100644 index 0000000000..4d2bc2b4d6 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/OMElement2Object.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding.axiom; + +import org.apache.axiom.om.OMElement; +import org.apache.tuscany.sca.databinding.impl.SimpleType2JavaTransformer; + +/** + * Transformer to convert data from a simple java bject to OMElement + */ +public class OMElement2Object extends SimpleType2JavaTransformer { + + @Override + protected String getText(OMElement source) { + return source.getText(); + } + + public Class getSourceType() { + return OMElement.class; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/OMElement2String.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/OMElement2String.java new file mode 100755 index 0000000000..3eb5878de3 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/OMElement2String.java @@ -0,0 +1,59 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding.axiom; + +import java.io.StringWriter; + +import javax.xml.stream.XMLStreamException; + +import org.apache.axiom.om.OMElement; +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; + +/** + * Transformer to convert data from an OMElement to XML String + */ +public class OMElement2String extends BaseTransformer implements PullTransformer { + // private XmlOptions options; + + public String transform(OMElement source, TransformationContext context) { + try { + StringWriter writer = new StringWriter(); + source.serialize(writer); + return writer.toString(); + } catch (XMLStreamException e) { + throw new TransformationException(e); + } + } + + public Class getSourceType() { + return OMElement.class; + } + + public Class getTargetType() { + return String.class; + } + + public int getWeight() { + return 40; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/OMElement2XMLStreamReader.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/OMElement2XMLStreamReader.java new file mode 100755 index 0000000000..c72bee62e2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/OMElement2XMLStreamReader.java @@ -0,0 +1,47 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding.axiom; + +import javax.xml.stream.XMLStreamReader; + +import org.apache.axiom.om.OMElement; +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; + +public class OMElement2XMLStreamReader extends BaseTransformer implements PullTransformer { + // private XmlOptions options; + + public XMLStreamReader transform(OMElement source, TransformationContext context) { + return source.getXMLStreamReader(); + } + + public Class getSourceType() { + return OMElement.class; + } + + public Class getTargetType() { + return XMLStreamReader.class; + } + + public int getWeight() { + return 10; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/OMElementWrapperHandler.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/OMElementWrapperHandler.java new file mode 100644 index 0000000000..91d00c4c79 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/OMElementWrapperHandler.java @@ -0,0 +1,70 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.databinding.axiom; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import javax.xml.namespace.QName; + +import org.apache.axiom.om.OMAbstractFactory; +import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.OMFactory; +import org.apache.axiom.om.OMNamespace; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.WrapperHandler; +import org.apache.tuscany.sca.interfacedef.util.ElementInfo; + +/** + * OMElement wrapper handler implementation + */ +public class OMElementWrapperHandler implements WrapperHandler { + + private OMFactory factory; + + public OMElementWrapperHandler() { + super(); + this.factory = OMAbstractFactory.getOMFactory(); + } + + public OMElement create(ElementInfo element, TransformationContext context) { + OMElement wrapper = factory.createOMElement(element.getQName(), null); + return wrapper; + } + + public void setChild(OMElement wrapper, int i, ElementInfo childElement, Object value) { + OMElement element = (OMElement)value; + QName elementName = childElement.getQName(); + OMNamespace namespace = factory.createOMNamespace(elementName.getNamespaceURI(), elementName.getPrefix()); + element.setNamespace(namespace); + element.setLocalName(childElement.getQName().getLocalPart()); + wrapper.addChild((OMElement)value); + } + + public List getChildren(OMElement wrapper) { + List elements = new ArrayList(); + for (Iterator i = wrapper.getChildElements(); i.hasNext();) { + elements.add(i.next()); + } + return elements; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/Object2OMElement.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/Object2OMElement.java new file mode 100644 index 0000000000..50ac0ecae6 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/Object2OMElement.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding.axiom; + +import javax.xml.namespace.QName; + +import org.apache.axiom.om.OMAbstractFactory; +import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.OMFactory; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.impl.Java2SimpleTypeTransformer; + +/** + * Transformer to convert data from an simple OMElement to Java Object + */ +public class Object2OMElement extends Java2SimpleTypeTransformer { + + private OMFactory factory; + + public Object2OMElement() { + super(); + factory = OMAbstractFactory.getOMFactory(); + } + + protected OMElement createElement(QName element, String text, TransformationContext context) { + OMElement omElement = factory.createOMElement(element, null); + factory.createOMText(omElement, text); + return omElement; + } + + @Override + public Class getTargetType() { + return OMElement.class; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/String2OMElement.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/String2OMElement.java new file mode 100755 index 0000000000..b2549029f2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/String2OMElement.java @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding.axiom; + +import java.io.ByteArrayInputStream; + +import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.impl.builder.StAXOMBuilder; +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; + +public class String2OMElement extends BaseTransformer implements + PullTransformer { + + @SuppressWarnings("unchecked") + public OMElement transform(String source, TransformationContext context) { + try { + StAXOMBuilder builder = new StAXOMBuilder(new ByteArrayInputStream(source.getBytes())); + OMElement element = builder.getDocumentElement(); + AxiomHelper.adjustElementName(context, element); + return element; + } catch (Exception e) { + throw new TransformationException(e); + } + } + + public Class getTargetType() { + return OMElement.class; + } + + public Class getSourceType() { + return String.class; + } + + public int getWeight() { + return 40; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/XMLStreamReader2OMElement.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/XMLStreamReader2OMElement.java new file mode 100755 index 0000000000..ffb31aae0b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/XMLStreamReader2OMElement.java @@ -0,0 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding.axiom; + +import javax.xml.stream.XMLStreamReader; + +import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.impl.builder.StAXOMBuilder; +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; + +public class XMLStreamReader2OMElement extends BaseTransformer implements + PullTransformer { + + public XMLStreamReader2OMElement() { + super(); + } + + public OMElement transform(XMLStreamReader source, TransformationContext context) { + try { + StAXOMBuilder builder = new StAXOMBuilder(source); + OMElement element = builder.getDocumentElement(); + AxiomHelper.adjustElementName(context, element); + return element; + } catch (Exception e) { + throw new TransformationException(e); + } + } + + public Class getTargetType() { + return OMElement.class; + } + + public Class getSourceType() { + return XMLStreamReader.class; + } + + public int getWeight() { + return 10; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/module/AxiomDataBindingModuleActivator.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/module/AxiomDataBindingModuleActivator.java new file mode 100644 index 0000000000..8dd3cb0f51 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/module/AxiomDataBindingModuleActivator.java @@ -0,0 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.databinding.axiom.module; + +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.ModuleActivator; +import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint; +import org.apache.tuscany.sca.databinding.TransformerExtensionPoint; +import org.apache.tuscany.sca.databinding.axiom.AxiomDataBinding; +import org.apache.tuscany.sca.databinding.axiom.OMElement2Object; +import org.apache.tuscany.sca.databinding.axiom.OMElement2String; +import org.apache.tuscany.sca.databinding.axiom.OMElement2XMLStreamReader; +import org.apache.tuscany.sca.databinding.axiom.Object2OMElement; +import org.apache.tuscany.sca.databinding.axiom.String2OMElement; +import org.apache.tuscany.sca.databinding.axiom.XMLStreamReader2OMElement; + +/** + * Module activator for AXIOM databinding + * + * @version $Rev$ $Date$ + */ +public class AxiomDataBindingModuleActivator implements ModuleActivator { + + public Object[] getExtensionPoints() { + return null; + } + + public void start(ExtensionPointRegistry registry) { + DataBindingExtensionPoint dataBindings = registry.getExtensionPoint(DataBindingExtensionPoint.class); + dataBindings.addDataBinding(new AxiomDataBinding()); + + TransformerExtensionPoint transformers = registry.getExtensionPoint(TransformerExtensionPoint.class); + transformers.addTransformer(new Object2OMElement()); + transformers.addTransformer(new OMElement2Object()); + transformers.addTransformer(new OMElement2String()); + transformers.addTransformer(new OMElement2XMLStreamReader()); + transformers.addTransformer(new String2OMElement()); + transformers.addTransformer(new XMLStreamReader2OMElement()); + } + + public void stop(ExtensionPointRegistry registry) { + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator new file mode 100644 index 0000000000..394d11304d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# Implementation class for the ExtensionActivator +org.apache.tuscany.sca.databinding.axiom.module.AxiomDataBindingModuleActivator \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/test/java/org/apache/tuscany/sca/databinding/axiom/AxiomExceptionHandlerTestCase.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/test/java/org/apache/tuscany/sca/databinding/axiom/AxiomExceptionHandlerTestCase.java new file mode 100644 index 0000000000..d75d729294 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/test/java/org/apache/tuscany/sca/databinding/axiom/AxiomExceptionHandlerTestCase.java @@ -0,0 +1,108 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.databinding.axiom; + +import java.io.StringReader; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamReader; + +import junit.framework.TestCase; + +import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.impl.builder.StAXOMBuilder; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; +import org.apache.tuscany.sca.interfacedef.util.FaultException; +import org.apache.tuscany.sca.interfacedef.util.XMLType; + +/** + * Test case for SDOExceptionHandler + */ +public class AxiomExceptionHandlerTestCase extends TestCase { + private static final String IPO_XML = + "" + "" + + " " + + " Helen Zoe" + + " 47 Eden Street" + + " Cambridge" + + " CB1 1JR" + + " " + + " " + + " Robert Smith" + + " 8 Oak Avenue" + + " Old Town" + + " PA" + + " 95819" + + " " + + " " + + " " + + " Lapis necklace" + + " 1" + + " 99.95" + + " Want this for the holidays" + + " 1999-12-05" + + " " + + " " + + ""; + + private AxiomExceptionHandler handler; + private OMElement faultElement; + + /** + * @see junit.framework.TestCase#setUp() + */ + protected void setUp() throws Exception { + super.setUp(); + this.handler = new AxiomExceptionHandler(); + XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(new StringReader(IPO_XML)); + StAXOMBuilder builder = new StAXOMBuilder(reader); + faultElement = builder.getDocumentElement(); + } + + public void testGetFaultType() { + DataType dataType = handler.getFaultType(new DataTypeImpl(FaultException.class, null)); + assertEquals(OMElement.class, dataType.getPhysical()); + assertEquals(XMLType.UNKNOWN, dataType.getLogical()); + assertEquals(AxiomDataBinding.NAME, dataType.getDataBinding()); + dataType = handler.getFaultType(new DataTypeImpl(Exception.class, null)); + assertNull(dataType); + } + + public void testCreate() { + + Exception ex = handler.createException(null, "Order", faultElement, null); + assertTrue(ex instanceof FaultException); + FaultException exception = (FaultException)ex; + assertEquals("Order", exception.getMessage()); + assertSame(faultElement, exception.getFaultInfo()); + } + + public void testGetFaultInfo() { + FaultException exception = new FaultException("Order", faultElement, null); + Object faultInfo = handler.getFaultInfo(exception); + assertSame(faultElement, faultInfo); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/test/java/org/apache/tuscany/sca/databinding/axiom/OMElementTestCase.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/test/java/org/apache/tuscany/sca/databinding/axiom/OMElementTestCase.java new file mode 100755 index 0000000000..7c04a98859 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/test/java/org/apache/tuscany/sca/databinding/axiom/OMElementTestCase.java @@ -0,0 +1,103 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding.axiom; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamReader; + +import junit.framework.Assert; +import junit.framework.TestCase; + +import org.apache.axiom.om.OMElement; + +public class OMElementTestCase extends TestCase { + private static final String IPO_XML = + "" + "" + + " " + + " Helen Zoe" + + " 47 Eden Street" + + " Cambridge" + + " CB1 1JR" + + " " + + " " + + " Robert Smith" + + " 8 Oak Avenue" + + " Old Town" + + " PA" + + " 95819" + + " " + + " " + + " " + + " Lapis necklace" + + " 1" + + " 99.95" + + " Want this for the holidays" + + " 1999-12-05" + + " " + + " " + + ""; + + public final void testStringTransform() { + String2OMElement t1 = new String2OMElement(); + OMElement element = t1.transform(IPO_XML, null); + OMElement2String t2 = new OMElement2String(); + String xml = t2.transform(element, null); + Assert.assertNotNull(xml); + Assert.assertNotNull(xml.indexOf("") != -1); + } + + public final void testStringTransform2() { + String str = + "Robert"; + String2OMElement t1 = new String2OMElement(); + OMElement element = t1.transform(str, null); + OMElement2String t2 = new OMElement2String(); + String xml = t2.transform(element, null); + Assert.assertNotNull(xml); + Assert.assertNotNull(xml.indexOf("") != -1); + } + + public final void testStAXTransform() { + String2OMElement t1 = new String2OMElement(); + OMElement element = t1.transform(IPO_XML, null); + + OMElement2XMLStreamReader t2 = new OMElement2XMLStreamReader(); + XMLStreamReader reader = t2.transform(element, null); + + XMLStreamReader2OMElement t3 = new XMLStreamReader2OMElement(); + OMElement element2 = t3.transform(reader, null); + + Assert.assertEquals(element2.getQName(), element.getQName()); + Assert.assertEquals(new QName("http://www.example.com/IPO", "purchaseOrder"), element2.getQName()); + } + + public final void testCopy() { + String2OMElement t1 = new String2OMElement(); + OMElement element = t1.transform(IPO_XML, null); + OMElement copy = (OMElement)new AxiomDataBinding().copy(element); + assertNotSame(element, copy); + assertEquals(new QName("http://www.example.com/IPO", "purchaseOrder"), copy.getQName()); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/test/resources/ipo.xml b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/test/resources/ipo.xml new file mode 100755 index 0000000000..df901d183d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/test/resources/ipo.xml @@ -0,0 +1,51 @@ + + + + + + Helen Zoe + 47 Eden Street + Cambridge + CB1 1JR + + + + Robert Smith + 8 Oak Avenue + Old Town + PA + 95819 + + + + + Lapis necklace + 1 + 99.95 + Want this for the holidays + 1999-12-05 + + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/test/resources/ipo.xsd b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/test/resources/ipo.xsd new file mode 100755 index 0000000000..af1e73172d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/test/resources/ipo.xsd @@ -0,0 +1,137 @@ + + + + + + + International Purchase order schema for Example.com + Copyright 2000 Example.com. All rights reserved. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/test/resources/order.wsdl b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/test/resources/order.wsdl new file mode 100644 index 0000000000..a5ead60382 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-axiom/src/test/resources/order.wsdl @@ -0,0 +1,76 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-jaxb/.ruleset b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-jaxb/.ruleset new file mode 100644 index 0000000000..27b9ab847c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-jaxb/.ruleset @@ -0,0 +1,191 @@ + + + + + PMD Plugin preferences rule set + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-jaxb/DISCLAIMER b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-jaxb/DISCLAIMER new file mode 100644 index 0000000000..d68a410903 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-jaxb/DISCLAIMER @@ -0,0 +1,8 @@ +Apache Tuscany is an effort undergoing incubation at The Apache Software +Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is +required of all newly accepted projects until a further review indicates that +the infrastructure, communications, and decision making process have stabilized +in a manner consistent with other successful ASF projects. While incubation +status is not necessarily a reflection of the completeness or stability of the +code, it does indicate that the project has yet to be fully endorsed by the ASF. + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-jaxb/LICENSE b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-jaxb/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-jaxb/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-jaxb/NOTICE b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-jaxb/NOTICE new file mode 100644 index 0000000000..94481d6cfa --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-jaxb/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2007 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-jaxb/pom.xml b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-jaxb/pom.xml new file mode 100755 index 0000000000..ba674058bd --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-jaxb/pom.xml @@ -0,0 +1,147 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 0.91-incubating-SNAPSHOT + ../pom.xml + + tuscany-databinding-jaxb + Apache Tuscany Data Binding for JAXB + + + + org.apache.tuscany.sca + tuscany-core-spi + 0.91-incubating-SNAPSHOT + + + org.apache.tuscany.sca + tuscany-databinding + 0.91-incubating-SNAPSHOT + + + org.apache.tuscany.sca + tuscany-interface-java-xml + 0.91-incubating-SNAPSHOT + + + javax.xml.bind + jaxb-api + 2.0 + + + + javax.xml.ws + jaxws-api + + 2.1 + + + + com.sun.xml.bind + jaxb-impl + 2.0.5 + runtime + + + + javax.xml.bind + jsr173_api + + + + + + + + + true + + java.net + java.net Maven 1.x Repository + https://maven-repository.dev.java.net/nonav/repository + legacy + + + + + + + true + + java.net + java.net Maven 1.x Repository + https://maven-repository.dev.java.net/repository + legacy + + + + + + + org.codehaus.mojo + build-helper-maven-plugin + 1.0 + + + add-test-source + generate-sources + + add-test-source + + + + target/jaxb-source + + + + + + + + com.sun.tools.xjc.maven2 + maven-jaxb-plugin + 1.1 + + + generate-jaxb + generate-sources + + generate + + + + + com.example.ipo.jaxb + ${project.build.directory}/jaxb-source + ${basedir}/src/test/resources + + ipo.xsd + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXB2Node.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXB2Node.java new file mode 100755 index 0000000000..c1d3c36076 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXB2Node.java @@ -0,0 +1,69 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding.jaxb; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBElement; +import javax.xml.bind.Marshaller; + +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; +import org.apache.tuscany.sca.databinding.impl.DOMHelper; +import org.w3c.dom.Document; +import org.w3c.dom.Node; + +public class JAXB2Node extends BaseTransformer implements PullTransformer { + + public Node transform(Object source, TransformationContext tContext) { + if (source == null) { + return null; + } + try { + JAXBContext context = JAXBContextHelper.createJAXBContext(tContext, true); + Marshaller marshaller = context.createMarshaller(); + // FIXME: The default Marshaller doesn't support + // marshaller.getNode() + Document document = DOMHelper.newDocument(); + JAXBElement jaxbElement = JAXBContextHelper.createJAXBElement(tContext.getSourceDataType(), source); + marshaller.marshal(jaxbElement, document); + return document; + } catch (Exception e) { + throw new TransformationException(e); + } + } + + public Class getSourceType() { + return Object.class; + } + + public Class getTargetType() { + return Node.class; + } + + public int getWeight() { + return 30; + } + + @Override + public String getSourceDataBinding() { + return JAXBDataBinding.NAME; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextHelper.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextHelper.java new file mode 100644 index 0000000000..93a7a5da0f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBContextHelper.java @@ -0,0 +1,176 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding.jaxb; + +import java.beans.Introspector; +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBElement; +import javax.xml.bind.JAXBException; +import javax.xml.bind.annotation.XmlEnum; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlSchema; +import javax.xml.bind.annotation.XmlType; +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.util.XMLType; + +public class JAXBContextHelper { + // TODO: Do we need to set them for source and target? + public static final String JAXB_CLASSES = "jaxb.classes"; + + public static final String JAXB_CONTEXT_PATH = "jaxb.contextPath"; + + private JAXBContextHelper() { + } + + public static JAXBContext createJAXBContext(TransformationContext tContext, boolean source) throws JAXBException { + if (tContext == null) + throw new TransformationException("JAXB context is not set for the transformation."); + + DataType bindingContext = source ? tContext.getSourceDataType() : tContext.getTargetDataType(); + // FIXME: We should check the context path or classes + // FIXME: What should we do if JAXB is an intermediate node? + + String contextPath = null; + JAXBContext context = null; + Class cls = bindingContext.getPhysical(); + if (cls.getPackage() != null) { + contextPath = cls.getPackage().getName(); + context = JAXBContext.newInstance(contextPath); + } + if (context == null) { + throw new TransformationException("JAXB context is not set for the transformation."); + } + return context; + } + + @SuppressWarnings("unchecked") + public static JAXBElement createJAXBElement(DataType dataType, Object value) { + if (value instanceof JAXBElement) { + return (JAXBElement)value; + } else { + Class type = (Class)dataType.getPhysical(); + Object logical = dataType.getLogical(); + QName elementName = JAXBDataBinding.ROOT_ELEMENT; + if (logical instanceof XMLType) { + XMLType xmlType = (XMLType)logical; + QName element = xmlType.getElementName(); + if (element != null) { + elementName = element; + } else { + /** + * Set the declared type to Object.class so that xsi:type + * will be produced + */ + type = Object.class; + } + } else { + type = Object.class; + } + return new JAXBElement(elementName, type, value); + } + } + + @SuppressWarnings("unchecked") + public static Object createReturnValue(DataType dataType, Object value) { + Class cls = getJavaType(dataType); + if (cls == JAXBElement.class) { + return createJAXBElement(dataType, value); + } else { + if (value instanceof JAXBElement) { + return ((JAXBElement)value).getValue(); + } else { + return value; + } + } + } + + public static Class getJavaType(DataType dataType) { + if (dataType == null) { + return null; + } + Type type = dataType.getPhysical(); + if (type instanceof Class) { + Class cls = (Class)type; + if (JAXBElement.class.isAssignableFrom(cls)) { + return null; + } else { + return cls; + } + } else if (type instanceof ParameterizedType) { + ParameterizedType pType = (ParameterizedType)type; + return (Class)pType.getRawType(); + } + return null; + } + + public static XMLType getXmlTypeName(Class javaType) { + String namespace = null; + String name = null; + Package pkg = javaType.getPackage(); + if (pkg != null) { + XmlSchema schema = pkg.getAnnotation(XmlSchema.class); + if (schema != null) { + namespace = schema.namespace(); + } + } + XmlType type = javaType.getAnnotation(XmlType.class); + if (type != null) { + String typeNamespace = type.namespace(); + String typeName = type.name(); + + if (typeNamespace.equals("##default") && typeName.equals("")) { + XmlRootElement rootElement = javaType.getAnnotation(XmlRootElement.class); + if (rootElement != null) { + namespace = rootElement.namespace(); + } else { + // FIXME: The namespace should be from the referencing + // property + namespace = null; + } + } else if (typeNamespace.equals("##default")) { + // namespace is from the package + } else { + namespace = typeNamespace; + } + + if (typeName.equals("##default")) { + name = Introspector.decapitalize(javaType.getSimpleName()); + } else { + name = typeName; + } + } else { + XmlEnum xmlEnum = javaType.getAnnotation(XmlEnum.class); + if (xmlEnum != null) { + name = Introspector.decapitalize(javaType.getSimpleName()); + } + } + if (name == null) { + return null; + } + return new XMLType(null, new QName(namespace, name)); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBDataBinding.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBDataBinding.java new file mode 100644 index 0000000000..9706ffdc21 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBDataBinding.java @@ -0,0 +1,114 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.databinding.jaxb; + +import java.lang.annotation.Annotation; +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBElement; +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.databinding.ExceptionHandler; +import org.apache.tuscany.sca.databinding.impl.BaseDataBinding; +import org.apache.tuscany.sca.databinding.impl.DOMHelper; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.util.XMLType; +import org.w3c.dom.Document; + +/** + * JAXB DataBinding + */ +public class JAXBDataBinding extends BaseDataBinding { + public static final String NAME = JAXBElement.class.getName(); + public static final String[] ALIASES = new String[] {"jaxb"}; + + public static final String ROOT_NAMESPACE = "http://tuscany.apache.org/xmlns/sca/databinding/jaxb/1.0"; + public static final QName ROOT_ELEMENT = new QName(ROOT_NAMESPACE, "root"); + + public JAXBDataBinding() { + super(NAME, ALIASES, JAXBElement.class); + } + + @Override + public boolean introspect(DataType dataType, Annotation[] annotations) { + Object physical = dataType.getPhysical(); + if (!(physical instanceof Class)) { + return false; + } + Class javaType = (Class)physical; + if (JAXBElement.class.isAssignableFrom(javaType)) { + Type type = javaType.getGenericSuperclass(); + if (type instanceof ParameterizedType) { + ParameterizedType parameterizedType = ((ParameterizedType)type); + Type rawType = parameterizedType.getRawType(); + if (rawType == JAXBElement.class) { + Type actualType = parameterizedType.getActualTypeArguments()[0]; + if (actualType instanceof Class) { + XMLType xmlType = JAXBContextHelper.getXmlTypeName((Class)actualType); + dataType.setLogical(xmlType); + dataType.setDataBinding(getName()); + return true; + } + } + } + dataType.setLogical(XMLType.UNKNOWN); + dataType.setDataBinding(getName()); + return true; + } + + XMLType xmlType = JAXBContextHelper.getXmlTypeName(javaType); + if (xmlType == null) { + return false; + } + dataType.setLogical(xmlType); + dataType.setDataBinding(getName()); + return true; + } + + @SuppressWarnings("unchecked") + @Override + public Object copy(Object arg) { + try { + boolean isElement = false; + Class cls = arg.getClass(); + if (arg instanceof JAXBElement) { + isElement = true; + cls = ((JAXBElement)arg).getDeclaredType(); + } else { + arg = new JAXBElement(ROOT_ELEMENT, Object.class, arg); + } + JAXBContext context = JAXBContext.newInstance(cls); + Document doc = DOMHelper.newDocument(); + context.createMarshaller().marshal(arg, doc); + JAXBElement element = context.createUnmarshaller().unmarshal(doc, cls); + return isElement ? element : element.getValue(); + } catch (Exception e) { + throw new IllegalArgumentException(e); + } + } + + @Override + public ExceptionHandler getExceptionHandler() { + return new JAXBExceptionHandler(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBExceptionHandler.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBExceptionHandler.java new file mode 100644 index 0000000000..c2ca78e018 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBExceptionHandler.java @@ -0,0 +1,107 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.databinding.jaxb; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Method; + +import javax.xml.namespace.QName; +import javax.xml.ws.WebFault; + +import org.apache.tuscany.sca.databinding.ExceptionHandler; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; +import org.apache.tuscany.sca.interfacedef.util.XMLType; + +/** + * JAXB implementation of ExceptionHandler + * + * @version $Rev$ $Date$ + */ +public class JAXBExceptionHandler implements ExceptionHandler { + private static final Class[] EMPTY_CLASS_ARRAY = new Class[0]; + + /** + *
    + *
  • WrapperException(String message, FaultBean faultInfo)
    + * A constructor where WrapperException is replaced with the name of the + * generated wrapper exception and FaultBean is replaced by the name of the + * generated fault bean. + *
  • WrapperException(String message, FaultBean faultInfo, Throwable + * cause)
    + * A constructor whereWrapperException is replaced with the name of the + * generated wrapper exception and FaultBean is replaced by the name of the + * generated fault bean. The last argument, cause, may be used to convey + * protocol specific fault information + *
+ */ + public Exception createException(DataType exceptionType, String message, Object faultInfo, Throwable cause) { + Class exceptionClass = (Class)exceptionType.getPhysical(); + DataType faultBeanType = exceptionType.getLogical(); + Class faultBeanClass = (Class)faultBeanType.getPhysical(); + try { + Constructor constructor = + exceptionClass.getConstructor(new Class[] {String.class, faultBeanClass, Throwable.class}); + return (Exception)constructor.newInstance(new Object[] {message, faultInfo, cause}); + } catch (Throwable e) { + throw new IllegalArgumentException(e); + } + } + + public Object getFaultInfo(Exception exception) { + if (exception == null) { + return null; + } + try { + Method method = exception.getClass().getMethod("getFaultInfo", EMPTY_CLASS_ARRAY); + return method.invoke(exception, (Object[])null); + } catch (Throwable e) { + throw new IllegalArgumentException(e); + } + } + + public DataType getFaultType(DataType exDataType) { + Class exceptionType = (Class) exDataType.getPhysical(); + WebFault webFault = exceptionType.getAnnotation(WebFault.class); + if (webFault == null) { + return null; + } else { + QName element = new QName(webFault.targetNamespace(), webFault.name()); + // TODO: Need to determine the fault bean class + // String faultBean = webFault.faultBean(); + Class faultBeanClass = null; + try { + Method method = exceptionType.getMethod("getFaultInfo", EMPTY_CLASS_ARRAY); + faultBeanClass = method.getReturnType(); + } catch (NoSuchMethodException e) { + faultBeanClass = null; + } + // The logical type of a fault is the QName of the element that the + // only part in + // the fault message references + DataType faultType = + new DataTypeImpl(JAXBDataBinding.NAME, faultBeanClass, new XMLType(element, null)); + // faultType.setMetadata(ElementInfo.class.getName(), new + // ElementInfo(element, null)); + return faultType; + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBWrapperHandler.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBWrapperHandler.java new file mode 100644 index 0000000000..528d6fd703 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXBWrapperHandler.java @@ -0,0 +1,123 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.databinding.jaxb; + +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.List; + +import javax.xml.bind.JAXBElement; +import javax.xml.bind.annotation.XmlElementDecl; +import javax.xml.bind.annotation.XmlRegistry; +import javax.xml.bind.annotation.XmlType; +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.WrapperHandler; +import org.apache.tuscany.sca.interfacedef.util.ElementInfo; + +/** + * JAXB WrapperHandler implementation + */ +public class JAXBWrapperHandler implements WrapperHandler> { + + public JAXBElement create(ElementInfo element, TransformationContext context) { + try { + // FIXME: How do we map the global element to a factory? + String packageName = null; + String factoryClassName = packageName + ".ObjectFactory"; + ClassLoader classLoader = context != null ? context.getClassLoader() : null; + if (classLoader == null) { + classLoader = Thread.currentThread().getContextClassLoader(); + } + Class factoryClass = Class.forName(factoryClassName, true, classLoader); + assert factoryClass.isAnnotationPresent(XmlRegistry.class); + Object factory = factoryClass.newInstance(); + QName elementName = element.getQName(); + Method method = null; + for (Method m : factoryClass.getMethods()) { + XmlElementDecl xmlElement = m.getAnnotation(XmlElementDecl.class); + QName name = new QName(xmlElement.namespace(), xmlElement.name()); + if (xmlElement != null && name.equals(elementName)) { + method = m; + break; + } + } + if (method != null) { + Class typeClass = method.getParameterTypes()[0]; + Object value = typeClass.newInstance(); + return (JAXBElement)method.invoke(factory, new Object[] {value}); + } else { + throw new TransformationException("ObjectFactory cannot be resolved."); + } + } catch (Exception e) { + throw new TransformationException(e); + } + } + + public void setChild(JAXBElement wrapper, int i, ElementInfo childElement, Object value) { + Object wrapperValue = wrapper.getValue(); + Class wrapperClass = wrapperValue.getClass(); + + XmlType xmlType = wrapperClass.getAnnotation(XmlType.class); + String[] properties = xmlType.propOrder(); + String property = properties[i]; + + try { + for (Method m : wrapperClass.getMethods()) { + if (m.getName().equals("set" + capitalize(property))) { + m.invoke(wrapperValue, new Object[] {value}); + return; + } + } + } catch (Throwable e) { + throw new TransformationException(e); + } + } + + private static String capitalize(String name) { + char first = Character.toUpperCase(name.charAt(0)); + return first + name.substring(1); + } + + /** + * @see org.apache.tuscany.sca.databinding.WrapperHandler#getChildren(java.lang.Object) + */ + public List getChildren(JAXBElement wrapper) { + Object wrapperValue = wrapper.getValue(); + Class wrapperClass = wrapperValue.getClass(); + + XmlType xmlType = wrapperClass.getAnnotation(XmlType.class); + String[] properties = xmlType.propOrder(); + List elements = new ArrayList(); + for (String p : properties) { + try { + Method method = wrapperClass.getMethod("get" + capitalize(p), (Class[])null); + Object value = method.invoke(wrapperValue, (Object[])null); + elements.add(value); + } catch (Throwable e) { + throw new TransformationException(e); + } + } + return elements; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXWSJavaInterfaceProcessor.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXWSJavaInterfaceProcessor.java new file mode 100644 index 0000000000..60ed6f2f81 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/JAXWSJavaInterfaceProcessor.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.databinding.jaxb; + +import java.lang.reflect.Method; +import java.util.HashMap; +import java.util.Map; + +import javax.jws.WebMethod; +import javax.jws.WebService; +import javax.xml.namespace.QName; +import javax.xml.ws.RequestWrapper; +import javax.xml.ws.ResponseWrapper; + +import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException; +import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.java.JavaInterface; +import org.apache.tuscany.sca.interfacedef.java.introspect.JavaInterfaceVisitor; +import org.apache.tuscany.sca.interfacedef.util.ElementInfo; +import org.apache.tuscany.sca.interfacedef.util.WrapperInfo; + +/** + * The databinding annotation processor for java interfaces + * + * @version $Rev$ $Date$ + */ +public class JAXWSJavaInterfaceProcessor implements JavaInterfaceVisitor { + + public JAXWSJavaInterfaceProcessor() { + super(); + } + + public void visitInterface(JavaInterface contract) throws InvalidInterfaceException { + if (!contract.isRemotable()) { + return; + } + Class clazz = contract.getJavaClass(); + Map operations = new HashMap(); + for (Operation op : contract.getOperations()) { + operations.put(op.getName(), op); + } + for (Method method : clazz.getMethods()) { + Operation operation = operations.get(method.getName()); + + WebMethod webMethod = method.getAnnotation(WebMethod.class); + if (webMethod == null) { + return; + } + + String operationName = getValue(webMethod.operationName(), operation.getName()); + + RequestWrapper requestWrapper = method.getAnnotation(RequestWrapper.class); + ResponseWrapper responseWrapper = method.getAnnotation(ResponseWrapper.class); + if (requestWrapper == null) { + return; + } + + WebService webService = clazz.getAnnotation(WebService.class); + String tns = ""; + if (webService != null) { + tns = webService.targetNamespace(); + } + + String ns = getValue(requestWrapper.targetNamespace(), tns); + String name = getValue(requestWrapper.localName(), operationName); + QName inputWrapper = new QName(ns, name); + + ns = getValue(responseWrapper.targetNamespace(), tns); + name = getValue(responseWrapper.localName(), operationName + "Response"); + + QName outputWrapper = new QName(ns, name); + + WrapperInfo wrapperInfo = new WrapperInfo(JAXBDataBinding.NAME, new ElementInfo(inputWrapper, null), + new ElementInfo(outputWrapper, null), null, null); + operation.setWrapperStyle(true); + operation.setWrapper(wrapperInfo); + } + } + + private static String getValue(String value, String defaultValue) { + return "".equals(value) ? defaultValue : value; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/Node2JAXB.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/Node2JAXB.java new file mode 100755 index 0000000000..31beb344f1 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/Node2JAXB.java @@ -0,0 +1,66 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding.jaxb; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.Unmarshaller; + +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; +import org.w3c.dom.Node; + +public class Node2JAXB extends BaseTransformer implements PullTransformer { + + public Node2JAXB() { + super(); + } + + public Object transform(Node source, TransformationContext context) { + if (source == null) + return null; + try { + JAXBContext jaxbContext = JAXBContextHelper.createJAXBContext(context, false); + Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); + Object result = unmarshaller.unmarshal(source); + return JAXBContextHelper.createReturnValue(context.getTargetDataType(), result); + } catch (Exception e) { + throw new TransformationException(e); + } + } + + public Class getSourceType() { + return Node.class; + } + + public Class getTargetType() { + return Object.class; + } + + public int getWeight() { + return 30; + } + + @Override + public String getTargetDataBinding() { + return JAXBDataBinding.NAME; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/Reader2JAXB.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/Reader2JAXB.java new file mode 100644 index 0000000000..e0bb0e189c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/Reader2JAXB.java @@ -0,0 +1,67 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding.jaxb; + +import java.io.Reader; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.Unmarshaller; +import javax.xml.transform.stream.StreamSource; + +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; + +public class Reader2JAXB extends BaseTransformer implements + PullTransformer { + + public Object transform(final Reader source, final TransformationContext context) { + if (source == null) { + return null; + } + try { + JAXBContext jaxbContext = JAXBContextHelper.createJAXBContext(context, false); + Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); + StreamSource streamSource = new StreamSource(source); + Object result = unmarshaller.unmarshal(streamSource); + return JAXBContextHelper.createReturnValue(context.getTargetDataType(), result); + } catch (Exception e) { + throw new TransformationException(e); + } + } + + public Class getSourceType() { + return Reader.class; + } + + public Class getTargetType() { + return Object.class; + } + + public int getWeight() { + return 30; + } + + @Override + public String getTargetDataBinding() { + return JAXBDataBinding.NAME; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/XMLStreamReader2JAXB.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/XMLStreamReader2JAXB.java new file mode 100755 index 0000000000..061f488a01 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/XMLStreamReader2JAXB.java @@ -0,0 +1,67 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding.jaxb; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.Unmarshaller; +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; + +public class XMLStreamReader2JAXB extends BaseTransformer implements + PullTransformer { + + public XMLStreamReader2JAXB() { + super(); + } + + public Object transform(XMLStreamReader source, TransformationContext context) { + if (source == null) { + return null; + } + try { + JAXBContext jaxbContext = JAXBContextHelper.createJAXBContext(context, false); + Unmarshaller unmarshaller = jaxbContext.createUnmarshaller(); + Object result = unmarshaller.unmarshal(source); + return JAXBContextHelper.createReturnValue(context.getTargetDataType(), result); + } catch (Exception e) { + throw new TransformationException(e); + } + } + + public Class getSourceType() { + return XMLStreamReader.class; + } + + public Class getTargetType() { + return Object.class; + } + + public int getWeight() { + return 10; + } + + @Override + public String getTargetDataBinding() { + return JAXBDataBinding.NAME; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/module/JAXBDataBindingModuleActivator.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/module/JAXBDataBindingModuleActivator.java new file mode 100644 index 0000000000..3e98bf652d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-jaxb/src/main/java/org/apache/tuscany/sca/databinding/jaxb/module/JAXBDataBindingModuleActivator.java @@ -0,0 +1,63 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.databinding.jaxb.module; + +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.ModuleActivator; +import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint; +import org.apache.tuscany.sca.databinding.TransformerExtensionPoint; +import org.apache.tuscany.sca.databinding.jaxb.JAXB2Node; +import org.apache.tuscany.sca.databinding.jaxb.JAXBDataBinding; +import org.apache.tuscany.sca.databinding.jaxb.JAXWSJavaInterfaceProcessor; +import org.apache.tuscany.sca.databinding.jaxb.Node2JAXB; +import org.apache.tuscany.sca.databinding.jaxb.Reader2JAXB; +import org.apache.tuscany.sca.databinding.jaxb.XMLStreamReader2JAXB; +import org.apache.tuscany.sca.interfacedef.java.introspect.JavaInterfaceIntrospectorExtensionPoint; + +/** + * Module activator for JAXB databinding + * + * @version $Rev$ $Date$ + */ +public class JAXBDataBindingModuleActivator implements ModuleActivator { + + public Object[] getExtensionPoints() { + return null; + } + + public void start(ExtensionPointRegistry registry) { + DataBindingExtensionPoint dataBindings = registry.getExtensionPoint(DataBindingExtensionPoint.class); + dataBindings.addDataBinding(new JAXBDataBinding()); + + TransformerExtensionPoint transformers = registry.getExtensionPoint(TransformerExtensionPoint.class); + transformers.addTransformer(new JAXB2Node()); + transformers.addTransformer(new Node2JAXB()); + transformers.addTransformer(new Reader2JAXB()); + transformers.addTransformer(new XMLStreamReader2JAXB()); + + JavaInterfaceIntrospectorExtensionPoint introspectors = registry.getExtensionPoint(JavaInterfaceIntrospectorExtensionPoint.class); + introspectors.addInterfaceVisitor(new JAXWSJavaInterfaceProcessor()); + + } + + public void stop(ExtensionPointRegistry registry) { + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-jaxb/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-jaxb/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator new file mode 100644 index 0000000000..2998cf93e0 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-jaxb/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# Implementation class for the ExtensionActivator +org.apache.tuscany.sca.databinding.jaxb.module.JAXBDataBindingModuleActivator \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBDataBindingTestCase.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBDataBindingTestCase.java new file mode 100644 index 0000000000..aa191c20b5 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBDataBindingTestCase.java @@ -0,0 +1,128 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.databinding.jaxb; + +import java.lang.annotation.Annotation; + +import javax.xml.bind.JAXBElement; +import javax.xml.namespace.QName; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.databinding.jaxb.JAXBDataBinding; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; +import org.apache.tuscany.sca.interfacedef.util.XMLType; + +import com.example.ipo.jaxb.ObjectFactory; +import com.example.ipo.jaxb.PurchaseOrderType; +import com.example.ipo.jaxb.USAddress; +import com.example.ipo.jaxb.USState; + +/** + * + */ +public class JAXBDataBindingTestCase extends TestCase { + private JAXBDataBinding binding; + + /** + * @see junit.framework.TestCase#setUp() + */ + protected void setUp() throws Exception { + super.setUp(); + binding = new JAXBDataBinding(); + } + + /** + * Test method for + * {@link org.apache.tuscany.sca.databinding.jaxb.JAXBDataBinding#introspect(java.lang.Class, Annotation)}. + */ + public final void testIntrospect() { + DataType dataType = new DataTypeImpl(JAXBElement.class, null); + boolean yes = binding.introspect(dataType, null); + assertTrue(yes); + assertTrue(dataType.getDataBinding().equals(binding.getName())); + assertTrue(dataType.getPhysical() == JAXBElement.class && dataType.getLogical() == XMLType.UNKNOWN); + dataType = new DataTypeImpl(MockJAXBElement.class, null); + yes = binding.introspect(dataType, null); + assertTrue(yes); + assertEquals(MockJAXBElement.class, dataType.getPhysical()); + assertEquals(new QName("http://www.example.com/IPO", "PurchaseOrderType"), ((XMLType)dataType.getLogical()) + .getTypeName()); + dataType = new DataTypeImpl(USAddress.class, null); + yes = binding.introspect(dataType, null); + assertTrue(yes); + assertEquals(USAddress.class, dataType.getPhysical()); + assertEquals(new QName("http://www.example.com/IPO", "USAddress"), ((XMLType)dataType.getLogical()) + .getTypeName()); + dataType = new DataTypeImpl(USState.class, null); + yes = binding.introspect(dataType, null); + assertTrue(yes); + assertTrue(dataType.getDataBinding().equals(binding.getName())); + assertEquals(USState.class, dataType.getPhysical()); + assertEquals(new QName("http://www.example.com/IPO", "USState"), ((XMLType)dataType.getLogical()).getTypeName()); + + } + + private static class MockJAXBElement extends JAXBElement { + + private static final long serialVersionUID = -2767569071002707973L; + + /** + * @param elementName + * @param type + * @param value + */ + public MockJAXBElement(QName elementName, Class type, PurchaseOrderType value) { + super(elementName, type, value); + } + + } + + @SuppressWarnings("unchecked") + public void testCopy() { + ObjectFactory factory = new ObjectFactory(); + PurchaseOrderType poType = factory.createPurchaseOrderType(); + JAXBElement po = factory.createPurchaseOrder(poType); + JAXBElement copy = (JAXBElement)binding.copy(po); + assertEquals(new QName("http://www.example.com/IPO", "purchaseOrder"), copy.getName()); + } + + @SuppressWarnings("unchecked") + public void testCopyNonElement() { + ObjectFactory factory = new ObjectFactory(); + PurchaseOrderType poType = factory.createPurchaseOrderType(); + poType.setComment("Comment"); + PurchaseOrderType copy = (PurchaseOrderType)binding.copy(poType); + assertTrue(copy instanceof PurchaseOrderType); + assertEquals("Comment", ((PurchaseOrderType)copy).getComment()); + } + + @SuppressWarnings("unchecked") + public void testCopyNonRoot() { + ObjectFactory factory = new ObjectFactory(); + USAddress address = factory.createUSAddress(); + address.setCity("San Jose"); + USAddress copy = (USAddress)binding.copy(address); + assertTrue(copy instanceof USAddress); + assertEquals("San Jose", ((USAddress)copy).getCity()); + + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBExceptionHandlerTestCase.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBExceptionHandlerTestCase.java new file mode 100644 index 0000000000..5b85f9096d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBExceptionHandlerTestCase.java @@ -0,0 +1,80 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.databinding.jaxb; + +import javax.xml.namespace.QName; + +import junit.framework.TestCase; + +import org.apache.tuscany.databinding.jaxb.fault.InvalidSymbolFault; +import org.apache.tuscany.databinding.jaxb.fault.InvalidSymbolFault_Exception; +import org.apache.tuscany.sca.databinding.jaxb.JAXBDataBinding; +import org.apache.tuscany.sca.databinding.jaxb.JAXBExceptionHandler; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; +import org.apache.tuscany.sca.interfacedef.util.XMLType; + +/** + * Test case for JAXBExceptionHandler + */ +public class JAXBExceptionHandlerTestCase extends TestCase { + private static final QName ELEMENT = new QName("http://www.example.com/stock", "InvalidSymbolFault"); + private JAXBExceptionHandler handler; + + /** + * @see junit.framework.TestCase#setUp() + */ + protected void setUp() throws Exception { + super.setUp(); + this.handler = new JAXBExceptionHandler(); + } + + public void testGetFaultType() { + DataType exType = new DataTypeImpl(InvalidSymbolFault_Exception.class, XMLType.UNKNOWN); + DataType dataType = handler.getFaultType(exType); + assertEquals(InvalidSymbolFault.class, dataType.getPhysical()); + assertEquals(ELEMENT, ((XMLType) dataType.getLogical()).getElementName()); + assertEquals(JAXBDataBinding.NAME, dataType.getDataBinding()); + } + + public void testCreate() { + DataType execType = new DataTypeImpl(InvalidSymbolFault_Exception.class, XMLType.UNKNOWN); + DataType faultType = handler.getFaultType(execType); + InvalidSymbolFault fault = new InvalidSymbolFault(); + fault.setMessage("ABC"); + fault.setSymbol("IBM0"); + DataType exType = new DataTypeImpl(InvalidSymbolFault_Exception.class, faultType); + Exception ex = handler.createException(exType, "Invalid symbol", fault, null); + assertTrue(ex instanceof InvalidSymbolFault_Exception); + InvalidSymbolFault_Exception exception = (InvalidSymbolFault_Exception)ex; + assertEquals("Invalid symbol", exception.getMessage()); + assertSame(fault, exception.getFaultInfo()); + } + + public void testGetFaultInfo() { + InvalidSymbolFault fault = new InvalidSymbolFault(); + fault.setMessage("ABC"); + fault.setSymbol("IBM0"); + InvalidSymbolFault_Exception exception = new InvalidSymbolFault_Exception("Invalid symbol", fault); + Object faultInfo = handler.getFaultInfo(exception); + assertSame(fault, faultInfo); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBTestCase.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBTestCase.java new file mode 100755 index 0000000000..f1caf42fcf --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBTestCase.java @@ -0,0 +1,160 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.databinding.jaxb; + +import static org.easymock.EasyMock.createMock; +import static org.easymock.EasyMock.expect; +import static org.easymock.EasyMock.replay; + +import java.io.StringReader; + +import javax.xml.namespace.QName; + +import junit.framework.Assert; +import junit.framework.TestCase; + +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.jaxb.JAXB2Node; +import org.apache.tuscany.sca.databinding.jaxb.Node2JAXB; +import org.apache.tuscany.sca.databinding.jaxb.Reader2JAXB; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; +import org.apache.tuscany.sca.interfacedef.util.XMLType; +import org.w3c.dom.Node; + +import com.example.ipo.jaxb.ObjectFactory; +import com.example.ipo.jaxb.PurchaseOrderType; + +public class JAXBTestCase extends TestCase { + private static final String IPO_XML = + "" + "" + + " " + + " Helen Zoe" + + " 47 Eden Street" + + " Cambridge" + + " CB1 1JR" + + " " + + " " + + " Robert Smith" + + " 8 Oak Avenue" + + " Old Town" + + " PA" + + " 95819" + + " " + + " " + + " " + + " Lapis necklace" + + " 1" + + " 99.95" + + " Want this for the holidays" + + " 1999-12-05" + + " " + + " " + + ""; + + private String contextPath = "com.example.ipo.jaxb"; + + protected void setUp() throws Exception { + super.setUp(); + } + + public void testTransform() throws Exception { + Reader2JAXB t0 = new Reader2JAXB(); + + DataType targetDataType = new DataTypeImpl(PurchaseOrderType.class, null); + + TransformationContext tContext = createMock(TransformationContext.class); + expect(tContext.getTargetDataType()).andReturn(targetDataType).anyTimes(); + replay(tContext); + + Object object1 = t0.transform(new StringReader(IPO_XML), tContext); + + DataType sourceDataType = new DataTypeImpl(PurchaseOrderType.class, null); + + TransformationContext tContext1 = createMock(TransformationContext.class); + expect(tContext1.getSourceDataType()).andReturn(sourceDataType).anyTimes(); + replay(tContext1); + + JAXB2Node t1 = new JAXB2Node(); + Node node = t1.transform(object1, tContext1); + + Assert.assertNotNull(node); + + Node2JAXB t2 = new Node2JAXB(); + Object object2 = t2.transform(node, tContext); + Assert.assertNotNull(object2); + + } + + public void testTransform2() throws Exception { + Reader2JAXB t0 = new Reader2JAXB(); + + QName root = new QName("http://www.example.com/IPO", "purchaseOrder"); + DataType targetDataType = new DataTypeImpl(PurchaseOrderType.class, new XMLType(root, null)); + // targetDataType.setMetadata(JAXBContextHelper.JAXB_CONTEXT_PATH, contextPath); + + TransformationContext tContext = createMock(TransformationContext.class); + expect(tContext.getTargetDataType()).andReturn(targetDataType).anyTimes(); + replay(tContext); + + Object object1 = t0.transform(new StringReader(IPO_XML), tContext); + + DataType sourceDataType = new DataTypeImpl(PurchaseOrderType.class, new XMLType(root, null)); + // sourceDataType.setMetadata(JAXBContextHelper.JAXB_CONTEXT_PATH, contextPath); + + TransformationContext tContext1 = createMock(TransformationContext.class); + expect(tContext1.getSourceDataType()).andReturn(sourceDataType).anyTimes(); + replay(tContext1); + + JAXB2Node t1 = new JAXB2Node(); + Node node = t1.transform(object1, tContext1); + + Assert.assertNotNull(node); + + Node2JAXB t2 = new Node2JAXB(); + Object object2 = t2.transform(node, tContext); + Assert.assertNotNull(object2); + + } + + public void testTransform3() throws Exception { + + DataType sourceDataType = new DataTypeImpl(PurchaseOrderType.class, null); + + TransformationContext tContext1 = createMock(TransformationContext.class); + expect(tContext1.getSourceDataType()).andReturn(sourceDataType).anyTimes(); + replay(tContext1); + + JAXB2Node t1 = new JAXB2Node(); + PurchaseOrderType po = new ObjectFactory().createPurchaseOrderType(); + Node node = t1.transform(po, tContext1); + + Assert.assertNotNull(node); + + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBWrapperHandlerTestCase.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBWrapperHandlerTestCase.java new file mode 100644 index 0000000000..355acd619c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/JAXBWrapperHandlerTestCase.java @@ -0,0 +1,71 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.databinding.jaxb; + +import java.util.List; + +import javax.xml.bind.JAXBElement; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.databinding.jaxb.JAXBWrapperHandler; + +import com.example.ipo.jaxb.ObjectFactory; +import com.example.ipo.jaxb.PurchaseOrderType; + +/** + * Test case for JAXBExceptionHandler + */ +public class JAXBWrapperHandlerTestCase extends TestCase { + // private static final QName ELEMENT = new QName("http://www.example.com/IPO", "purchaseOrder"); + private JAXBWrapperHandler handler; + + /** + * @see junit.framework.TestCase#setUp() + */ + protected void setUp() throws Exception { + super.setUp(); + this.handler = new JAXBWrapperHandler(); + } + + public void testCreate() { + // ElementInfo element = new ElementInfo(ELEMENT, null); + // JAXBElement jaxbElement = handler.create(element, null); + } + + public void testSetChild() { + ObjectFactory factory = new ObjectFactory(); + PurchaseOrderType po = factory.createPurchaseOrderType(); + JAXBElement wrapper = factory.createPurchaseOrder(po); + handler.setChild(wrapper, 2, null, "Comment"); + } + + public void testGetChildren() { + ObjectFactory factory = new ObjectFactory(); + PurchaseOrderType po = factory.createPurchaseOrderType(); + po.setComment("Comment"); + JAXBElement wrapper = factory.createPurchaseOrder(po); + List children = handler.getChildren(wrapper); + assertNotNull(children); + assertEquals(4, children.size()); + assertEquals("Comment", children.get(2)); + assertNull(children.get(0)); + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/fault/InvalidSymbolFault.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/fault/InvalidSymbolFault.java new file mode 100644 index 0000000000..fd21d72337 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/fault/InvalidSymbolFault.java @@ -0,0 +1,78 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.databinding.jaxb.fault; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; +import javax.xml.bind.annotation.XmlType; + +/** + *

+ * Java class for anonymous complex type. + */ +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "", propOrder = {"message", "symbol"}) +@XmlRootElement(name = "InvalidSymbolFault") +public class InvalidSymbolFault { + + @XmlElement(required = true) + protected String message; + @XmlElement(required = true) + protected String symbol; + + /** + * Gets the value of the message property. + * + * @return possible object is {@link String } + */ + public String getMessage() { + return message; + } + + /** + * Sets the value of the message property. + * + * @param value allowed object is {@link String } + */ + public void setMessage(String value) { + this.message = value; + } + + /** + * Gets the value of the symbol property. + * + * @return possible object is {@link String } + */ + public String getSymbol() { + return symbol; + } + + /** + * Sets the value of the symbol property. + * + * @param value allowed object is {@link String } + */ + public void setSymbol(String value) { + this.symbol = value; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/fault/InvalidSymbolFault_Exception.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/fault/InvalidSymbolFault_Exception.java new file mode 100644 index 0000000000..19ce1dca23 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-jaxb/src/test/java/org/apache/tuscany/databinding/jaxb/fault/InvalidSymbolFault_Exception.java @@ -0,0 +1,63 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.databinding.jaxb.fault; + +import javax.xml.ws.WebFault; + +/** + * This class was generated by the JAXWS SI. JAX-WS RI 2.1-02/02/2007 09:55 + * AM(vivekp)-FCS Generated source version: 2.1 + */ +@WebFault(name = "InvalidSymbolFault", targetNamespace = "http://www.example.com/stock") +public class InvalidSymbolFault_Exception extends Exception { + + /** + * Java type that goes as soapenv:Fault detail element. + */ + private InvalidSymbolFault faultInfo; + + /** + * @param faultInfo + * @param message + */ + public InvalidSymbolFault_Exception(String message, InvalidSymbolFault faultInfo) { + super(message); + this.faultInfo = faultInfo; + } + + /** + * @param faultInfo + * @param message + * @param cause + */ + public InvalidSymbolFault_Exception(String message, InvalidSymbolFault faultInfo, Throwable cause) { + super(message, cause); + this.faultInfo = faultInfo; + } + + /** + * @return returns fault bean: + * org.apache.tuscany.sca.test.exceptions.impl.jaxb.InvalidSymbolFault + */ + public InvalidSymbolFault getFaultInfo() { + return faultInfo; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-jaxb/src/test/resources/ipo.xsd b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-jaxb/src/test/resources/ipo.xsd new file mode 100755 index 0000000000..241ec15d36 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-jaxb/src/test/resources/ipo.xsd @@ -0,0 +1,136 @@ + + + + + + International Purchase order schema for Example.com + Copyright 2000 Example.com. All rights reserved. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo-axiom/.checkstyle b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo-axiom/.checkstyle new file mode 100644 index 0000000000..c7b30ffd5e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo-axiom/.checkstyle @@ -0,0 +1,25 @@ + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo-axiom/.ruleset b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo-axiom/.ruleset new file mode 100644 index 0000000000..27b9ab847c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo-axiom/.ruleset @@ -0,0 +1,191 @@ + + + + + PMD Plugin preferences rule set + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo-axiom/DISCLAIMER b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo-axiom/DISCLAIMER new file mode 100644 index 0000000000..d68a410903 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo-axiom/DISCLAIMER @@ -0,0 +1,8 @@ +Apache Tuscany is an effort undergoing incubation at The Apache Software +Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is +required of all newly accepted projects until a further review indicates that +the infrastructure, communications, and decision making process have stabilized +in a manner consistent with other successful ASF projects. While incubation +status is not necessarily a reflection of the completeness or stability of the +code, it does indicate that the project has yet to be fully endorsed by the ASF. + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo-axiom/LICENSE b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo-axiom/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo-axiom/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo-axiom/NOTICE b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo-axiom/NOTICE new file mode 100644 index 0000000000..94481d6cfa --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo-axiom/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2007 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo-axiom/pom.xml b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo-axiom/pom.xml new file mode 100644 index 0000000000..0486cbf1bc --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo-axiom/pom.xml @@ -0,0 +1,131 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 0.91-incubating-SNAPSHOT + ../pom.xml + + tuscany-databinding-sdo-axiom + Apache Tuscany Data Binding for SDO/AXIOM + + + + org.apache.tuscany.sca + tuscany-databinding + 0.91-incubating-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-databinding-sdo + 0.91-incubating-SNAPSHOT + + + + org.apache.ws.commons.axiom + axiom-api + 1.2.4 + + + xerces + xercesImpl + + + + + + org.apache.ws.commons.axiom + axiom-impl + 1.2.4 + runtime + + + + xerces + xercesImpl + 2.8.1 + runtime + + + + + + + org.codehaus.mojo + build-helper-maven-plugin + 1.0 + + + add-test-source + generate-sources + + add-test-source + + + + target/sdo-source + + + + + + + org.apache.tuscany.sdo + tuscany-sdo-plugin + 1.0-incubating-beta1 + + + generate-po-sdo + generate-test-sources + + ${basedir}/src/test/resources/ipo.xsd + com.example.ipo.sdo + true + true + true + + + generate + + + + generate-stock-sdo + generate-test-sources + + ${basedir}/src/test/resources/stock.xsd + com.example.stock.sdo + Stock + true + true + true + + + generate + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo-axiom/src/main/java/org/apache/tuscany/sca/databinding/sdo2om/DataObject2OMElement.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo-axiom/src/main/java/org/apache/tuscany/sca/databinding/sdo2om/DataObject2OMElement.java new file mode 100644 index 0000000000..4060fd8e5b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo-axiom/src/main/java/org/apache/tuscany/sca/databinding/sdo2om/DataObject2OMElement.java @@ -0,0 +1,88 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding.sdo2om; + +import static org.apache.tuscany.sca.databinding.sdo.SDODataBinding.ROOT_ELEMENT; + +import org.apache.axiom.om.OMAbstractFactory; +import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.OMFactory; +import org.apache.axiom.om.OMNamespace; +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; +import org.apache.tuscany.sca.databinding.sdo.SDOContextHelper; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.util.XMLType; + +import commonj.sdo.DataObject; +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.XMLDocument; + +/** + * SDO DataObject --> AXIOM OMElement transformer + * + * @version $Rev$ $Date$ + */ +public class DataObject2OMElement extends BaseTransformer implements + PullTransformer { + + public OMElement transform(DataObject source, TransformationContext context) { + HelperContext helperContext = SDOContextHelper.getHelperContext(context); + OMFactory factory = OMAbstractFactory.getOMFactory(); + + OMNamespace namespace = null; + String localName = ROOT_ELEMENT.getLocalPart(); + if (context != null) { + DataType dataType = context.getTargetDataType(); + Object logical = dataType == null ? null : dataType.getLogical(); + if (logical instanceof XMLType) { + XMLType xmlType = (XMLType)logical; + if (xmlType.isElement()) { + namespace = factory.createOMNamespace(xmlType.getElementName().getNamespaceURI(), xmlType + .getElementName().getPrefix()); + localName = xmlType.getElementName().getLocalPart(); + } + } + } + if (namespace == null) { + namespace = factory.createOMNamespace(ROOT_ELEMENT.getNamespaceURI(), ROOT_ELEMENT.getPrefix()); + } + + XMLDocument document = helperContext.getXMLHelper().createDocument(source, + namespace.getNamespaceURI(), + localName); + SDODataSource dataSource = new SDODataSource(document, helperContext); + OMElement element = factory.createOMElement(dataSource, localName, namespace); + return element; + } + + public Class getSourceType() { + return DataObject.class; + } + + public Class getTargetType() { + return OMElement.class; + } + + public int getWeight() { + return 10; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo-axiom/src/main/java/org/apache/tuscany/sca/databinding/sdo2om/DataObjectSerializer.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo-axiom/src/main/java/org/apache/tuscany/sca/databinding/sdo2om/DataObjectSerializer.java new file mode 100644 index 0000000000..4301ba09e3 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo-axiom/src/main/java/org/apache/tuscany/sca/databinding/sdo2om/DataObjectSerializer.java @@ -0,0 +1,427 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.databinding.sdo2om; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import javax.xml.namespace.NamespaceContext; +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sdo.impl.AttributeImpl; +import org.apache.tuscany.sdo.impl.ReferenceImpl; +import org.apache.tuscany.sdo.util.SDOUtil; +import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EDataType; +import org.eclipse.emf.ecore.EReference; +import org.eclipse.emf.ecore.EStructuralFeature; +import org.eclipse.emf.ecore.util.ExtendedMetaData; + +import commonj.sdo.DataObject; +import commonj.sdo.Property; +import commonj.sdo.Sequence; +import commonj.sdo.Type; +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.XMLDocument; +import commonj.sdo.helper.XSDHelper; + +public class DataObjectSerializer { + private static final String ELEMENT_TEXT = "Text Element"; + + // static final String ELEMENT_TEXT = "Element Text"; + private static final QName XSI_TYPE_QNAME = new QName("http://www.w3.org/2001/XMLSchema-instance", "type", "xsi"); + + private Map declaredNamespaceMap = new HashMap(); + + private NameSpaceContextImpl namespaceContext = new NameSpaceContextImpl(); + + private DataObject rootDataObject; + + private String rootElementName; + + private String rootElementURI; + + private XMLStreamWriter xmlWriter; + + private XSDHelper xsdHelper; + + public DataObjectSerializer(DataObject rootObject, + XMLStreamWriter xmlWriter, + HelperContext helperCtx, + TransformationContext context) { + this.xmlWriter = xmlWriter; + this.rootDataObject = rootObject; + this.xsdHelper = helperCtx.getXSDHelper(); + this.rootElementName = xsdHelper.getLocalName(rootObject.getType()); + this.rootElementURI = rootDataObject.getType().getURI(); + + if (context != null) { + DataType dataType = context.getTargetDataType(); + Object targetQName = dataType == null ? null : dataType.getLogical(); + if (targetQName instanceof QName) { + QName name = (QName)targetQName; + this.rootElementName = name.getLocalPart(); + this.rootElementURI = name.getNamespaceURI(); + } + } + + } + + // private void serializeNamespace(String prefix, String URI, + // XMLStreamWriter writer) throws XMLStreamException { + // String prefix1 = writer.getPrefix(URI); + // if (prefix1 == null) { + // writer.writeNamespace(prefix, URI); + // writer.setPrefix(prefix, URI); + // } + // } + + public DataObjectSerializer(XMLDocument sourceDocument, XMLStreamWriter xmlWriter, HelperContext helperCtx) { + this.xmlWriter = xmlWriter; + this.rootDataObject = sourceDocument.getRootObject(); + this.rootElementName = sourceDocument.getRootElementName(); + this.rootElementURI = sourceDocument.getRootElementURI(); + this.xsdHelper = helperCtx.getXSDHelper(); + } + + protected class NameSpaceContextImpl implements NamespaceContext { + private int counter; + + private Map prefixToNamespaceMapping = new HashMap(); + + public NameSpaceContextImpl() { + prefixToNamespaceMapping.put("xml", "http://www.w3.org/XML/1998/namespace"); + prefixToNamespaceMapping.put("xmlns", "http://www.w3.org/2000/xmlns/"); + prefixToNamespaceMapping.put("xsi", "http://www.w3.org/2001/XMLSchema-instance"); + } + + public synchronized QName createQName(String nsURI, String name) { + String prefix = nsURI != null ? (String)getPrefix(nsURI) : null; + if (prefix == null && nsURI != null && !nsURI.equals("")) { + prefix = "p" + (counter++); + } + if (prefix == null) { + prefix = ""; + } + if (nsURI != null) { + prefixToNamespaceMapping.put(prefix, nsURI); + declaredNamespaceMap.put(prefix, nsURI); + } + return new QName(nsURI, name, prefix); + } + + public String getNamespaceURI(String prefix) { + if (prefix == null) { + throw new IllegalArgumentException("Prefix is null"); + } + + String ns = (String)prefixToNamespaceMapping.get(prefix); + if (ns != null) { + return ns; + } else { + return null; + } + } + + public String getPrefix(String nsURI) { + if (nsURI == null) { + throw new IllegalArgumentException("Namespace is null"); + } + for (Iterator i = prefixToNamespaceMapping.entrySet().iterator(); i.hasNext();) { + Map.Entry entry = (Map.Entry)i.next(); + if (entry.getValue().equals(nsURI)) { + return (String)entry.getKey(); + } + } + return null; + } + + public Iterator getPrefixes(String nsURI) { + List prefixList = new ArrayList(); + for (Iterator i = prefixToNamespaceMapping.entrySet().iterator(); i.hasNext();) { + Map.Entry entry = (Map.Entry)i.next(); + if (entry.getValue().equals(nsURI)) { + prefixList.add(entry.getKey()); + } + } + return prefixList.iterator(); + } + + public void registerMapping(String prefix, String nsURI) { + prefixToNamespaceMapping.put(prefix, nsURI); + } + + public void removeMapping(String prefix) { + prefixToNamespaceMapping.remove(prefix); + } + } + + protected static class NameValuePair implements Map.Entry { + private Object key; + + private Object value; + + public NameValuePair(Object key, Object value) { + this.key = key; + this.value = value; + } + + public Object getKey() { + return key; + } + + public Object getValue() { + return value; + } + + public Object setValue(Object value) { + Object v = this.value; + this.value = value; + return v; + } + + } + + private static boolean isTransient(Property property, Object type) { + // HACK: We need some SDOUtil extension to understand a property is + // derived + EStructuralFeature feature = (EStructuralFeature)property; + if (ExtendedMetaData.INSTANCE.getGroup(feature) != null) { + return false; + } + feature = ExtendedMetaData.INSTANCE.getAffiliation((EClass)type, feature); + if (feature != null && feature != property) { + return false; + } + if (property instanceof ReferenceImpl) { + ReferenceImpl r = (ReferenceImpl)property; + if (r.isTransient()) { + return true; + } + EReference opposite = r.getEOpposite(); + if (opposite != null && opposite.isContainment()) { + return true; + } + } else if (property instanceof AttributeImpl) { + AttributeImpl a = (AttributeImpl)property; + if (a.isTransient()) { + return true; + } + EDataType d = (EDataType)a.getEType(); + if (!d.isSerializable()) { + return true; + } + } + return false; + } + + private void addListValue(List propertyList, + List children, + Property property, + List objList) throws XMLStreamException { + if (objList != null) { + for (int j = 0; j < objList.size(); j++) { + Object object = objList.get(j); + addSingleValue(propertyList, children, property, object); + } + } + } + + private void addProperty(List propertyList, + List children, + Property property, + Object value, + DataObject dataObject) throws XMLStreamException { + + if (property.isMany() && property.getContainingType().isOpen() && value instanceof Sequence) { + addSequenceValue(propertyList, children, (Sequence)value); + } else if (SDOUtil.isMany(property, dataObject) && value instanceof List) { + addListValue(propertyList, children, property, (List)value); + } else { + // Complex Type + addSingleValue(propertyList, children, property, value); + } + } + + private void addSequenceValue(List elements, List children, Sequence seq) + throws XMLStreamException { + if (seq != null && seq.size() > 0) { + for (int j = 0; j < seq.size(); j++) { + Object o = seq.getValue(j); + Property p = seq.getProperty(j); + addSingleValue(elements, children, p, o); + } + } + } + + private void addSingleValue(List propertyList, + List children, + Property property, + Object value) throws XMLStreamException { + String uri = xsdHelper.getNamespaceURI(property); + String name = xsdHelper.getLocalName(property); + QName qname = namespaceContext.createQName(uri, name); + Type propertyType = property.getType(); + + if (property.getName().equals("value") && uri == null && name.equals(":0")) { + propertyList.add(new NameValuePair(ELEMENT_TEXT, value.toString())); + } else if (value == null) { + NameValuePair entry = new NameValuePair(qname, null); + propertyList.add(entry); + } else if (propertyType.isDataType()) { + NameValuePair entry = new NameValuePair(qname, SDOUtil.convertToString(propertyType, value)); + propertyList.add(entry); + } else { + children.add((DataObject)value); + } + } + + private void registerNamespace(String prefix, String uri) { + if (!uri.equals(namespaceContext.getNamespaceURI(prefix))) { + namespaceContext.registerMapping(prefix, uri); + declaredNamespaceMap.put(prefix, uri); + } + } + + public void serialize() throws XMLStreamException { + xmlWriter.setNamespaceContext(namespaceContext); + writeDataObject(rootDataObject, rootElementName, rootElementURI); + xmlWriter.flush(); + } + + private void writeDataObject(DataObject obj, String elementName, String elementURI) throws XMLStreamException { + List elementList = new ArrayList(); + List children = new ArrayList(); + List attributes = new ArrayList(); + + String typeName; + QName realTypeName = null; + + if (elementName != null) { + realTypeName = namespaceContext.createQName(elementURI, elementName); + String typeQName = realTypeName.getPrefix() + ":" + realTypeName.getLocalPart(); + declaredNamespaceMap.put(realTypeName.getPrefix(), realTypeName.getNamespaceURI()); + attributes.add(new NameValuePair(XSI_TYPE_QNAME, typeQName)); + registerNamespace(XSI_TYPE_QNAME.getPrefix(), XSI_TYPE_QNAME.getNamespaceURI()); + } else { + + typeName = xsdHelper.getLocalName(obj.getContainmentProperty()); + realTypeName = namespaceContext.createQName(obj.getType().getURI(), typeName); + registerNamespace(realTypeName.getPrefix(), realTypeName.getNamespaceURI()); + } + + registerNamespace(realTypeName.getPrefix(), realTypeName.getNamespaceURI()); + + if (obj.getType().isSequenced()) { + Sequence sequence = obj.getSequence(); + for (int i = 0; i < sequence.size(); i++) { + Property property = sequence.getProperty(i); + Object value = sequence.getValue(i); + if (property == null) { + elementList.add(new NameValuePair(ELEMENT_TEXT, value)); + } else { + addProperty(elementList, children, property, value, obj); + } + } + + // Attributes are not in the sequence + List properties = obj.getInstanceProperties(); + for (Iterator i = properties.iterator(); i.hasNext();) { + Property property = (Property)i.next(); + if (xsdHelper.isAttribute(property) && obj.isSet(property) && !isTransient(property, obj.getType())) { + Object value = obj.get(property); + QName name = + namespaceContext.createQName(xsdHelper.getNamespaceURI(property), xsdHelper + .getLocalName(property)); + attributes.add(new NameValuePair(name, SDOUtil.convertToString(property.getType(), value))); + } + } + } else { + Iterator i = obj.getInstanceProperties().iterator(); + while (i.hasNext()) { + Property p = (Property)i.next(); + if (obj.isSet(p) && !isTransient(p, obj.getType())) { + Object value = obj.get(p); + if (xsdHelper.isAttribute(p)) { + QName name = + namespaceContext.createQName(xsdHelper.getNamespaceURI(p), xsdHelper.getLocalName(p)); + attributes.add(new NameValuePair(name, SDOUtil.convertToString(p.getType(), value))); + } else { + addProperty(elementList, children, p, value, obj); + } + } + } + } + + String prefix = realTypeName.getPrefix(); + String nameSpaceName = realTypeName.getNamespaceURI(); + + if (nameSpaceName != null) { + String writerPrefix = xmlWriter.getPrefix(nameSpaceName); + if (writerPrefix != null) { + xmlWriter.writeStartElement(nameSpaceName, realTypeName.getLocalPart()); + } else { + if (prefix != null) { + xmlWriter.writeStartElement(prefix, realTypeName.getLocalPart(), nameSpaceName); + xmlWriter.writeNamespace(prefix, nameSpaceName); + xmlWriter.setPrefix(prefix, nameSpaceName); + } else { + xmlWriter.writeStartElement(nameSpaceName, realTypeName.getLocalPart()); + xmlWriter.writeDefaultNamespace(nameSpaceName); + xmlWriter.setDefaultNamespace(nameSpaceName); + } + } + } else { + xmlWriter.writeStartElement(realTypeName.getLocalPart()); + } + + for (NameValuePair pair : attributes) { + QName name = (QName)pair.getKey(); + assert namespaceContext.getPrefix(name.getPrefix()).equals(name.getNamespaceURI()); + xmlWriter.writeAttribute(name.getPrefix(), name.getNamespaceURI(), name.getLocalPart(), (String)pair + .getValue()); + } + + for (NameValuePair pair : elementList) { + if (ELEMENT_TEXT.equals(pair.getKey().toString())) { + xmlWriter.writeCharacters((String)pair.getValue()); + } else { + QName name = (QName)pair.getKey(); + xmlWriter.writeStartElement(name.getPrefix(), name.getLocalPart(), name.getNamespaceURI()); + xmlWriter.writeCharacters((String)pair.getValue()); + xmlWriter.writeEndElement(); + } + } + + for (DataObject child : children) { + writeDataObject(child, null, null); + } + xmlWriter.writeEndElement(); + + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo-axiom/src/main/java/org/apache/tuscany/sca/databinding/sdo2om/SDODataSource.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo-axiom/src/main/java/org/apache/tuscany/sca/databinding/sdo2om/SDODataSource.java new file mode 100644 index 0000000000..96d0ee563c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo-axiom/src/main/java/org/apache/tuscany/sca/databinding/sdo2om/SDODataSource.java @@ -0,0 +1,85 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.databinding.sdo2om; + +import static org.apache.tuscany.sca.databinding.sdo.SDODataBinding.ROOT_ELEMENT; + +import java.io.IOException; +import java.io.OutputStream; +import java.io.Writer; + +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.axiom.om.OMDataSource; +import org.apache.axiom.om.OMOutputFormat; +import org.apache.axiom.om.impl.serialize.StreamingOMSerializer; +import org.apache.tuscany.sdo.helper.XMLStreamHelper; +import org.apache.tuscany.sdo.util.SDOUtil; + +import commonj.sdo.DataObject; +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.XMLDocument; + +public class SDODataSource implements OMDataSource { + private HelperContext helperContext; + private XMLDocument sourceDocument; + + public SDODataSource(XMLDocument source, HelperContext helperContext) { + this.sourceDocument = source; + this.helperContext = helperContext; + } + + public SDODataSource(DataObject obj, HelperContext helperContext) { + this.helperContext = helperContext; + this.sourceDocument = + helperContext.getXMLHelper().createDocument(obj, + ROOT_ELEMENT.getNamespaceURI(), + ROOT_ELEMENT.getLocalPart()); + } + + public XMLStreamReader getReader() throws XMLStreamException { + XMLStreamHelper streamHelper = SDOUtil.createXMLStreamHelper(helperContext.getTypeHelper()); + return streamHelper.createXMLStreamReader(sourceDocument); + } + + public void serialize(XMLStreamWriter xmlWriter) throws XMLStreamException { + StreamingOMSerializer serializer = new StreamingOMSerializer(); + serializer.serialize(getReader(), xmlWriter); + } + + public void serialize(OutputStream output, OMOutputFormat format) throws XMLStreamException { + try { + helperContext.getXMLHelper().save(sourceDocument, output, null); + } catch (Exception e) { + throw new XMLStreamException(e); + } + } + + public void serialize(Writer writer, OMOutputFormat format) throws XMLStreamException { + try { + helperContext.getXMLHelper().save(sourceDocument, writer, null); + } catch (IOException e) { + throw new XMLStreamException(e); + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo-axiom/src/main/java/org/apache/tuscany/sca/databinding/sdo2om/XMLDocument2OMElement.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo-axiom/src/main/java/org/apache/tuscany/sca/databinding/sdo2om/XMLDocument2OMElement.java new file mode 100644 index 0000000000..d6ae818f31 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo-axiom/src/main/java/org/apache/tuscany/sca/databinding/sdo2om/XMLDocument2OMElement.java @@ -0,0 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding.sdo2om; + +import org.apache.axiom.om.OMAbstractFactory; +import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.OMFactory; +import org.apache.axiom.om.OMNamespace; +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; +import org.apache.tuscany.sca.databinding.sdo.SDOContextHelper; + +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.XMLDocument; + +/** + * SDO XMLDocument --> AXIOM OMElement transformer + * @version $Rev$ $Date$ + */ +public class XMLDocument2OMElement extends BaseTransformer implements + PullTransformer { + + public OMElement transform(XMLDocument source, TransformationContext context) { + HelperContext helperContext = SDOContextHelper.getHelperContext(context); + SDODataSource dataSource = new SDODataSource(source, helperContext); + OMFactory factory = OMAbstractFactory.getOMFactory(); + OMNamespace namespace = factory.createOMNamespace(source.getRootElementURI(), source.getRootElementName()); + OMElement element = factory.createOMElement(dataSource, source.getRootElementName(), namespace); + return element; + } + + public Class getSourceType() { + return XMLDocument.class; + } + + public Class getTargetType() { + return OMElement.class; + } + + public int getWeight() { + return 10; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo-axiom/src/main/java/org/apache/tuscany/sca/databinding/sdo2om/module/SDOAxiomModuleActivator.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo-axiom/src/main/java/org/apache/tuscany/sca/databinding/sdo2om/module/SDOAxiomModuleActivator.java new file mode 100644 index 0000000000..dc9ecdafae --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo-axiom/src/main/java/org/apache/tuscany/sca/databinding/sdo2om/module/SDOAxiomModuleActivator.java @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.databinding.sdo2om.module; + +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.ModuleActivator; +import org.apache.tuscany.sca.databinding.TransformerExtensionPoint; +import org.apache.tuscany.sca.databinding.sdo2om.DataObject2OMElement; +import org.apache.tuscany.sca.databinding.sdo2om.XMLDocument2OMElement; + +/** + * Module activator for SDO/AXIOM databinding + * + * @version $Rev$ $Date$ + */ +public class SDOAxiomModuleActivator implements ModuleActivator { + + public Object[] getExtensionPoints() { + return null; + } + + public void start(ExtensionPointRegistry registry) { + TransformerExtensionPoint transformers = registry.getExtensionPoint(TransformerExtensionPoint.class); + transformers.addTransformer(new DataObject2OMElement()); + transformers.addTransformer(new XMLDocument2OMElement()); + } + + public void stop(ExtensionPointRegistry registry) { + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo-axiom/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo-axiom/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator new file mode 100644 index 0000000000..a16317431c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo-axiom/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# Implementation class for the ExtensionActivator +org.apache.tuscany.sca.databinding.sdo2om.module.SDOAxiomModuleActivator \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo-axiom/src/test/java/org/apache/tuscany/sca/databinding/sdo2om/DataObject2OMElementTestCase.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo-axiom/src/test/java/org/apache/tuscany/sca/databinding/sdo2om/DataObject2OMElementTestCase.java new file mode 100644 index 0000000000..9d32991bf9 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo-axiom/src/test/java/org/apache/tuscany/sca/databinding/sdo2om/DataObject2OMElementTestCase.java @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.databinding.sdo2om; + +import javax.xml.stream.XMLStreamException; + +import junit.framework.Assert; + +import org.apache.axiom.om.OMElement; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; +import org.apache.tuscany.sca.interfacedef.util.XMLType; + +import commonj.sdo.DataObject; + +/** + * + */ +public class DataObject2OMElementTestCase extends SDOTransformerTestCaseBase { + + @Override + protected DataType getSourceDataType() { + return new DataTypeImpl(DataObject.class.getName(), DataObject.class, new XMLType(ORDER_QNAME, null)); + } + + @Override + protected DataType getTargetDataType() { + return new DataTypeImpl(OMElement.class.getName(), OMElement.class, new XMLType(ORDER_QNAME, null)); + } + + public final void testTransform() throws XMLStreamException { + OMElement element = new DataObject2OMElement().transform(dataObject, context); + Assert.assertEquals(ORDER_QNAME.getNamespaceURI(), element.getNamespace().getNamespaceURI()); + Assert.assertEquals(ORDER_QNAME.getLocalPart(), element.getLocalName()); +// TODO: This fails with Axiom 1.2.4 +// StringWriter writer = new StringWriter(); +// element.serialize(writer); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo-axiom/src/test/java/org/apache/tuscany/sca/databinding/sdo2om/SDOTransformerTestCaseBase.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo-axiom/src/test/java/org/apache/tuscany/sca/databinding/sdo2om/SDOTransformerTestCaseBase.java new file mode 100644 index 0000000000..7485910db6 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo-axiom/src/test/java/org/apache/tuscany/sca/databinding/sdo2om/SDOTransformerTestCaseBase.java @@ -0,0 +1,79 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.databinding.sdo2om; + +import javax.xml.namespace.QName; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.impl.TransformationContextImpl; +import org.apache.tuscany.sca.interfacedef.DataType; + +import com.example.ipo.sdo.PurchaseOrderType; +import com.example.ipo.sdo.SdoFactory; +import com.example.ipo.sdo.USAddress; +import commonj.sdo.DataObject; +import commonj.sdo.helper.HelperContext; +import commonj.sdo.impl.HelperProvider; + +/** + * The base class for SDO-related test cases + */ +public abstract class SDOTransformerTestCaseBase extends TestCase { + protected static final QName ORDER_QNAME = new QName("http://www.example.com/IPO", "purchaseOrder"); + + protected HelperContext helperContext; + protected String binding = DataObject.class.getName(); + protected TransformationContext context; + protected TransformationContext reversedContext; + protected DataObject dataObject; + + /** + * @see junit.framework.TestCase#setUp() + */ + protected void setUp() throws Exception { + super.setUp(); + helperContext = HelperProvider.getDefaultContext(); + SdoFactory.INSTANCE.register(helperContext); + + context = new TransformationContextImpl(); + context.setSourceDataType(getSourceDataType()); + context.setTargetDataType(getTargetDataType()); + + reversedContext = new TransformationContextImpl(); + reversedContext.setSourceDataType(getTargetDataType()); + reversedContext.setTargetDataType(getSourceDataType()); + + PurchaseOrderType po = SdoFactory.INSTANCE.createPurchaseOrderType(); + USAddress address = SdoFactory.INSTANCE.createUSAddress(); + address.setCity("San Jose"); + address.setStreet("123 ABC St"); + address.setState("CA"); + address.setStreet("95131"); + po.setBillTo(address); + dataObject = (DataObject) po; + } + + protected abstract DataType getSourceDataType(); + + protected abstract DataType getTargetDataType(); + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo-axiom/src/test/java/org/apache/tuscany/sca/databinding/sdo2om/XMLDocument2OMElementTestCase.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo-axiom/src/test/java/org/apache/tuscany/sca/databinding/sdo2om/XMLDocument2OMElementTestCase.java new file mode 100644 index 0000000000..e141e27098 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo-axiom/src/test/java/org/apache/tuscany/sca/databinding/sdo2om/XMLDocument2OMElementTestCase.java @@ -0,0 +1,62 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.databinding.sdo2om; + +import java.io.StringWriter; + +import javax.xml.stream.XMLStreamException; + +import junit.framework.Assert; + +import org.apache.axiom.om.OMElement; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; +import org.apache.tuscany.sca.interfacedef.util.XMLType; + +import commonj.sdo.helper.XMLDocument; + +/** + * + */ +public class XMLDocument2OMElementTestCase extends SDOTransformerTestCaseBase { + + @Override + protected DataType getSourceDataType() { + return new DataTypeImpl(XMLDocument.class.getName(), XMLDocument.class, new XMLType(ORDER_QNAME, null)); + } + + @Override + protected DataType getTargetDataType() { + return new DataTypeImpl(OMElement.class.getName(), OMElement.class, new XMLType(ORDER_QNAME, null)); + } + + public final void testTransform() throws XMLStreamException { + XMLDocument document = + helperContext.getXMLHelper().createDocument(dataObject, + ORDER_QNAME.getNamespaceURI(), + ORDER_QNAME.getLocalPart()); + OMElement element = new XMLDocument2OMElement().transform(document, context); + Assert.assertEquals(ORDER_QNAME.getNamespaceURI(), element.getNamespace().getNamespaceURI()); + Assert.assertEquals(ORDER_QNAME.getLocalPart(), element.getLocalName()); + StringWriter writer = new StringWriter(); + element.serialize(writer); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo-axiom/src/test/resources/ipo.xsd b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo-axiom/src/test/resources/ipo.xsd new file mode 100644 index 0000000000..241ec15d36 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo-axiom/src/test/resources/ipo.xsd @@ -0,0 +1,136 @@ + + + + + + International Purchase order schema for Example.com + Copyright 2000 Example.com. All rights reserved. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo-axiom/src/test/resources/stock.xsd b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo-axiom/src/test/resources/stock.xsd new file mode 100644 index 0000000000..a0a6717371 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo-axiom/src/test/resources/stock.xsd @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/.checkstyle b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/.checkstyle new file mode 100644 index 0000000000..c7b30ffd5e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/.checkstyle @@ -0,0 +1,25 @@ + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/.ruleset b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/.ruleset new file mode 100644 index 0000000000..27b9ab847c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/.ruleset @@ -0,0 +1,191 @@ + + + + + PMD Plugin preferences rule set + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/DISCLAIMER b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/DISCLAIMER new file mode 100644 index 0000000000..d68a410903 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/DISCLAIMER @@ -0,0 +1,8 @@ +Apache Tuscany is an effort undergoing incubation at The Apache Software +Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is +required of all newly accepted projects until a further review indicates that +the infrastructure, communications, and decision making process have stabilized +in a manner consistent with other successful ASF projects. While incubation +status is not necessarily a reflection of the completeness or stability of the +code, it does indicate that the project has yet to be fully endorsed by the ASF. + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/LICENSE b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/NOTICE b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/NOTICE new file mode 100644 index 0000000000..94481d6cfa --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2007 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/pom.xml b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/pom.xml new file mode 100755 index 0000000000..453d4edbcb --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/pom.xml @@ -0,0 +1,119 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 0.91-incubating-SNAPSHOT + ../pom.xml + + tuscany-databinding-sdo + Apache Tuscany Data Binding for SDO + + + + org.apache.tuscany.sca + tuscany-core-spi + 0.91-incubating-SNAPSHOT + + + org.apache.tuscany.sca + tuscany-databinding + 0.91-incubating-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-implementation-java-xml + 0.91-incubating-SNAPSHOT + + + + org.apache.tuscany.sdo + tuscany-sdo-impl + 1.0-incubating-beta1 + + + + + + + org.codehaus.mojo + build-helper-maven-plugin + 1.0 + + + add-test-source + generate-sources + + add-test-source + + + + target/sdo-source + + + + + + + org.apache.tuscany.sdo + tuscany-sdo-plugin + 1.0-incubating-beta1 + + + generate-po-sdo + generate-sources + + ${basedir}/src/test/resources/ipo.xsd + com.example.ipo.sdo + true + true + true + + + generate + + + + generate-stock-sdo + generate-sources + + ${basedir}/src/test/resources/stock.xsd + com.example.stock.sdo + Stock + true + true + true + + + generate + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/DataObject2String.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/DataObject2String.java new file mode 100755 index 0000000000..405de57ab3 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/DataObject2String.java @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding.sdo; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; + +import commonj.sdo.DataObject; +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.XMLHelper; + +public class DataObject2String extends BaseTransformer implements + PullTransformer { + + public String transform(DataObject source, TransformationContext context) { + try { + HelperContext helperContext = SDOContextHelper.getHelperContext(context); + XMLHelper xmlHelper = helperContext.getXMLHelper(); + QName elementName = SDOContextHelper.getElement(context.getSourceDataType()); + return xmlHelper.save(source, elementName.getNamespaceURI(), elementName.getLocalPart()); + } catch (Exception e) { + throw new TransformationException(e); + } + } + + public Class getSourceType() { + return DataObject.class; + } + + public Class getTargetType() { + return String.class; + } + + public int getWeight() { + return 40; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/DataObject2XMLStreamReader.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/DataObject2XMLStreamReader.java new file mode 100755 index 0000000000..863a787362 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/DataObject2XMLStreamReader.java @@ -0,0 +1,68 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding.sdo; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; +import org.apache.tuscany.sdo.helper.XMLStreamHelper; +import org.apache.tuscany.sdo.util.SDOUtil; + + +import commonj.sdo.DataObject; +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.XMLDocument; +import commonj.sdo.helper.XMLHelper; + +public class DataObject2XMLStreamReader extends BaseTransformer implements + PullTransformer { + + public XMLStreamReader transform(DataObject source, TransformationContext context) { + try { + HelperContext helperContext = SDOContextHelper.getHelperContext(context); + XMLStreamHelper streamHelper = SDOUtil.createXMLStreamHelper(helperContext.getTypeHelper()); + QName elementName = SDOContextHelper.getElement(context.getSourceDataType()); + XMLHelper xmlHelper = helperContext.getXMLHelper(); + XMLDocument document = + xmlHelper.createDocument(source, elementName.getNamespaceURI(), elementName.getLocalPart()); + return streamHelper.createXMLStreamReader(document); + } catch (XMLStreamException e) { + // TODO: Add context to the exception + throw new TransformationException(e); + } + } + + public Class getSourceType() { + return DataObject.class; + } + + public Class getTargetType() { + return XMLStreamReader.class; + } + + public int getWeight() { + return 10; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/DuplicateHelperContextException.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/DuplicateHelperContextException.java new file mode 100644 index 0000000000..c83e93dc4e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/DuplicateHelperContextException.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding.sdo; + + +/** + * @version $Rev$ $Date$ + */ +public class DuplicateHelperContextException extends RuntimeException { + private static final long serialVersionUID = -5229624905543066038L; + + /** + * Constructor specifying message and the ID of the duplicate HelperContext. + * + * @param message exception message + * @param identifier the id of the HelperContext that is already present + */ + public DuplicateHelperContextException(String message) { + super(message); + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/HelperContextProcessor.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/HelperContextProcessor.java new file mode 100644 index 0000000000..561e5f3b39 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/HelperContextProcessor.java @@ -0,0 +1,110 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding.sdo; + +import java.beans.Introspector; +import java.lang.reflect.Field; +import java.lang.reflect.Method; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.implementation.java.JavaImplementation; +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.introspect.IntrospectionException; +import org.apache.tuscany.sca.implementation.java.introspect.impl.BaseJavaClassVisitor; + +import commonj.sdo.helper.HelperContext; + +/** + * Processes {@link @HelperContext} annotations on a component implementation + * and adds a {@link JavaMappedProperty} to the component type which will be + * used to inject the appropriate context + * + * @version $Rev$ $Date$ + */ +public class HelperContextProcessor extends BaseJavaClassVisitor { + private HelperContextRegistry registry; + + /** + * @param registry + */ + public HelperContextProcessor(AssemblyFactory assemblyFactory, HelperContextRegistry registry) { + super(assemblyFactory); + this.registry = registry; + } + + /** + * Takes a setter or getter method name and converts it to a property name + * according to JavaBean conventions. For example, setFoo(var) + * is returned as property foo + */ + public static String toPropertyName(String name) { + if (!name.startsWith("set")) { + return name; + } + return Introspector.decapitalize(name.substring(3)); + } + + public void visitMethod(Method method, + JavaImplementation type) throws IntrospectionException { + if (!method.isAnnotationPresent(org.apache.tuscany.sca.databinding.sdo.api.HelperContext.class)) { + return; + } + if (method.getParameterTypes().length != 1) { + throw new IllegalArgumentException("HelperContext setter must have one parameter: " + method); + } + Class paramType = method.getParameterTypes()[0]; + if (HelperContext.class == paramType) { + String name = toPropertyName(method.getName()); + JavaResourceImpl resource = new JavaResourceImpl(new JavaElementImpl(method, 0)); +// resource.setObjectFactory(new HelperContextFactory(context.getComponentId())); + type.getResources().put(name, resource); + } + } + + public void visitField(Field field, + JavaImplementation type) throws IntrospectionException { + if (!field.isAnnotationPresent(org.apache.tuscany.sca.databinding.sdo.api.HelperContext.class)) { + return; + } + Class paramType = field.getType(); + if (HelperContext.class == paramType) { + String name = field.getName(); + JavaResourceImpl resource = new JavaResourceImpl(new JavaElementImpl(field)); +// resource.setObjectFactory(new HelperContextFactory(context.getComponentId())); + type.getResources().put(name, resource); + } + } + + /* + private class HelperContextFactory implements ObjectFactory { + private URI id; + + public HelperContextFactory(URI id) { + super(); + this.id = id; + } + + public HelperContext getInstance() throws ObjectCreationException { + return registry.getHelperContext(id); + } + + } + */ +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/HelperContextRegistry.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/HelperContextRegistry.java new file mode 100644 index 0000000000..75d9d33cbb --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/HelperContextRegistry.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.databinding.sdo; + +import commonj.sdo.helper.HelperContext; + +/** + * A registry for SDO HelperContext + * + * @version $Rev$ $Date$ + */ +public interface HelperContextRegistry { + /** + * Register a HelperContext with the id + * + * @param id + * @param context + */ + void register(Object id, HelperContext context) throws DuplicateHelperContextException; + + /** + * Unregister the HelperContext + * + * @param id + */ + void unregister(Object id); + + /** + * Get the HelperContext associated with the id + * + * @param id The URI of the HelperContext + * @return + */ + HelperContext getHelperContext(Object id); +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/HelperContextRegistryImpl.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/HelperContextRegistryImpl.java new file mode 100644 index 0000000000..429946f78d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/HelperContextRegistryImpl.java @@ -0,0 +1,49 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.databinding.sdo; + +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +import commonj.sdo.helper.HelperContext; + +/** + * A registry for SDO HelperContext + * + * @version $Rev$ $Date$ + */ +public class HelperContextRegistryImpl implements HelperContextRegistry { + private final Map registry = new ConcurrentHashMap(); + + public synchronized void register(Object id, HelperContext context) { + if (registry.containsKey(id)) { + throw new DuplicateHelperContextException("Duplicate HelperContext: " + id); + } + registry.put(id, context); + } + + public void unregister(Object id) { + registry.remove(id); + } + + public HelperContext getHelperContext(Object id) { + return registry.get(id); + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/ImportSDO.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/ImportSDO.java new file mode 100644 index 0000000000..30a3e1c3a9 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/ImportSDO.java @@ -0,0 +1,78 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.databinding.sdo; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.impl.BaseImpl; + +import commonj.sdo.helper.HelperContext; + +/** + * The model object for import.sdo + * + * @version $Rev$ $Date$ + */ +public class ImportSDO extends BaseImpl { + public static final QName IMPORT_SDO = + new QName("http://tuscany.apache.org/xmlns/sca/databinding/sdo/1.0", "import.sdo"); + + private HelperContext helperContext; + private String factoryClassName; + private String schemaLocation; + + public ImportSDO(HelperContext helperContext) { + super(); + this.helperContext = helperContext; + setUnresolved(true); + } + + public HelperContext getHelperContext() { + return helperContext; + } + + /** + * @return the factoryClassName + */ + public String getFactoryClassName() { + return factoryClassName; + } + + /** + * @param factoryClassName the factoryClassName to set + */ + public void setFactoryClassName(String factoryClassName) { + this.factoryClassName = factoryClassName; + } + + /** + * @return the schemaLocation + */ + public String getSchemaLocation() { + return schemaLocation; + } + + /** + * @param schemaLocation the schemaLocation to set + */ + public void setSchemaLocation(String schemaLocation) { + this.schemaLocation = schemaLocation; + } +} \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/ImportSDOProcessor.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/ImportSDOProcessor.java new file mode 100755 index 0000000000..32019ef760 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/ImportSDOProcessor.java @@ -0,0 +1,193 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding.sdo; + +import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; +import static org.apache.tuscany.sca.databinding.sdo.ImportSDO.IMPORT_SDO; + +import java.io.IOException; +import java.io.InputStream; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.net.URI; +import java.net.URL; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.contribution.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.sdo.util.SDOUtil; + +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.XSDHelper; +import commonj.sdo.impl.HelperProvider; + + +/** + * Loader that handles <import.sdo> elements. + * + * @version $Rev$ $Date$ + */ +public class ImportSDOProcessor implements StAXArtifactProcessor { + private HelperContextRegistry helperContextRegistry; + + public ImportSDOProcessor(HelperContextRegistry helperContextRegistry) { + super(); + this.helperContextRegistry = helperContextRegistry; + } + + public QName getXMLType() { + return IMPORT_SDO; + } + + public ImportSDO read(XMLStreamReader reader) throws ContributionReadException { + assert IMPORT_SDO.equals(reader.getName()); + + HelperContext helperContext = null; + + // FIXME: [rfeng] How to get the enclosing composite? + int id = System.identityHashCode(reader); + // FIXME: [rfeng] How to associate the TypeHelper with deployment + // context? + synchronized (helperContextRegistry) { + helperContext = helperContextRegistry.getHelperContext(id); + if (helperContext == null) { + helperContext = SDOUtil.createHelperContext(); + helperContextRegistry.register(id, helperContext); + } + } + + ImportSDO importSDO = new ImportSDO(helperContext); + String factoryName = reader.getAttributeValue(null, "factory"); + if (factoryName != null) { + importSDO.setFactoryClassName(factoryName); + } + String location = reader.getAttributeValue(null, "location"); + if (location != null) { + importSDO.setSchemaLocation(location); + } + + // Skip to end element + try { + while (reader.hasNext()) { + if (reader.next() == END_ELEMENT && ImportSDO.IMPORT_SDO.equals(reader.getName())) { + break; + } + } + } catch (XMLStreamException e) { + throw new ContributionReadException(e); + } + return importSDO; + } + + private void importFactory(ImportSDO importSDO) throws ContributionResolveException { + String factoryName = importSDO.getFactoryClassName(); + if (factoryName != null) { + ClassLoader cl = Thread.currentThread().getContextClassLoader(); + try { + Class factoryClass = cl.loadClass(factoryName); + register(factoryClass, importSDO.getHelperContext()); + } catch (Exception e) { + throw new ContributionResolveException(e); + } + importSDO.setUnresolved(false); + } + } + + private static void register(Class factoryClass, HelperContext helperContext) throws Exception { + Field field = factoryClass.getField("INSTANCE"); + Object factory = field.get(null); + Method method = factory.getClass().getMethod("register", new Class[] {HelperContext.class}); + method.invoke(factory, new Object[] {helperContext}); + + // FIXME: How do we associate the application HelperContext with the one + // imported by the composite + HelperContext defaultContext = HelperProvider.getDefaultContext(); + method.invoke(factory, new Object[] {defaultContext}); + } + + private void importWSDL(ImportSDO importSDO) throws ContributionResolveException { + String location = importSDO.getSchemaLocation(); + if (location != null) { + try { + URL wsdlURL = null; + URI uri = URI.create(location); + if (uri.isAbsolute()) { + wsdlURL = uri.toURL(); + } + wsdlURL = Thread.currentThread().getContextClassLoader().getResource(location); + if (null == wsdlURL) { + ContributionResolveException loaderException = new ContributionResolveException( + "WSDL location error"); + throw loaderException; + } + InputStream xsdInputStream = wsdlURL.openStream(); + try { + XSDHelper xsdHelper = importSDO.getHelperContext().getXSDHelper(); + xsdHelper.define(xsdInputStream, wsdlURL.toExternalForm()); + } finally { + xsdInputStream.close(); + } + // FIXME: How do we associate the application HelperContext with + // the one + // imported by the composite + HelperContext defaultContext = HelperProvider.getDefaultContext(); + xsdInputStream = wsdlURL.openStream(); + try { + XSDHelper xsdHelper = defaultContext.getXSDHelper(); + ClassLoader cl = Thread.currentThread().getContextClassLoader(); + xsdHelper.define(xsdInputStream, wsdlURL.toExternalForm()); + } finally { + xsdInputStream.close(); + } + } catch (IOException e) { + throw new ContributionResolveException(e); + } + importSDO.setUnresolved(false); + } + } + + public QName getArtifactType() { + return ImportSDO.IMPORT_SDO; + } + + public void write(ImportSDO model, XMLStreamWriter outputSource) throws ContributionWriteException { + // TODO Auto-generated method stub + + } + + public Class getModelType() { + return ImportSDO.class; + } + + public void resolve(ImportSDO importSDO, ModelResolver resolver) throws ContributionResolveException { + importFactory(importSDO); + importWSDL(importSDO); + if (!importSDO.isUnresolved()) { + resolver.addModel(importSDO); + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOContextHelper.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOContextHelper.java new file mode 100644 index 0000000000..78058a5969 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOContextHelper.java @@ -0,0 +1,106 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.databinding.sdo; + +import java.awt.Component; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.util.XMLType; +import org.apache.tuscany.sdo.util.SDOUtil; + +import commonj.sdo.helper.HelperContext; +import commonj.sdo.impl.HelperProvider; + +/** + * Helper class to get TypeHelper from the context + */ +public final class SDOContextHelper { + private SDOContextHelper() { + } + + public static HelperContext getHelperContext(TransformationContext context) { + if (context == null || context.getMetadata() == null) { + return getDefaultHelperContext(); + } + HelperContext helperContext = null; + Component composite = (Component)context.getMetadata().get(Component.class); + if (composite != null) { + // SDOHelperContext sdoContext = + // (SDOHelperContext)composite.getExtensions().get(HelperContext.class.getName()); + // if (sdoContext != null) { + // helperContext = sdoContext.getHelperContext(); + // } + // AtomicComponent child = + // (AtomicComponent)composite.getSystemChild(HelperContext.class.getName()); + // try { + // helperContext = (HelperContext)child.getTargetInstance(); + // } catch (TargetResolutionException e) { + // helperContext = null; + // } + } + if (helperContext == null) { + return getDefaultHelperContext(); + } else { + return helperContext; + } + } + + public static HelperContext getHelperContext(Composite model) { + HelperContext helperContext = null; + for (Object ext : model.getExtensions()) { + if (ext instanceof HelperContext) { + helperContext = (HelperContext)ext; + break; + } + } + if (helperContext == null) { + helperContext = SDOUtil.createHelperContext(); + model.getExtensions().add(helperContext); + } + + if (helperContext == null) { + helperContext = getDefaultHelperContext(); + } + + return helperContext; + } + + protected static HelperContext getDefaultHelperContext() { + // SDOUtil.createHelperContext(); + return HelperProvider.getDefaultContext(); + } + + public static QName getElement(DataType dataType) { + Object logical = dataType.getLogical(); + QName elementName = SDODataBinding.ROOT_ELEMENT; + if (logical instanceof XMLType) { + XMLType xmlType = (XMLType)logical; + QName element = xmlType.getElementName(); + if (element != null) { + elementName = element; + } + } + return elementName; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDODataBinding.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDODataBinding.java new file mode 100644 index 0000000000..2736d4bbde --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDODataBinding.java @@ -0,0 +1,122 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.databinding.sdo; + +import java.lang.annotation.Annotation; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.databinding.ExceptionHandler; +import org.apache.tuscany.sca.databinding.SimpleTypeMapper; +import org.apache.tuscany.sca.databinding.WrapperHandler; +import org.apache.tuscany.sca.databinding.impl.BaseDataBinding; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.util.XMLType; + +import commonj.sdo.DataObject; +import commonj.sdo.Type; +import commonj.sdo.helper.CopyHelper; +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.XMLDocument; +import commonj.sdo.impl.HelperProvider; + +/** + * SDO Databinding + * + * @version $Reve$ $Date$ + */ +public class SDODataBinding extends BaseDataBinding { + public static final String NAME = DataObject.class.getName(); + public static final String[] ALIASES = new String[] {"sdo"}; + + public static final String ROOT_NAMESPACE = "commonj.sdo"; + public static final QName ROOT_ELEMENT = new QName(ROOT_NAMESPACE, "dataObject"); + + private WrapperHandler wrapperHandler; + + public SDODataBinding() { + super(NAME, ALIASES, DataObject.class); + wrapperHandler = new SDOWrapperHandler(); + } + + @Override + public boolean introspect(DataType dataType, Annotation[] annotations) { + Object physical = dataType.getPhysical(); + if (!(physical instanceof Class)) { + return false; + } + Class javaType = (Class)physical; + HelperContext context = HelperProvider.getDefaultContext(); + // FIXME: Need a better to test dynamic SDO + if (DataObject.class.isAssignableFrom(javaType)) { + // Dynamic SDO + dataType.setDataBinding(getName()); + dataType.setLogical(XMLType.UNKNOWN); + return true; + } + // FIXME: We need to access HelperContext + Type type = context.getTypeHelper().getType(javaType); + if (type == null) { + return false; + } + if (type.isDataType()) { + // FIXME: Ignore simple types? + return false; + } + String namespace = type.getURI(); + String name = context.getXSDHelper().getLocalName(type); + QName xmlType = new QName(namespace, name); + dataType.setDataBinding(getName()); + dataType.setLogical(new XMLType(null, xmlType)); + return true; + } + + @Override + public WrapperHandler getWrapperHandler() { + return wrapperHandler; + } + + public SimpleTypeMapper getSimpleTypeMapper() { + return new SDOSimpleTypeMapper(); + } + + @Override + public Object copy(Object arg) { + HelperContext context = HelperProvider.getDefaultContext(); + CopyHelper copyHelper = context.getCopyHelper(); + if (arg instanceof XMLDocument) { + XMLDocument document = (XMLDocument)arg; + DataObject dataObject = copyHelper.copy(document.getRootObject()); + return context.getXMLHelper().createDocument(dataObject, + document.getRootElementURI(), + document.getRootElementName()); + } else if (arg instanceof DataObject) { + return context.getCopyHelper().copy((DataObject)arg); + } else { + return super.copy(arg); + } + } + + @Override + public ExceptionHandler getExceptionHandler() { + return new SDOExceptionHandler(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOExceptionHandler.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOExceptionHandler.java new file mode 100644 index 0000000000..1056d2ec38 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOExceptionHandler.java @@ -0,0 +1,124 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.databinding.sdo; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; +import java.lang.reflect.Method; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.databinding.ExceptionHandler; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; +import org.apache.tuscany.sca.interfacedef.util.XMLType; + +import commonj.sdo.Type; +import commonj.sdo.helper.HelperContext; +import commonj.sdo.impl.HelperProvider; + +/** + * SDO implementation of ExceptionHandler + * + * @version $Rev$ $Date$ + */ +public class SDOExceptionHandler implements ExceptionHandler { + private static final Class[] EMPTY_CLASS_ARRAY = new Class[0]; + + // FIXME: Need a way to pass in the HelperContext + private HelperContext helperContext = HelperProvider.getDefaultContext(); + + /** + *
    + *
  • WrapperException(String message, FaultBean faultInfo)
    + * A constructor where WrapperException is replaced with the name of the + * generated wrapper exception and FaultBean is replaced by the name of the + * generated fault bean. + *
  • WrapperException(String message, FaultBean faultInfo, Throwable + * cause)
    + * A constructor whereWrapperException is replaced with the name of the + * generated wrapper exception and FaultBean is replaced by the name of the + * generated fault bean. The last argument, cause, may be used to convey + * protocol specific fault information + *
+ */ + public Exception createException(DataType exceptionType, String message, Object faultInfo, Throwable cause) { + Class exceptionClass = (Class)exceptionType.getPhysical(); + DataType faultBeanType = exceptionType.getLogical(); + Class faultBeanClass = (Class)faultBeanType.getPhysical(); + try { + Constructor constructor = + exceptionClass.getConstructor(new Class[] {String.class, faultBeanClass, Throwable.class}); + return (Exception)constructor.newInstance(new Object[] {message, faultInfo, cause}); + } catch (Throwable e) { + throw new IllegalArgumentException(e); + } + } + + public Object getFaultInfo(Exception exception) { + if (exception == null) { + return null; + } + try { + Method method = exception.getClass().getMethod("getFaultInfo", EMPTY_CLASS_ARRAY); + return method.invoke(exception, (Object[])null); + } catch (Throwable e) { + throw new IllegalArgumentException(e); + } + } + + public DataType getFaultType(DataType exceptionDataType) { + Class exceptionType = (Class) exceptionDataType.getPhysical(); + Class faultBeanClass = null; + try { + Method method = exceptionType.getMethod("getFaultInfo", EMPTY_CLASS_ARRAY); + faultBeanClass = method.getReturnType(); + } catch (NoSuchMethodException e) { + faultBeanClass = null; + } + if (faultBeanClass == null) { + return null; + } + + QName faultElement = null; + try { + Field field = exceptionType.getField("FAULT_ELEMENT"); + faultElement = (QName)field.get(null); + } catch (NoSuchFieldException e) { + // Fall back to type inspection + Type type = helperContext.getTypeHelper().getType(faultBeanClass); + if (type != null) { + String ns = type.getURI(); + String name = helperContext.getXSDHelper().getLocalName(type); + faultElement = new QName(ns, name); + } + } catch (Throwable e) { + // Ignore + } + if (faultElement == null) { + return null; + } + DataType faultType = + new DataTypeImpl(SDODataBinding.NAME, faultBeanClass, new XMLType(faultElement, null)); + return faultType; + + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOSimpleTypeMapper.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOSimpleTypeMapper.java new file mode 100644 index 0000000000..752120c889 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOSimpleTypeMapper.java @@ -0,0 +1,67 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.databinding.sdo; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.databinding.SimpleTypeMapper; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sdo.util.SDOUtil; + + +import commonj.sdo.Type; +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.TypeHelper; + +/** + * SDO Java/XML mapping for simple XSD types + */ +public class SDOSimpleTypeMapper implements SimpleTypeMapper { + public static final String URI_2001_SCHEMA_XSD = "http://www.w3.org/2001/XMLSchema"; + + public SDOSimpleTypeMapper() { + super(); + } + + public Object toJavaObject(QName typeName, String value, TransformationContext context) { + Type type = null; + if (URI_2001_SCHEMA_XSD.equals(typeName.getNamespaceURI())) { + type = SDOUtil.getXSDSDOType(typeName.getLocalPart()); + } else { + HelperContext helperContext = SDOContextHelper.getHelperContext(context); + TypeHelper typeHelper = helperContext.getTypeHelper(); + type = typeHelper.getType(typeName.getNamespaceURI(), typeName.getLocalPart()); + } + return SDOUtil.createFromString(type, value); + } + + public String toXMLLiteral(QName typeName, Object obj, TransformationContext context) { + Type type = null; + if (URI_2001_SCHEMA_XSD.equals(typeName.getNamespaceURI())) { + type = SDOUtil.getXSDSDOType(typeName.getLocalPart()); + } else { + HelperContext helperContext = SDOContextHelper.getHelperContext(context); + TypeHelper typeHelper = helperContext.getTypeHelper(); + type = typeHelper.getType(typeName.getNamespaceURI(), typeName.getLocalPart()); + } + return SDOUtil.convertToString(type, obj); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOWrapperHandler.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOWrapperHandler.java new file mode 100644 index 0000000000..d89627da71 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/SDOWrapperHandler.java @@ -0,0 +1,99 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.databinding.sdo; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.WrapperHandler; +import org.apache.tuscany.sca.interfacedef.util.ElementInfo; + +import commonj.sdo.DataObject; +import commonj.sdo.Property; +import commonj.sdo.Sequence; +import commonj.sdo.Type; +import commonj.sdo.helper.DataFactory; +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.XMLDocument; +import commonj.sdo.helper.XMLHelper; + +/** + * SDO Wrapper Handler + */ +public class SDOWrapperHandler implements WrapperHandler { + + /** + * @see org.apache.tuscany.sca.databinding.WrapperHandler#create(ElementInfo, TransformationContext) + */ + public Object create(ElementInfo element, TransformationContext context) { + HelperContext helperContext = SDOContextHelper.getHelperContext(context); + QName typeName = element.getType().getQName(); + DataFactory dataFactory = helperContext.getDataFactory(); + DataObject root = dataFactory.create(typeName.getNamespaceURI(), typeName.getLocalPart()); + XMLHelper xmlHelper = helperContext.getXMLHelper(); + return xmlHelper.createDocument(root, element.getQName().getNamespaceURI(), element.getQName().getLocalPart()); + } + + /** + * @see org.apache.tuscany.sca.databinding.WrapperHandler#setChild(java.lang.Object, int, ElementInfo, + * java.lang.Object) + */ + public void setChild(Object wrapper, int i, ElementInfo childElement, Object value) { + DataObject wrapperDO = + (wrapper instanceof XMLDocument) ? ((XMLDocument)wrapper).getRootObject() : (DataObject)wrapper; + wrapperDO.set(i, value); + } + + @SuppressWarnings("unchecked") + public List getChildren(Object wrapper) { + DataObject wrapperDO = + (wrapper instanceof XMLDocument) ? ((XMLDocument)wrapper).getRootObject() : (DataObject)wrapper; + List properties = wrapperDO.getInstanceProperties(); + List elements = new ArrayList(); + Type type = wrapperDO.getType(); + if (type.isSequenced()) { + // Add values in the sequence + Sequence sequence = wrapperDO.getSequence(); + for (int i = 0; i < sequence.size(); i++) { + // Skip mixed text + if (sequence.getProperty(i) != null) { + elements.add(sequence.getValue(i)); + } + } + } else { + for (Property p : properties) { + Object child = wrapperDO.get(p); + if (p.isMany()) { + for (Object c : (Collection)child) { + elements.add(c); + } + } else { + elements.add(child); + } + } + } + return elements; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/String2DataObject.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/String2DataObject.java new file mode 100755 index 0000000000..01ec74bb30 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/String2DataObject.java @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding.sdo; + +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; + +import commonj.sdo.DataObject; +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.XMLHelper; + +public class String2DataObject extends BaseTransformer implements + PullTransformer { + + public DataObject transform(String source, TransformationContext context) { + try { + HelperContext helperContext = SDOContextHelper.getHelperContext(context); + XMLHelper xmlHelper = helperContext.getXMLHelper(); + return xmlHelper.load(source).getRootObject(); + } catch (Exception e) { + throw new TransformationException(e); + } + } + + public Class getSourceType() { + return String.class; + } + + public Class getTargetType() { + return DataObject.class; + } + + public int getWeight() { + return 50; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/XMLDocument2String.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/XMLDocument2String.java new file mode 100644 index 0000000000..d11e6e46d9 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/XMLDocument2String.java @@ -0,0 +1,59 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding.sdo; + +import java.io.StringWriter; + +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; + +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.XMLDocument; +import commonj.sdo.helper.XMLHelper; + +public class XMLDocument2String extends BaseTransformer implements + PullTransformer { + + public String transform(XMLDocument source, TransformationContext context) { + try { + HelperContext helperContext = SDOContextHelper.getHelperContext(context); + XMLHelper xmlHelper = helperContext.getXMLHelper(); + StringWriter writer = new StringWriter(); + xmlHelper.save(source, writer, null); + return writer.toString(); + } catch (Exception e) { + throw new TransformationException(e); + } + } + + public Class getSourceType() { + return XMLDocument.class; + } + + public Class getTargetType() { + return String.class; + } + + public int getWeight() { + return 40; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/XMLDocument2XMLStreamReader.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/XMLDocument2XMLStreamReader.java new file mode 100755 index 0000000000..0ea20bdee3 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/XMLDocument2XMLStreamReader.java @@ -0,0 +1,64 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding.sdo; + +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; +import org.apache.tuscany.sdo.helper.XMLStreamHelper; +import org.apache.tuscany.sdo.util.SDOUtil; + + +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.XMLDocument; + +public class XMLDocument2XMLStreamReader extends BaseTransformer implements + PullTransformer { + /** + * @param source + * @param context + * @return + */ + public XMLStreamReader transform(XMLDocument source, TransformationContext context) { + try { + HelperContext helperContext = SDOContextHelper.getHelperContext(context); + XMLStreamHelper streamHelper = SDOUtil.createXMLStreamHelper(helperContext.getTypeHelper()); + return streamHelper.createXMLStreamReader(source); + } catch (XMLStreamException e) { + throw new TransformationException(e); + } + } + + public Class getSourceType() { + return XMLDocument.class; + } + + public Class getTargetType() { + return XMLStreamReader.class; + } + + public int getWeight() { + return 10; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/XMLStreamReader2DataObject.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/XMLStreamReader2DataObject.java new file mode 100755 index 0000000000..8797ed1f28 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/XMLStreamReader2DataObject.java @@ -0,0 +1,64 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding.sdo; + +import javax.xml.stream.XMLStreamConstants; +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; +import org.apache.tuscany.sdo.helper.XMLStreamHelper; +import org.apache.tuscany.sdo.util.SDOUtil; + +import commonj.sdo.DataObject; +import commonj.sdo.helper.HelperContext; + +public class XMLStreamReader2DataObject extends BaseTransformer implements + PullTransformer { + + public DataObject transform(XMLStreamReader source, TransformationContext context) { + try { + HelperContext helperContext = SDOContextHelper.getHelperContext(context); + XMLStreamHelper streamHelper = SDOUtil.createXMLStreamHelper(helperContext.getTypeHelper()); + // The XMLStreamHelper requires that the reader is posistioned at + // START_ELEMENT + while (source.getEventType() != XMLStreamConstants.START_ELEMENT && source.hasNext()) { + source.next(); + } + return streamHelper.loadObject(source); + } catch (Exception e) { + throw new TransformationException(e); + } + } + + public Class getTargetType() { + return DataObject.class; + } + + public Class getSourceType() { + return XMLStreamReader.class; + } + + public int getWeight() { + return 15; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/XMLStreamReader2XMLDocument.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/XMLStreamReader2XMLDocument.java new file mode 100755 index 0000000000..759da7c4ab --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/XMLStreamReader2XMLDocument.java @@ -0,0 +1,59 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding.sdo; + +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; +import org.apache.tuscany.sdo.helper.XMLStreamHelper; +import org.apache.tuscany.sdo.util.SDOUtil; + + +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.XMLDocument; + +public class XMLStreamReader2XMLDocument extends BaseTransformer implements + PullTransformer { + + public XMLDocument transform(XMLStreamReader source, TransformationContext context) { + try { + HelperContext helperContext = SDOContextHelper.getHelperContext(context); + XMLStreamHelper streamHelper = SDOUtil.createXMLStreamHelper(helperContext.getTypeHelper()); + return streamHelper.load(source); + } catch (Exception e) { + throw new TransformationException(e); + } + } + + public Class getTargetType() { + return XMLDocument.class; + } + + public Class getSourceType() { + return XMLStreamReader.class; + } + + public int getWeight() { + return 15; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/api/HelperContext.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/api/HelperContext.java new file mode 100644 index 0000000000..9b6beead14 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/api/HelperContext.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding.sdo.api; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +/** + * This annotation can be used by component implementation class to receive the + * SDO HelperContext. + * + * @version $Rev$ $Date$ + */ +@Target({METHOD, FIELD}) +@Retention(RUNTIME) +public @interface HelperContext { +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/module/SDODataBindingModuleActivator.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/module/SDODataBindingModuleActivator.java new file mode 100644 index 0000000000..4f6caa6ec0 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/main/java/org/apache/tuscany/sca/databinding/sdo/module/SDODataBindingModuleActivator.java @@ -0,0 +1,80 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.databinding.sdo.module; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.core.ExtensionPointRegistry; +import org.apache.tuscany.sca.core.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.core.ModuleActivator; +import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint; +import org.apache.tuscany.sca.databinding.TransformerExtensionPoint; +import org.apache.tuscany.sca.databinding.sdo.DataObject2String; +import org.apache.tuscany.sca.databinding.sdo.DataObject2XMLStreamReader; +import org.apache.tuscany.sca.databinding.sdo.HelperContextProcessor; +import org.apache.tuscany.sca.databinding.sdo.HelperContextRegistry; +import org.apache.tuscany.sca.databinding.sdo.HelperContextRegistryImpl; +import org.apache.tuscany.sca.databinding.sdo.ImportSDOProcessor; +import org.apache.tuscany.sca.databinding.sdo.SDODataBinding; +import org.apache.tuscany.sca.databinding.sdo.String2DataObject; +import org.apache.tuscany.sca.databinding.sdo.XMLDocument2String; +import org.apache.tuscany.sca.databinding.sdo.XMLDocument2XMLStreamReader; +import org.apache.tuscany.sca.databinding.sdo.XMLStreamReader2DataObject; +import org.apache.tuscany.sca.databinding.sdo.XMLStreamReader2XMLDocument; +import org.apache.tuscany.sca.implementation.java.introspect.JavaClassIntrospectorExtensionPoint; + +/** + * @version $Rev$ $Date$ + */ +public class SDODataBindingModuleActivator implements ModuleActivator { + + public Object[] getExtensionPoints() { + return null; + } + + public void start(ExtensionPointRegistry registry) { + ModelFactoryExtensionPoint factories = registry.getExtensionPoint(ModelFactoryExtensionPoint.class); + AssemblyFactory assemblyFactory = factories.getFactory(AssemblyFactory.class); + + DataBindingExtensionPoint dataBindings = registry.getExtensionPoint(DataBindingExtensionPoint.class); + dataBindings.addDataBinding(new SDODataBinding()); + + StAXArtifactProcessorExtensionPoint processors = registry.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); + HelperContextRegistry contextRegistry = new HelperContextRegistryImpl(); + processors.addArtifactProcessor(new ImportSDOProcessor(contextRegistry)); + + TransformerExtensionPoint transformers = registry.getExtensionPoint(TransformerExtensionPoint.class); + transformers.addTransformer(new DataObject2String()); + transformers.addTransformer(new DataObject2XMLStreamReader()); + transformers.addTransformer(new XMLDocument2String()); + transformers.addTransformer(new String2DataObject()); + transformers.addTransformer(new XMLDocument2XMLStreamReader()); + transformers.addTransformer(new XMLStreamReader2DataObject()); + transformers.addTransformer(new XMLStreamReader2XMLDocument()); + + JavaClassIntrospectorExtensionPoint introspectors = registry.getExtensionPoint(JavaClassIntrospectorExtensionPoint.class); + introspectors.addClassVisitor(new HelperContextProcessor(assemblyFactory, contextRegistry)); + + } + + public void stop(ExtensionPointRegistry registry) { + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator new file mode 100644 index 0000000000..b39b5ae567 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator @@ -0,0 +1,18 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# Implementation class for the ExtensionActivator +org.apache.tuscany.sca.databinding.sdo.module.SDODataBindingModuleActivator diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/test/java/com/example/stock/sdo/fault/InvalidSymbolFault_Exception.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/test/java/com/example/stock/sdo/fault/InvalidSymbolFault_Exception.java new file mode 100644 index 0000000000..8c4f243df5 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/test/java/com/example/stock/sdo/fault/InvalidSymbolFault_Exception.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 com.example.stock.sdo.fault; + +import javax.xml.namespace.QName; + +import com.example.stock.sdo.InvalidSymbolFault; + +/** + * Hand-crafted java exception for SDO fault + * + */ +public class InvalidSymbolFault_Exception extends Exception { + /** + * Generated QName for the fault element + */ + public static final QName FAULT_ELEMENT = new QName("http://www.example.com/stock", "InvalidSymbolFault"); + /** + * Java type that goes as soapenv:Fault detail element. + */ + private InvalidSymbolFault faultInfo; + + /** + * @param faultInfo + * @param message + */ + public InvalidSymbolFault_Exception(String message, InvalidSymbolFault faultInfo) { + super(message); + this.faultInfo = faultInfo; + } + + /** + * @param faultInfo + * @param message + * @param cause + */ + public InvalidSymbolFault_Exception(String message, InvalidSymbolFault faultInfo, Throwable cause) { + super(message, cause); + this.faultInfo = faultInfo; + } + + /** + * @return returns fault bean: + * org.apache.tuscany.sca.test.exceptions.impl.jaxb.InvalidSymbolFault + */ + public InvalidSymbolFault getFaultInfo() { + return faultInfo; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/DataObject2StringTestCase.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/DataObject2StringTestCase.java new file mode 100644 index 0000000000..3665434cee --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/DataObject2StringTestCase.java @@ -0,0 +1,64 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.databinding.sdo; + +import junit.framework.Assert; + +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; +import org.apache.tuscany.sca.interfacedef.util.XMLType; + +import com.example.ipo.sdo.PurchaseOrderType; +import commonj.sdo.DataObject; + +/** + * + */ +public class DataObject2StringTestCase extends SDOTransformerTestCaseBase { + @Override + protected DataType getSourceDataType() { + return new DataTypeImpl(binding, PurchaseOrderType.class, new XMLType(ORDER_QNAME, null)); + } + + @Override + protected DataType getTargetDataType() { + return new DataTypeImpl>(String.class, String.class); + } + + public final void testTransform() { + String xml = new DataObject2String().transform(dataObject, context); + Assert.assertTrue(xml.indexOf("San Jose") != -1); + DataObject po = new String2DataObject().transform(xml, reversedContext); + Assert.assertTrue(po instanceof PurchaseOrderType); + PurchaseOrderType orderType = (PurchaseOrderType)po; + Assert.assertEquals("San Jose", orderType.getBillTo().getCity()); + } + + public final void testXML() { + String xml = + ""; + DataObject dataObject = new String2DataObject().transform(xml, reversedContext); + context.setSourceDataType(new DataTypeImpl(DataObject.class.getName(), DataObject.class, null)); + xml = new DataObject2String().transform(dataObject, context); + Assert.assertTrue(xml.contains("xsi:type=\"ipo:USAddress\"")); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/DataObject2XMLStreamReaderTestCase.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/DataObject2XMLStreamReaderTestCase.java new file mode 100644 index 0000000000..369912f115 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/DataObject2XMLStreamReaderTestCase.java @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.databinding.sdo; + +import javax.xml.stream.XMLStreamConstants; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; +import org.apache.tuscany.sca.interfacedef.util.XMLType; + +import com.example.ipo.sdo.PurchaseOrderType; + +/** + * + */ +public class DataObject2XMLStreamReaderTestCase extends SDOTransformerTestCaseBase { + + @Override + protected DataType getSourceDataType() { + return new DataTypeImpl(binding, PurchaseOrderType.class, new XMLType(ORDER_QNAME, null)); + } + + @Override + protected DataType getTargetDataType() { + return new DataTypeImpl>(XMLStreamReader.class, XMLStreamReader.class); + } + + public final void testTransform() throws XMLStreamException { + XMLStreamReader reader = new DataObject2XMLStreamReader().transform(dataObject, context); + while (reader.hasNext()) { + int event = reader.next(); + if (event == XMLStreamConstants.START_ELEMENT) { + break; + } + } + new XMLStreamReader2DataObject().transform(reader, reversedContext); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/HelperContextProcessorTestCase.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/HelperContextProcessorTestCase.java new file mode 100644 index 0000000000..c6fc6813e0 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/HelperContextProcessorTestCase.java @@ -0,0 +1,83 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.databinding.sdo; + +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.net.URI; + +import javax.xml.stream.XMLInputFactory; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory; +import org.apache.tuscany.sca.implementation.java.DefaultJavaImplementationFactory; +import org.apache.tuscany.sca.implementation.java.JavaImplementation; +import org.apache.tuscany.sca.implementation.java.JavaImplementationFactory; +import org.apache.tuscany.sca.implementation.java.impl.JavaResourceImpl; + +import commonj.sdo.helper.HelperContext; + +/** + * @version $Rev$ $Date$ + */ +public class HelperContextProcessorTestCase extends TestCase { + + @SuppressWarnings("unchecked") + public void testProcessor() throws Exception { + HelperContextRegistry registry = new HelperContextRegistryImpl(); + HelperContextProcessor processor = new HelperContextProcessor(new DefaultAssemblyFactory(), registry); + URI id = URI.create("/composite1/"); + XMLInputFactory xmlFactory = XMLInputFactory.newInstance(); + + AssemblyFactory assemblyFactory = new DefaultAssemblyFactory(); + JavaImplementationFactory javaImplementationFactory = new DefaultJavaImplementationFactory(); + JavaImplementation componentType = javaImplementationFactory.createJavaImplementation(); + componentType.setJavaClass(FooImpl.class); + for (Field f : FooImpl.class.getDeclaredFields()) { + processor.visitField(f, componentType); + + } + for (Method m : FooImpl.class.getMethods()) { + processor.visitMethod(m, componentType); + } + + JavaResourceImpl r1 = (JavaResourceImpl)componentType.getResources().get("context"); + assertNotNull(r1); + JavaResourceImpl r2 = (JavaResourceImpl)componentType.getResources().get("context2"); + assertNotNull(r2); +// HelperContext c1 = (HelperContext)r1.getObjectFactory().getInstance(); +// HelperContext c2 = (HelperContext)r2.getObjectFactory().getInstance(); +// assertSame(c1, c2); + } + + private static class FooImpl { + @org.apache.tuscany.sca.databinding.sdo.api.HelperContext + protected HelperContext context2; + + private HelperContext context; + + @org.apache.tuscany.sca.databinding.sdo.api.HelperContext + public void setContext(HelperContext context1) { + this.context = context1; + } + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/ImportSDOProcessorTestCase.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/ImportSDOProcessorTestCase.java new file mode 100755 index 0000000000..cd7a02cb88 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/ImportSDOProcessorTestCase.java @@ -0,0 +1,85 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding.sdo; + +import java.io.StringReader; +import java.net.URI; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +import junit.framework.TestCase; + +import com.example.ipo.sdo.SdoFactory; + +/** + * @version $Rev$ $Date$ + */ +public class ImportSDOProcessorTestCase extends TestCase { + private static boolean inited; + + private ImportSDOProcessor loader; + private XMLInputFactory xmlFactory; + + public void testMinimal() throws Exception { + String xml = ""; + XMLStreamReader reader = getReader(xml); + assertTrue(loader.read(reader) instanceof ImportSDO); + } + + public void testLocation() throws Exception { + String xml = ""; + XMLStreamReader reader = getReader(xml); + assertTrue(loader.read(reader) instanceof ImportSDO); + } + + public void testFactory() throws Exception { + String xml = ""; + XMLStreamReader reader = getReader(xml); + assertFalse(inited); + ImportSDO importSDO = loader.read(reader); + assertNotNull(importSDO); + loader.resolve(importSDO, new TestModelResolver(getClass().getClassLoader())); + assertTrue(inited); + } + + protected void setUp() throws Exception { + super.setUp(); + URI id = URI.create("/composite1/"); + loader = new ImportSDOProcessor(new HelperContextRegistryImpl()); + xmlFactory = XMLInputFactory.newInstance(); + } + + protected XMLStreamReader getReader(String xml) throws XMLStreamException { + XMLStreamReader reader = xmlFactory.createXMLStreamReader(new StringReader(xml)); + reader.next(); + return reader; + } + + public static class MockFactory { + public static final Object INSTANCE = SdoFactory.INSTANCE; + + static { + ImportSDOProcessorTestCase.inited = true; + } + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDODataBindingTestCase.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDODataBindingTestCase.java new file mode 100644 index 0000000000..17e4901cc2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDODataBindingTestCase.java @@ -0,0 +1,110 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.databinding.sdo; + +import javax.xml.namespace.QName; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; +import org.apache.tuscany.sca.interfacedef.util.XMLType; + +import com.example.ipo.sdo.PurchaseOrderType; +import com.example.ipo.sdo.SdoFactory; +import com.example.ipo.sdo.USAddress; +import commonj.sdo.DataObject; +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.XMLDocument; +import commonj.sdo.impl.HelperProvider; + +/** + * + */ +public class SDODataBindingTestCase extends TestCase { + protected static final QName ORDER_QNAME = new QName("http://www.example.com/IPO", "purchaseOrder"); + private SDODataBinding binding; + private HelperContext context; + + /** + * @see junit.framework.TestCase#setUp() + */ + protected void setUp() throws Exception { + super.setUp(); + binding = new SDODataBinding(); + context = HelperProvider.getDefaultContext(); + SdoFactory.INSTANCE.register(context); + } + + public final void testIntrospect() { + DataType dataType = new DataTypeImpl(DataObject.class, null); + boolean yes = binding.introspect(dataType, null); + assertTrue(yes); + assertTrue(dataType.getDataBinding().equals(binding.getName())); + assertTrue(dataType.getPhysical() == DataObject.class && dataType.getLogical() == XMLType.UNKNOWN); + dataType = new DataTypeImpl(PurchaseOrderType.class, null); + yes = binding.introspect(dataType, null); + assertTrue(yes); + assertEquals(PurchaseOrderType.class, dataType.getPhysical()); + assertEquals(new QName("http://www.example.com/IPO", "PurchaseOrderType"), ((XMLType)dataType.getLogical()) + .getTypeName()); + dataType = new DataTypeImpl(USAddress.class, null); + yes = binding.introspect(dataType, null); + assertTrue(yes); + assertEquals(USAddress.class, dataType.getPhysical()); + assertEquals(new QName("http://www.example.com/IPO", "USAddress"), ((XMLType)dataType.getLogical()) + .getTypeName()); + } + + public final void testCopyRoot() { + PurchaseOrderType po = SdoFactory.INSTANCE.createPurchaseOrderType(); + po.setComment("Comment"); + Object copy = binding.copy(po); + assertTrue(copy instanceof PurchaseOrderType); + assertTrue(po != copy); + assertTrue(context.getEqualityHelper().equal((DataObject)po, (DataObject)copy)); + assertEquals("Comment", ((PurchaseOrderType)copy).getComment()); + } + + public final void testCopyNonRoot() { + USAddress address = SdoFactory.INSTANCE.createUSAddress(); + address.setCity("San Jose"); + Object copy = binding.copy(address); + assertTrue(copy instanceof USAddress); + assertTrue(address != copy); + assertTrue(context.getEqualityHelper().equal((DataObject)address, (DataObject)copy)); + assertEquals("San Jose", ((USAddress)copy).getCity()); + } + + public final void testCopyXMLDocument() { + PurchaseOrderType po = SdoFactory.INSTANCE.createPurchaseOrderType(); + po.setComment("Comment"); + XMLDocument doc = + context.getXMLHelper().createDocument((DataObject)po, + ORDER_QNAME.getNamespaceURI(), + ORDER_QNAME.getLocalPart()); + Object copy = binding.copy(doc); + assertTrue(copy instanceof XMLDocument); + XMLDocument docCopy = (XMLDocument)copy; + assertTrue(doc != copy); + assertTrue(context.getEqualityHelper().equal((DataObject)po, docCopy.getRootObject())); + assertEquals("Comment", ((PurchaseOrderType)docCopy.getRootObject()).getComment()); + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDOExceptionHandlerTestCase.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDOExceptionHandlerTestCase.java new file mode 100644 index 0000000000..f8373cfd1c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDOExceptionHandlerTestCase.java @@ -0,0 +1,82 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.databinding.sdo; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; +import org.apache.tuscany.sca.interfacedef.util.XMLType; + +import com.example.stock.sdo.InvalidSymbolFault; +import com.example.stock.sdo.StockFactory; +import com.example.stock.sdo.fault.InvalidSymbolFault_Exception; +import commonj.sdo.impl.HelperProvider; + +/** + * Test case for SDOExceptionHandler + */ +public class SDOExceptionHandlerTestCase extends TestCase { + // FIXME: Tuscany SDO impl uses _._type for anonymouse type, by the SDO + // spec, it should be same as the + // enclosing element/attribute name + private SDOExceptionHandler handler; + + /** + * @see junit.framework.TestCase#setUp() + */ + protected void setUp() throws Exception { + super.setUp(); + this.handler = new SDOExceptionHandler(); + StockFactory.INSTANCE.register(HelperProvider.getDefaultContext()); + } + + public void testGetFaultType() { + DataType execType = new DataTypeImpl(InvalidSymbolFault_Exception.class, XMLType.UNKNOWN); + DataType dataType = handler.getFaultType(execType); + assertEquals(InvalidSymbolFault.class, dataType.getPhysical()); + assertEquals(InvalidSymbolFault_Exception.FAULT_ELEMENT, ((XMLType) dataType.getLogical()).getElementName()); + assertEquals(SDODataBinding.NAME, dataType.getDataBinding()); + } + + public void testCreate() { + DataType execType = new DataTypeImpl(InvalidSymbolFault_Exception.class, XMLType.UNKNOWN); + DataType faultType = handler.getFaultType(execType); + InvalidSymbolFault fault = StockFactory.INSTANCE.createInvalidSymbolFault(); + fault.setMessage("ABC"); + fault.setSymbol("IBM0"); + DataType exType = new DataTypeImpl(InvalidSymbolFault_Exception.class, faultType); + Exception ex = handler.createException(exType, "Invalid symbol", fault, null); + assertTrue(ex instanceof InvalidSymbolFault_Exception); + InvalidSymbolFault_Exception exception = (InvalidSymbolFault_Exception)ex; + assertEquals("Invalid symbol", exception.getMessage()); + assertSame(fault, exception.getFaultInfo()); + } + + public void testGetFaultInfo() { + InvalidSymbolFault fault = StockFactory.INSTANCE.createInvalidSymbolFault(); + fault.setMessage("ABC"); + fault.setSymbol("IBM0"); + InvalidSymbolFault_Exception exception = new InvalidSymbolFault_Exception("Invalid symbol", fault); + Object faultInfo = handler.getFaultInfo(exception); + assertSame(fault, faultInfo); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDOTransformerTestCaseBase.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDOTransformerTestCaseBase.java new file mode 100644 index 0000000000..ff1ac633a8 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDOTransformerTestCaseBase.java @@ -0,0 +1,79 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.databinding.sdo; + +import javax.xml.namespace.QName; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.impl.TransformationContextImpl; +import org.apache.tuscany.sca.interfacedef.DataType; + +import com.example.ipo.sdo.PurchaseOrderType; +import com.example.ipo.sdo.SdoFactory; +import com.example.ipo.sdo.USAddress; +import commonj.sdo.DataObject; +import commonj.sdo.helper.HelperContext; +import commonj.sdo.impl.HelperProvider; + +/** + * The base class for SDO-related test cases + */ +public abstract class SDOTransformerTestCaseBase extends TestCase { + protected static final QName ORDER_QNAME = new QName("http://www.example.com/IPO", "purchaseOrder"); + + protected HelperContext helperContext; + protected String binding = DataObject.class.getName(); + protected TransformationContext context; + protected TransformationContext reversedContext; + protected DataObject dataObject; + + /** + * @see junit.framework.TestCase#setUp() + */ + protected void setUp() throws Exception { + super.setUp(); + helperContext = HelperProvider.getDefaultContext(); + SdoFactory.INSTANCE.register(helperContext); + + context = new TransformationContextImpl(); + context.setSourceDataType(getSourceDataType()); + context.setTargetDataType(getTargetDataType()); + + reversedContext = new TransformationContextImpl(); + reversedContext.setSourceDataType(getTargetDataType()); + reversedContext.setTargetDataType(getSourceDataType()); + + PurchaseOrderType po = SdoFactory.INSTANCE.createPurchaseOrderType(); + USAddress address = SdoFactory.INSTANCE.createUSAddress(); + address.setCity("San Jose"); + address.setStreet("123 ABC St"); + address.setState("CA"); + address.setStreet("95131"); + po.setBillTo(address); + dataObject = (DataObject) po; + } + + protected abstract DataType getSourceDataType(); + + protected abstract DataType getTargetDataType(); + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDOWrapperHandlerTestCase.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDOWrapperHandlerTestCase.java new file mode 100644 index 0000000000..ed57e81ee7 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/SDOWrapperHandlerTestCase.java @@ -0,0 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding.sdo; + +import java.util.List; + +import junit.framework.TestCase; + +import org.apache.tuscany.sdo.util.SDOUtil; + + +import commonj.sdo.helper.HelperContext; +import commonj.sdo.helper.XMLDocument; +import commonj.sdo.helper.XMLHelper; +import commonj.sdo.helper.XSDHelper; + +/** + * @version $Rev$ $Date$ + */ +public class SDOWrapperHandlerTestCase extends TestCase { + private HelperContext context; + private SDOWrapperHandler handler; + + public void setUp() throws Exception { + context = SDOUtil.createHelperContext(); + handler = new SDOWrapperHandler(); + } + + public void testWrapperAnyType() throws Exception { + XMLHelper xmlHelper = context.getXMLHelper(); + XMLDocument document = xmlHelper.load(getClass().getResourceAsStream("/wrapper.xml")); + List children = handler.getChildren(document); + assertEquals(5, children.size()); + } + + public void testWrapper() throws Exception { + XSDHelper xsdHelper = context.getXSDHelper(); + xsdHelper.define(getClass().getResourceAsStream("/wrapper.xsd"), null); + XMLHelper xmlHelper = context.getXMLHelper(); + XMLDocument document = xmlHelper.load(getClass().getResourceAsStream("/wrapper.xml")); + List children = handler.getChildren(document); + assertEquals(5, children.size()); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/TestModelResolver.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/TestModelResolver.java new file mode 100644 index 0000000000..f1caa4e8a7 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/TestModelResolver.java @@ -0,0 +1,63 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.databinding.sdo; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; + + +/** + * A default implementation of an artifact resolver, based on a map. + * + * @version $Rev$ $Date$ + */ +public class TestModelResolver implements ModelResolver { + private static final long serialVersionUID = -7826976465762296634L; + + private Map map = new HashMap(); + + public TestModelResolver(ClassLoader 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 { + + // Return the unresolved object + return unresolved; + } + } + + public void addModel(Object resolved) { + map.put(resolved, resolved); + } + + public Object removeModel(Object resolved) { + return map.remove(resolved); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/XMLDocument2XMLStreamReaderTestCase.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/XMLDocument2XMLStreamReaderTestCase.java new file mode 100644 index 0000000000..78bc62eb3a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/test/java/org/apache/tuscany/sca/databinding/sdo/XMLDocument2XMLStreamReaderTestCase.java @@ -0,0 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.databinding.sdo; + +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; + +import junit.framework.Assert; + +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; +import org.apache.tuscany.sca.interfacedef.util.XMLType; + +import com.example.ipo.sdo.PurchaseOrderType; +import commonj.sdo.helper.XMLDocument; + +/** + * + */ +public class XMLDocument2XMLStreamReaderTestCase extends SDOTransformerTestCaseBase { + + @Override + protected DataType getSourceDataType() { + return new DataTypeImpl(XMLDocument.class.getName(), XMLDocument.class, new XMLType(ORDER_QNAME, null)); + } + + @Override + protected DataType getTargetDataType() { + return new DataTypeImpl>(XMLStreamReader.class, XMLStreamReader.class); + } + + public final void testTransform() throws XMLStreamException { + XMLDocument document = + helperContext.getXMLHelper().createDocument(dataObject, + ORDER_QNAME.getNamespaceURI(), + ORDER_QNAME.getLocalPart()); + XMLStreamReader reader = new XMLDocument2XMLStreamReader().transform(document, context); + XMLDocument document2 = new XMLStreamReader2XMLDocument().transform(reader, reversedContext); + Assert.assertEquals(ORDER_QNAME.getNamespaceURI(), document2.getRootElementURI()); + Assert.assertEquals(ORDER_QNAME.getLocalPart(), document2.getRootElementName()); + Assert.assertTrue(document2.getRootObject() instanceof PurchaseOrderType); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/test/resources/ipo.xsd b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/test/resources/ipo.xsd new file mode 100755 index 0000000000..241ec15d36 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/test/resources/ipo.xsd @@ -0,0 +1,136 @@ + + + + + + International Purchase order schema for Example.com + Copyright 2000 Example.com. All rights reserved. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/test/resources/model/sca-core.xsd b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/test/resources/model/sca-core.xsd new file mode 100755 index 0000000000..56c6977254 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/test/resources/model/sca-core.xsd @@ -0,0 +1,233 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/test/resources/model/sca-implementation-mock.xsd b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/test/resources/model/sca-implementation-mock.xsd new file mode 100755 index 0000000000..bbaf58f00c --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/test/resources/model/sca-implementation-mock.xsd @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/test/resources/stock.xsd b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/test/resources/stock.xsd new file mode 100644 index 0000000000..a0a6717371 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/test/resources/stock.xsd @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/test/resources/wrapper.xml b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/test/resources/wrapper.xml new file mode 100644 index 0000000000..2526629409 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/test/resources/wrapper.xml @@ -0,0 +1,27 @@ + + + + message + symbol + message1 + symbol1 + symbol2 + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/test/resources/wrapper.xsd b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/test/resources/wrapper.xsd new file mode 100644 index 0000000000..ea4dc5f7f3 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding-sdo/src/test/resources/wrapper.xsd @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding/.checkstyle b/sca-java-1.x/branches/sca-java-0.91/modules/databinding/.checkstyle new file mode 100644 index 0000000000..c7b30ffd5e --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding/.checkstyle @@ -0,0 +1,25 @@ + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding/.pmd b/sca-java-1.x/branches/sca-java-0.91/modules/databinding/.pmd new file mode 100644 index 0000000000..2db10d6a6a --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding/.pmd @@ -0,0 +1,20 @@ + + +truefalse \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding/.ruleset b/sca-java-1.x/branches/sca-java-0.91/modules/databinding/.ruleset new file mode 100644 index 0000000000..ba9b5ce886 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding/.ruleset @@ -0,0 +1,190 @@ + + + + PMD Plugin preferences rule set + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding/DISCLAIMER b/sca-java-1.x/branches/sca-java-0.91/modules/databinding/DISCLAIMER new file mode 100644 index 0000000000..d68a410903 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding/DISCLAIMER @@ -0,0 +1,8 @@ +Apache Tuscany is an effort undergoing incubation at The Apache Software +Foundation (ASF), sponsored by the Apache Web Services PMC. Incubation is +required of all newly accepted projects until a further review indicates that +the infrastructure, communications, and decision making process have stabilized +in a manner consistent with other successful ASF projects. While incubation +status is not necessarily a reflection of the completeness or stability of the +code, it does indicate that the project has yet to be fully endorsed by the ASF. + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding/LICENSE b/sca-java-1.x/branches/sca-java-0.91/modules/databinding/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding/NOTICE b/sca-java-1.x/branches/sca-java-0.91/modules/databinding/NOTICE new file mode 100644 index 0000000000..94481d6cfa --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2007 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding/pom.xml b/sca-java-1.x/branches/sca-java-0.91/modules/databinding/pom.xml new file mode 100644 index 0000000000..a171204fa2 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding/pom.xml @@ -0,0 +1,51 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 0.91-incubating-SNAPSHOT + ../pom.xml + + tuscany-databinding + Apache Tuscany DataBinding Framework + + + + org.apache.tuscany.sca + tuscany-interface + 0.91-incubating-SNAPSHOT + + + + stax + stax-api + 1.0.1 + + + + org.codehaus.woodstox + wstx-asl + 3.2.0 + runtime + + + diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DataBinding.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DataBinding.java new file mode 100644 index 0000000000..e8f5317a25 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DataBinding.java @@ -0,0 +1,99 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.databinding; + +import java.lang.annotation.Annotation; + +import org.apache.tuscany.sca.interfacedef.DataType; + +/** + * DataBinding represents a data representation, for example, SDO, JAXB and AXIOM + */ +public interface DataBinding { + /** + * A special databinding for input message of an operation + */ + String IDL_INPUT = "idl:input"; + /** + * A special databinding for output message of an operation + */ + String IDL_OUTPUT = "idl:output"; + /** + * A special databinding for fault message of an operation + */ + String IDL_FAULT = "idl:fault"; + /** + * The name of a databinding should be case-insensitive and unique + * + * @return The name of the databinding + */ + String getName(); + + /** + * Get the aliases for the databinding + * + * @return An array of aliases + */ + String[] getAliases(); + + /** + * Introspect and populate information to a DataType model + * + * @param javaType The java class or interface to be introspected + * @param annotations The java annotations + * @return true if the databinding has recognized the given data type + */ + boolean introspect(DataType dataType, Annotation[] annotations); + + /** + * Introspect the data to figure out the corresponding data type + * + * @param value The object to be checked + * @return The DataType or null if the java type is not supported by this databinding + */ + DataType introspect(Object value); + + /** + * Provide a WrapperHandler for this databinding + * @return A wrapper handler which can handle wrapping/wrapping for this databinding + */ + WrapperHandler getWrapperHandler(); + + /** + * Make a copy of the object for "pass-by-value" semantics + * @param source object to copy + * @return copy of the object passed in as argument + */ + Object copy(Object object); + + /** + * Get the type mapper for simple types + * @return The databinding-specific simple type mapper + */ + SimpleTypeMapper getSimpleTypeMapper(); + + /** + * Get the handler that can handle exceptions/faults in the + * databinding-specific way + * + * @return An instance of the exception handler + */ + ExceptionHandler getExceptionHandler(); +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DataBindingExtensionPoint.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DataBindingExtensionPoint.java new file mode 100644 index 0000000000..471b4b715f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DataBindingExtensionPoint.java @@ -0,0 +1,71 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding; + +import java.lang.annotation.Annotation; + +import org.apache.tuscany.sca.interfacedef.DataType; + +/** + * An extension point for data binding extensions. + */ +public interface DataBindingExtensionPoint { + + /** + * Register a data binding + * + * @param dataBinding + */ + void addDataBinding(DataBinding dataBinding); + + /** + * Look up a data binding by id + * + * @param id The name of the databinding + * @return The databinding + */ + DataBinding getDataBinding(String id); + + /** + * Unregister a data binding + * + * @param id + * @return The unregistered databinding + */ + DataBinding removeDataBinding(String id); + + /** + * Introspect the java class to figure out what DataType supports it + * + * @param DataType The initial data type + * @param annotations The java annotations + * @return A DataType representing the java type or null if no databinding + * recognizes the java type + */ + boolean introspectType(DataType dataType, Annotation[] annotations); + + /** + * Introspect the value to figure out the corresponding DataType + * + * @param value The object value + * @return A DataType representing the value or null if no databinding + * recognizes the value + */ + DataType introspectType(Object value); +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DataPipe.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DataPipe.java new file mode 100755 index 0000000000..a6f747996d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DataPipe.java @@ -0,0 +1,44 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding; + +/** + * Data pipe allows a data source pushes data into its sink and pipe the data into its result + * + * @param The data binding type of the sink + * @param The data binding type of the result + */ +public interface DataPipe extends Transformer { + + /** + * Returns a sink (for example, java.io.OutputStream, java.io.Writer or org.xml.sax.ContentHandler) to receive data + * pushed by the source + * + * @return The sink to consume data + */ + S getSink(); + + /** + * Returns the data populated by the sink + * + * @return + */ + R getResult(); + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DefaultDataBindingExtensionPoint.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DefaultDataBindingExtensionPoint.java new file mode 100644 index 0000000000..cce57cb2ae --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DefaultDataBindingExtensionPoint.java @@ -0,0 +1,116 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.databinding; + +import java.lang.annotation.Annotation; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +import org.apache.tuscany.sca.databinding.javabeans.JavaBeansDataBinding; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; + +/** + * The default implementation of a data binding extension point. + * + * @version $Rev$ $Date$ + */ +public class DefaultDataBindingExtensionPoint implements DataBindingExtensionPoint { + private final Map bindings = new HashMap(); + + public DataBinding getDataBinding(String id) { + if (id == null) { + return null; + } + return bindings.get(id.toLowerCase()); + } + + public void addDataBinding(DataBinding dataBinding) { + bindings.put(dataBinding.getName().toLowerCase(), dataBinding); + String[] aliases = dataBinding.getAliases(); + if (aliases != null) { + for (String alias : aliases) { + bindings.put(alias.toLowerCase(), dataBinding); + } + } + } + + public DataBinding removeDataBinding(String id) { + if (id == null) { + return null; + } + DataBinding dataBinding = bindings.remove(id.toLowerCase()); + if (dataBinding != null) { + String[] aliases = dataBinding.getAliases(); + if (aliases != null) { + for (String alias : aliases) { + bindings.remove(alias.toLowerCase()); + } + } + } + return dataBinding; + } + + private Set getDataBindings() { + return new HashSet(bindings.values()); + } + + public boolean introspectType(DataType dataType, Annotation[] annotations) { + for (DataBinding binding : getDataBindings()) { + // don't introspect for JavaBeansDatabinding as all javatypes will + // anyways match to its basetype + // which is java.lang.Object. Default to this only if no databinding + // results + if (!binding.getName().equals(JavaBeansDataBinding.NAME)) { + if (binding.introspect(dataType, annotations)) { + return true; + } + } + } + // FIXME: Should we honor the databinding from operation/interface + // level? + Class physical = dataType.getPhysical(); + if (physical == Object.class || Throwable.class.isAssignableFrom((Class)physical)) { + return false; + } + dataType.setDataBinding(JavaBeansDataBinding.NAME); + return false; + } + + public DataType introspectType(Object value) { + DataType dataType = null; + for (DataBinding binding : getDataBindings()) { + // don't introspect for JavaBeansDatabinding as all javatypes will + // anyways match to its basetype + // which is java.lang.Object. Default to this only if no databinding + // results + if (!binding.getName().equals(JavaBeansDataBinding.NAME)) { + dataType = binding.introspect(value); + } + if (dataType != null) { + return dataType; + } + } + return new DataTypeImpl(JavaBeansDataBinding.NAME, value.getClass(), value.getClass()); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DefaultTransformerExtensionPoint.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DefaultTransformerExtensionPoint.java new file mode 100755 index 0000000000..8c37ce2d89 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DefaultTransformerExtensionPoint.java @@ -0,0 +1,90 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.sca.databinding.impl.DirectedGraph; + +/** + * @version $Rev$ $Date$ + */ +public class DefaultTransformerExtensionPoint implements TransformerExtensionPoint { + private DataBindingExtensionPoint dataBindings; + + private final DirectedGraph graph = new DirectedGraph(); + + public DefaultTransformerExtensionPoint(DataBindingExtensionPoint dataBindings) { + this.dataBindings = dataBindings; + } + + public void addTransformer(String sourceType, String resultType, int weight, Transformer transformer) { + graph.addEdge(sourceType, resultType, transformer, weight); + } + + public void addTransformer(Transformer transformer) { + graph.addEdge(transformer.getSourceDataBinding(), + transformer.getTargetDataBinding(), + transformer, + transformer.getWeight()); + } + + public boolean removeTransformer(String sourceType, String resultType) { + return graph.removeEdge(sourceType, resultType); + } + + public Transformer getTransformer(String sourceType, String resultType) { + DirectedGraph.Edge edge = graph.getEdge(sourceType, resultType); + return (edge == null) ? null : edge.getValue(); + } + + public List getTransformerChain(String sourceType, String resultType) { + String source = normalize(sourceType); + String result = normalize(resultType); + List transformers = new ArrayList(); + DirectedGraph.Path path = graph.getShortestPath(source, result); + if (path == null) { + return null; + } + for (DirectedGraph.Edge edge : path.getEdges()) { + transformers.add(edge.getValue()); + } + return transformers; + } + + public String toString() { + return graph.toString(); + } + + /** + * Normalize the id to a name of a data binding as databindings may have aliases + * @param id + * @return + */ + private String normalize(String id) { + if (dataBindings != null) { + DataBinding dataBinding = dataBindings.getDataBinding(id); + return dataBinding == null ? id : dataBinding.getName(); + } else { + return id; + } + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/ExceptionHandler.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/ExceptionHandler.java new file mode 100644 index 0000000000..131e8a3114 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/ExceptionHandler.java @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.databinding; + +import org.apache.tuscany.sca.interfacedef.DataType; + +/** + * ExceptionHandler provides databinding-specific logic for exception handling + * + * @version $Rev$ $Date$ + */ +public interface ExceptionHandler { + /** + * Create an exception to wrap the fault data + * + * @param exceptionType The DataType for the exception + * @param message The error message + * @param faultInfo The databinding-specific fault data + * @param cause The protocol-specific error + * @return An instance of java exception to represent the fault + */ + Exception createException(DataType exceptionType, String message, Object faultInfo, Throwable cause); + + /** + * Retrieve the fault info from a java exception + * + * @param exception The databinding-specific java exception that represents + * the fault data + * @return The databinding-specific fault data + */ + Object getFaultInfo(Exception exception); + + /** + * Introspect an exception class to figure out the fault data type + * + * @param exceptionDataType The exception class + * @return The data type for the fault + */ + DataType getFaultType(DataType exceptionDataType); +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/Mediator.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/Mediator.java new file mode 100755 index 0000000000..168a1052b3 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/Mediator.java @@ -0,0 +1,67 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding; + +import java.util.Map; + +import org.apache.tuscany.sca.interfacedef.DataType; + +/** + * This interface will be used as a Tuscany system service to perform data mediations + * + * Mediate the data from one type to the other one + * + */ +public interface Mediator { + + /** + * Mediate the data from the source type to the target type + * @param source The data to be mediated + * @param sourceDataType Data type for the source data + * @param targetDataType Data type for the target data + * @param context + * @return + */ + Object mediate(Object source, DataType sourceDataType, DataType targetDataType, Map context); + /** + * Mediate the source data into the target which is a sink to receive the data + * @param source The data to be mediated + * @param target The sink to receive data + * @param sourceDataType Data type for the source data + * @param targetDataType Data type for the target data + */ + void mediate( + Object source, + Object target, + DataType sourceDataType, + DataType targetDataType, + Map context); + + /** + * Get the DataBindings used by this mediator. + * @return + */ + DataBindingExtensionPoint getDataBindings(); + + /** + * Get the Transformers used by this mediator. + * @return + */ + TransformerExtensionPoint getTransformers(); +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/PullTransformer.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/PullTransformer.java new file mode 100644 index 0000000000..feed87e45f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/PullTransformer.java @@ -0,0 +1,36 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding; + +/** + * PullTransformer transforms data from one binding format to the other one which can be directly consumed + * + * @param The source data type + * @param the target data type + */ +public interface PullTransformer extends Transformer { + /** + * Transform source data into the result type. + * + * @param source The source data + * @param context The context for the transformation + * @return The transformed result + */ + R transform(S source, TransformationContext context); +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/PushTransformer.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/PushTransformer.java new file mode 100644 index 0000000000..80e5e4f0a3 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/PushTransformer.java @@ -0,0 +1,34 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding; + +/** + * A transformer that pushes data from its source into the sink + * + * @param + * @param + */ +public interface PushTransformer extends Transformer { + /** + * @param source The source data + * @param sink The sink to receive the data + * @param context + */ + void transform(S source, R sink, TransformationContext context); +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/SimpleTypeMapper.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/SimpleTypeMapper.java new file mode 100644 index 0000000000..70ea431d57 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/SimpleTypeMapper.java @@ -0,0 +1,44 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.databinding; + +import javax.xml.namespace.QName; + +/** + * Type Mapper between XML schema simple data types and java objects + */ +public interface SimpleTypeMapper { + /** + * Parse the XML lexical representation into a java object + * @param simpleType The XSD simple type + * @param value the XML lexical representation + * @param context The context of the transformation + * @return A java object for the XML value + */ + Object toJavaObject(QName simpleType, String value, TransformationContext context); + /** + * Create the XML lexical representation for a java object + * @param simpleType The XSD simple type + * @param obj The java object + * @param context The context of the transformation + * @return The XML lexical representation + */ + String toXMLLiteral(QName simpleType, Object obj, TransformationContext context); +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/TransformationContext.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/TransformationContext.java new file mode 100755 index 0000000000..27818dc24f --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/TransformationContext.java @@ -0,0 +1,79 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding; + +import java.util.Map; + +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.Operation; + +/** + * Context for data transformation + * + */ +public interface TransformationContext { + + Operation getSourceOperation(); + void setSourceOperation(Operation sourceOperation); + Operation getTargetOperation(); + void setTargetOperation(Operation targetOperation); + + /** + * Get the source data type + * + * @return + */ + DataType getSourceDataType(); + + /** + * Get the target data type + * + * @return + */ + DataType getTargetDataType(); + + /** + * Set the source data type + * + * @param sourceDataType + */ + void setSourceDataType(DataType sourceDataType); + + /** + * Set the target data type + * + * @param targetDataType + */ + void setTargetDataType(DataType targetDataType); + + /** + * Get the classloader + * + * @return + */ + ClassLoader getClassLoader(); + + /** + * Get a map of metadata + * + * @return + */ + Map getMetadata(); + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/TransformationException.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/TransformationException.java new file mode 100755 index 0000000000..8d2b36482d --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/TransformationException.java @@ -0,0 +1,63 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding; + + +/** + * Reports problems during data transformation + */ +public class TransformationException extends RuntimeException { + + private static final long serialVersionUID = 7662385613693006428L; + private String sourceDataBinding; + private String targetDataBinding; + + public TransformationException() { + super(); + } + + public TransformationException(String message, Throwable cause) { + super(message, cause); + } + + public TransformationException(String message) { + super(message); + } + + public TransformationException(Throwable cause) { + super(cause); + } + + public String getSourceDataBinding() { + return sourceDataBinding; + } + + public void setSourceDataBinding(String sourceDataBinding) { + this.sourceDataBinding = sourceDataBinding; + } + + public String getTargetDataBinding() { + return targetDataBinding; + } + + public void setTargetDataBinding(String targetDataBinding) { + this.targetDataBinding = targetDataBinding; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/Transformer.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/Transformer.java new file mode 100755 index 0000000000..062f087a15 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/Transformer.java @@ -0,0 +1,49 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding; + +/** + * A transformer provides the data transformation from source type to target type. The cost of the transformation is + * modeled as weight. + */ +public interface Transformer { + /** + * Get the source type that this transformer transforms data from. The type is used as the key when the transformer + * is registered with TransformerRegistry. + * + * @return A key indentifying the source type + */ + String getSourceDataBinding(); + + /** + * Get the target type that this transformer transforms data into. The type is used as the key when the transformer + * is registered with TransformerRegistry. + * + * @return A key indentifying the target type + */ + String getTargetDataBinding(); + + /** + * Get the cost of the transformation. The weight can be used to choose the most efficient path if there are more + * than one available from the source to the target. + * + * @return An integer representing the cost of the transformation + */ + int getWeight(); +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/TransformerExtensionPoint.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/TransformerExtensionPoint.java new file mode 100755 index 0000000000..1abae06754 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/TransformerExtensionPoint.java @@ -0,0 +1,76 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding; + +import java.util.List; + +/** + * An extension point for data transformer extensions. + */ +public interface TransformerExtensionPoint { + + /** + * Register a transformer + * + * @param sourceDataBinding + * @param targetDataBinding + * @param weight + * @param transformer + */ + void addTransformer(String sourceDataBinding, + String targetDataBinding, + int weight, + Transformer transformer); + + /** + * Register a transformer + * + * @param transformer + */ + void addTransformer(Transformer transformer); + + /** + * Unregister a transformer + * + * @param sourceDataBinding + * @param targetDataBinding + * @return + */ + boolean removeTransformer(String sourceDataBinding, String targetDataBinding); + + /** + * Get the direct Transformer which can transform data from source type to + * result type + * + * @param sourceDataBinding + * @param targetDataBinding + * @return + */ + Transformer getTransformer(String sourceDataBinding, String targetDataBinding); + + /** + * Get the a chain of Transformers which can transform data from source type + * to result type + * + * @param sourceDataBinding + * @param targetDataBinding + * @return + */ + List getTransformerChain(String sourceDataBinding, String targetDataBinding); +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/WrapperHandler.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/WrapperHandler.java new file mode 100644 index 0000000000..a94e986755 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/WrapperHandler.java @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.databinding; + +import java.util.List; + +import org.apache.tuscany.sca.interfacedef.util.ElementInfo; + +/** + * A contract for transformers to deal with wrapping/unwrapping for WSDL wrapper style operations + */ +public interface WrapperHandler { + /** + * Create a wrapper element + * + * @param element The XSD element + * @param context The transformation context + * @return An object representing the wrapper element + */ + T create(ElementInfo element, TransformationContext context); + + /** + * Set child element for the wrapper + * + * @param wrapper The wrapper + * @param i The index + * @param childElement The XSD element + * @param value The value of the child + */ + void setChild(T wrapper, int i, ElementInfo childElement, Object value); + + /** + * Get a list of child elements from the wrapper + * @param wrapper + * @return child elements under the wrapper + */ + List getChildren(T wrapper); +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/annotation/DataBinding.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/annotation/DataBinding.java new file mode 100644 index 0000000000..1d0e117d34 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/annotation/DataBinding.java @@ -0,0 +1,44 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding.annotation; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.ElementType.TYPE; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +/** + * Used to demarcate expected data types for an operation + * + * @version $Rev$ $Date$ + */ +@Target({TYPE, METHOD}) +@Retention(RUNTIME) +public @interface DataBinding { + + /** + * Returns the unique name of the data binding + * @return the unique name of the data binding + */ + String value(); + boolean wrapperStyle() default false; + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/BaseDataBinding.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/BaseDataBinding.java new file mode 100644 index 0000000000..377984a1cc --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/BaseDataBinding.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.databinding.impl; + +import java.lang.annotation.Annotation; +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; + +import org.apache.tuscany.sca.databinding.DataBinding; +import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint; +import org.apache.tuscany.sca.databinding.ExceptionHandler; +import org.apache.tuscany.sca.databinding.SimpleTypeMapper; +import org.apache.tuscany.sca.databinding.WrapperHandler; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; + +/** + * Base Implementation of DataBinding + * + * @version $Rev$ $Date$ + */ +public abstract class BaseDataBinding implements DataBinding { + + protected DataBindingExtensionPoint registry; + + protected Class baseType; + + protected String name; + protected String[] aliases; + + /** + * Create a databinding with the base java type whose name will be used as + * the name of the databinding + * + * @param baseType The base java class or interface representing the + * databinding, for example, org.w3c.dom.Node + */ + protected BaseDataBinding(Class baseType) { + this(baseType.getName(), null, baseType); + } + + /** + * Create a databinding with the name and base java type + * + * @param name The name of the databinding + * @param baseType The base java class or interface representing the + * databinding, for example, org.w3c.dom.Node + */ + protected BaseDataBinding(String name, Class baseType) { + this(name, null, baseType); + } + + /** + * Create a databinding with the name and base java type + * + * @param name The name of the databinding + * @param aliases The aliases of the databinding + * @param baseType The base java class or interface representing the + * databinding, for example, org.w3c.dom.Node + */ + protected BaseDataBinding(String name, String[] aliases, Class baseType) { + this.name = name; + this.baseType = baseType; + this.aliases = aliases; + } + + public void setDataBindingRegistry(DataBindingExtensionPoint registry) { + this.registry = registry; + } + + public void init() { + registry.addDataBinding(this); + } + + @SuppressWarnings("unchecked") + public boolean introspect(DataType type, Annotation[] annotations) { + assert type != null; + Type physical = type.getPhysical(); + if (physical instanceof ParameterizedType) { + physical = ((ParameterizedType)physical).getRawType(); + } + if (physical instanceof Class) { + Class cls = (Class)physical; + if (baseType != null && baseType.isAssignableFrom(cls)) { + type.setDataBinding(getName()); + type.setLogical(baseType); + return true; + } + } + return false; + } + + public DataType introspect(Object value) { + if (value == null) { + return null; + } else { + DataType dataType = new DataTypeImpl(value.getClass(), value.getClass()); + if (introspect(dataType, null)) { + return dataType; + } else { + return null; + } + } + } + + public final String getName() { + return name; + } + + /** + * @see org.apache.tuscany.sca.databinding.DataBinding#getWrapperHandler() + */ + public WrapperHandler getWrapperHandler() { + return null; + } + + public ExceptionHandler getExceptionHandler() { + return null; + } + + public Object copy(Object object) { + return object; + } + + public SimpleTypeMapper getSimpleTypeMapper() { + return new SimpleTypeMapperImpl(); + } + + public String[] getAliases() { + return aliases; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/BaseTransformer.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/BaseTransformer.java new file mode 100644 index 0000000000..5d68324f31 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/BaseTransformer.java @@ -0,0 +1,62 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding.impl; + +import org.apache.tuscany.sca.databinding.Transformer; +import org.apache.tuscany.sca.databinding.TransformerExtensionPoint; + +/** + * Base Implementation of Transformer which provides the registration to the transformer registry + * + * @version $Rev$ $Date$ + */ +public abstract class BaseTransformer implements Transformer { + + protected TransformerExtensionPoint registry; + + protected BaseTransformer() { + super(); + } + + public void setTransformerRegistry(TransformerExtensionPoint registry) { + this.registry = registry; + } + + public void init() { + registry.addTransformer(this); + } + + protected abstract Class getSourceType(); + + protected abstract Class getTargetType(); + + public String getSourceDataBinding() { + return getSourceType().getName(); + } + + public String getTargetDataBinding() { + return getTargetType().getName(); + } + + public int getWeight() { + // default to 50 + return 50; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/DOMHelper.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/DOMHelper.java new file mode 100644 index 0000000000..2fe4cc44cf --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/DOMHelper.java @@ -0,0 +1,69 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding.impl; + +import javax.xml.namespace.QName; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; + +/** + * Helper for DOM + */ +public final class DOMHelper { + private static final DocumentBuilderFactory FACTORY = DocumentBuilderFactory.newInstance(); + static { + FACTORY.setNamespaceAware(true); + } + + private DOMHelper() { + } + + public static Document newDocument() throws ParserConfigurationException { + return newDocumentBuilder().newDocument(); + } + + public static DocumentBuilder newDocumentBuilder() throws ParserConfigurationException { + return FACTORY.newDocumentBuilder(); + } + + public static QName getQName(Node node) { + String ns = node.getNamespaceURI(); + if (ns == null) { + ns = ""; + } + // node.getLocalName() will return null if it is created using DOM Level + // 1 method + // such as createElement() + return new QName(ns, node.getNodeName()); + } + + public static Element createElement(Document document, QName name) { + String prefix = name.getPrefix(); + String qname = + (prefix != null && prefix.length() > 0) ? prefix + ":" + name.getLocalPart() : name + .getLocalPart(); + return document.createElementNS(name.getNamespaceURI(), qname); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/DirectedGraph.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/DirectedGraph.java new file mode 100755 index 0000000000..d99fe488de --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/DirectedGraph.java @@ -0,0 +1,357 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding.impl; + +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + * Directed, weighted graph + * + * @param The type of vertex object + * @param The type of edge object + */ +public class DirectedGraph { + private final Map vertices = new HashMap(); + + /** + * Key for the shortest path cache + */ + private final class VertexPair { + private Vertex source; + + private Vertex target; + + /** + * @param source + * @param target + */ + private VertexPair(Vertex source, Vertex target) { + super(); + this.source = source; + this.target = target; + } + + public boolean equals(Object object) { + if (!VertexPair.class.isInstance(object)) { + return false; + } + VertexPair pair = (VertexPair)object; + return source == pair.source && target == pair.target; + } + + public int hashCode() { + int x = source == null ? 0 : source.hashCode(); + int y = target == null ? 0 : target.hashCode(); + return x ^ y; + } + + } + + private final Map paths = new HashMap(); + + /** + * Vertex of a graph + */ + public final class Vertex { + private V value; + + // TODO: Do we want to support multiple edges for a vertex pair? If so, + // we should use a List instead of Map + private Map outEdges = new HashMap(); + + private Vertex(V value) { + this.value = value; + } + + public String toString() { + return "(" + value + ")"; + } + + public V getValue() { + return value; + } + + public Map getOutEdges() { + return outEdges; + } + + } + + /** + * An Edge connects two vertices in one direction + */ + public final class Edge { + private Vertex sourceVertex; + + private Vertex targetVertex; + + private E value; + + private int weight; + + public Edge(Vertex source, Vertex target, E value, int weight) { + this.sourceVertex = source; + this.targetVertex = target; + this.value = value; + this.weight = weight; + } + + public String toString() { + return sourceVertex + "->" + targetVertex + "[" + value + "," + weight + "]"; + } + + public E getValue() { + return value; + } + + public void setValue(E value) { + this.value = value; + } + + public Vertex getTargetVertex() { + return targetVertex; + } + + public void setTargetVertex(Vertex vertex) { + this.targetVertex = vertex; + } + + public int getWeight() { + return weight; + } + + public void setWeight(int weight) { + this.weight = weight; + } + + public Vertex getSourceVertex() { + return sourceVertex; + } + + public void setSourceVertex(Vertex sourceVertex) { + this.sourceVertex = sourceVertex; + } + } + + private final class Node implements Comparable { + + private long distance = Integer.MAX_VALUE; + + private Node previous; // NOPMD by rfeng on 9/26/06 9:17 PM + + private Vertex vertex; // NOPMD by rfeng on 9/26/06 9:17 PM + + private Node(Vertex vertex) { + this.vertex = vertex; + } + + public int compareTo(Node o) { + return (distance > o.distance) ? 1 : ((distance == o.distance) ? 0 : -1); + } + } + + public void addEdge(V source, V target, E edgeValue, int weight) { + Vertex s = getVertex(source); + if (s == null) { + s = new Vertex(source); + vertices.put(source, s); + } + Vertex t = getVertex(target); + if (t == null) { + t = new Vertex(target); + vertices.put(target, t); + } + Edge edge = new Edge(s, t, edgeValue, weight); + s.outEdges.put(t, edge); + } + + public Vertex getVertex(V source) { + Vertex s = vertices.get(source); + return s; + } + + public boolean removeEdge(V source, V target) { + Vertex s = getVertex(source); + if (s == null) { + return false; + } + + Vertex t = getVertex(target); + if (t == null) { + return false; + } + + return s.outEdges.remove(t) != null; + + } + + public Edge getEdge(Vertex source, Vertex target) { + return source.outEdges.get(target); + } + + public Edge getEdge(V source, V target) { + return getEdge(getVertex(source), getVertex(target)); + } + + /** + * Get the shortes path from the source vertex to the target vertex using + * Dijkstra's algorithm. If there's no path, null will be returned. If the + * source is the same as the target, it returns a path with empty edges with + * weight 0. + * + * @param sourceValue The value identifies the source + * @param targetValue The value identifies the target + * @return The shortest path + */ + public Path getShortestPath(V sourceValue, V targetValue) { + Vertex source = getVertex(sourceValue); + if (source == null) { + return null; + } + Vertex target = getVertex(targetValue); + if (target == null) { + return null; + } + + VertexPair pair = new VertexPair(source, target); + if (paths.containsKey(pair)) { + return paths.get(pair); + } + + // HACK: To support same vertex + if (source == target) { + Path path = new Path(); + Edge edge = getEdge(source, target); + if (edge != null) { + path.addEdge(edge); + } + paths.put(pair, path); + return path; + } + + Map nodes = new HashMap(); + for (Vertex v : vertices.values()) { + Node node = new Node(v); + if (v == source) { + node.distance = 0; + } + nodes.put(v, node); + } + + Set otherNodes = new HashSet(nodes.values()); + Set nodesOnPath = new HashSet(); + while (!otherNodes.isEmpty()) { + Node nextNode = extractMin(otherNodes); + if (nextNode.vertex == target) { + Path path = getPath(nextNode); + paths.put(pair, path); // Cache it + return path; + } + nodesOnPath.add(nextNode); + for (Edge edge : nextNode.vertex.outEdges.values()) { + Node adjacentNode = nodes.get(edge.targetVertex); + if (nextNode.distance + edge.weight < adjacentNode.distance) { + adjacentNode.distance = nextNode.distance + edge.weight; + adjacentNode.previous = nextNode; + } + } + } + paths.put(pair, null); // Cache it + return null; + } + + /** + * Searches for the vertex u in the vertex set Q that has the least d[u] + * value. That vertex is removed from the set Q and returned to the user. + * + * @param nodes + * @return + */ + private Node extractMin(Set nodes) { + Node node = Collections.min(nodes); + nodes.remove(node); + return node; + } + + /** + * The path between two vertices + */ + public final class Path { + private List edges = new LinkedList(); + + private int weight; + + public int getWeight() { + return weight; + } + + public List getEdges() { + return edges; + } + + public void addEdge(Edge edge) { + edges.add(0, edge); + weight += edge.weight; + } + + public String toString() { + return edges + ", " + weight; + } + } + + private Path getPath(Node t) { + if (t.distance == Integer.MAX_VALUE) { + return null; + } + Path path = new Path(); + Node u = t; + while (u.previous != null) { + Edge edge = getEdge(u.previous.vertex, u.vertex); + path.addEdge(edge); + u = u.previous; + } + return path; + } + + public String toString() { + StringBuffer sb = new StringBuffer(); + for (Vertex v : vertices.values()) { + sb.append(v.outEdges.values()).append("\n"); + } + return sb.toString(); + } + + public Map getVertices() { + return vertices; + } + + public void addGraph(DirectedGraph otherGraph) { + for (Vertex v : otherGraph.vertices.values()) { + for (Edge e : v.outEdges.values()) { + addEdge(e.sourceVertex.value, e.targetVertex.value, e.value, e.weight); + } + } + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/Group2GroupTransformer.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/Group2GroupTransformer.java new file mode 100644 index 0000000000..52917aaf50 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/Group2GroupTransformer.java @@ -0,0 +1,91 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.databinding.impl; + +import org.apache.tuscany.sca.databinding.Mediator; +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.interfacedef.DataType; + +/** + * This is a special transformer to transform the output from one IDL to the + * other one + */ +public class Group2GroupTransformer extends BaseTransformer implements + PullTransformer { + + protected Mediator mediator; + + /** + * @param wrapperHandler + */ + public Group2GroupTransformer() { + super(); + } + + /** + * @param mediator the mediator to set + */ + public void setMediator(Mediator mediator) { + this.mediator = mediator; + } + + @Override + public String getSourceDataBinding() { + return GroupDataBinding.NAME; + } + + @Override + public String getTargetDataBinding() { + return GroupDataBinding.NAME; + } + + /** + * @see org.apache.tuscany.sca.databinding.impl.BaseTransformer#getSourceType() + */ + @Override + protected Class getSourceType() { + return Object.class; + } + + /** + * @see org.apache.tuscany.sca.databinding.impl.BaseTransformer#getTargetType() + */ + @Override + protected Class getTargetType() { + return Object.class; + } + + /** + * @see org.apache.tuscany.sca.databinding.Transformer#getWeight() + */ + public int getWeight() { + return 10; + } + + @SuppressWarnings("unchecked") + public Object transform(Object source, TransformationContext context) { + DataType sourceType = context.getSourceDataType(); + DataType targetType = context.getTargetDataType(); + + return mediator.mediate(source, sourceType.getLogical(), targetType.getLogical(), context.getMetadata()); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/GroupDataBinding.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/GroupDataBinding.java new file mode 100644 index 0000000000..2403600389 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/GroupDataBinding.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.databinding.impl; + +import java.lang.annotation.Annotation; +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; + +import org.apache.tuscany.sca.interfacedef.DataType; + +/** + * The base class for a special databinding which represents a group of other databindings + * + * @version $Rev$ $Date$ + */ +public abstract class GroupDataBinding extends BaseDataBinding { + public static final String NAME = "databinding:group"; + + /** + * Marker type is a java class or interface representing the data format. + */ + protected Class[] markerTypes; + + public GroupDataBinding(Class[] types) { + super(NAME, null, GroupDataBinding.class); + this.markerTypes = types; + } + + @SuppressWarnings("unchecked") + public boolean introspect(DataType type, Annotation[] annotations) { + if (markerTypes == null) { + return false; + } + Type physical = type.getPhysical(); + if (physical instanceof ParameterizedType) { + physical = ((ParameterizedType)physical).getRawType(); + } + if (!(physical instanceof Class)) { + return false; + } + Class cls = (Class)physical; + for (Class c : markerTypes) { + if (isTypeOf(c, cls)) { + type.setDataBinding(getDataBinding(c)); + type.setLogical(getLogical(cls, annotations)); + return true; + } + } + return false; + } + + /** + * Test if the given type is a subtype of the base type + * @param markerType + * @param type + * @return + */ + protected boolean isTypeOf(Class markerType, Class type) { + return markerType.isAssignableFrom(type); + } + + /** + * Derive the databinding name from a base class + * @param baseType + * @return + */ + protected String getDataBinding(Class baseType) { + return baseType.getName(); + } + + /** + * Get the logical type + * @param type The java type + * @param annotations + * @return + */ + protected abstract Object getLogical(Class type, Annotation[] annotations); + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/Java2SimpleTypeTransformer.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/Java2SimpleTypeTransformer.java new file mode 100644 index 0000000000..b39a944f32 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/Java2SimpleTypeTransformer.java @@ -0,0 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding.impl; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.SimpleTypeMapper; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.interfacedef.util.XMLType; + +/** + * Transformer to convert data from a simple java object to a databinding's representation + */ +public abstract class Java2SimpleTypeTransformer extends BaseTransformer implements + PullTransformer { + + protected SimpleTypeMapper mapper; + + public Java2SimpleTypeTransformer() { + this.mapper = new SimpleTypeMapperImpl(); + } + + public Java2SimpleTypeTransformer(SimpleTypeMapper mapper) { + this.mapper = (mapper != null) ? mapper : new SimpleTypeMapperImpl(); + } + + public T transform(Object source, TransformationContext context) { + XMLType xmlType = (XMLType) context.getTargetDataType().getLogical(); + String text = mapper.toXMLLiteral(xmlType.getTypeName(), source, context); + return createElement(xmlType.getElementName(), text, context); + } + + public Class getSourceType() { + return Object.class; + } + + public int getWeight() { + return 10000; + } + + protected abstract T createElement(QName element, String literal, TransformationContext context); + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/MediatorImpl.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/MediatorImpl.java new file mode 100644 index 0000000000..adff1718de --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/MediatorImpl.java @@ -0,0 +1,167 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding.impl; + +import java.util.List; +import java.util.Map; + +import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint; +import org.apache.tuscany.sca.databinding.DataPipe; +import org.apache.tuscany.sca.databinding.Mediator; +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.PushTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.Transformer; +import org.apache.tuscany.sca.databinding.TransformerExtensionPoint; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl; + +/** + * Default Mediator implementation + */ +public class MediatorImpl implements Mediator { + + private DataBindingExtensionPoint dataBindings; + private TransformerExtensionPoint transformers; + + public MediatorImpl(DataBindingExtensionPoint dataBindings, + TransformerExtensionPoint transformers) { + this.dataBindings = dataBindings; + this.transformers = transformers; + } + + @SuppressWarnings("unchecked") + public Object mediate(Object source, DataType sourceDataType, DataType targetDataType, Map metadata) { + if (sourceDataType == null || sourceDataType.getDataBinding() == null) { + sourceDataType = dataBindings.introspectType(source); + } + if (sourceDataType == null) { + return source; + } else if (sourceDataType.equals(targetDataType)) { + return source; + } + + List path = getTransformerChain(sourceDataType, targetDataType); + + Object result = source; + int size = path.size(); + int i = 0; + while (i < size) { + Transformer transformer = path.get(i); + TransformationContext context = createTransformationContext(sourceDataType, + targetDataType, + size, + i, + transformer, + metadata); + // the source and target type + if (transformer instanceof PullTransformer) { + // For intermediate node, set data type to null + result = ((PullTransformer)transformer).transform(result, context); + } else if (transformer instanceof PushTransformer) { + DataPipe dataPipe = (i < size - 1) ? (DataPipe)path.get(++i) : null; + ((PushTransformer)transformer).transform(result, dataPipe.getSink(), context); + result = dataPipe.getResult(); + } + i++; + } + + return result; + } + + private TransformationContext createTransformationContext(DataType sourceDataType, + DataType targetDataType, + int size, + int index, + Transformer transformer, + Map metadata) { + DataType sourceType = (index == 0) ? sourceDataType : new DataTypeImpl(transformer + .getSourceDataBinding(), Object.class, sourceDataType.getLogical()); + DataType targetType = (index == size - 1) ? targetDataType : new DataTypeImpl(transformer + .getTargetDataBinding(), Object.class, targetDataType.getLogical()); + ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); + TransformationContext context = new TransformationContextImpl(sourceType, targetType, classLoader, metadata); + return context; + } + + @SuppressWarnings("unchecked") + public void mediate(Object source, + Object target, + DataType sourceDataType, + DataType targetDataType, + Map metadata) { + if (source == null) { + // Shortcut for null value + return; + } + if (sourceDataType == null || sourceDataType.getDataBinding() == null) { + sourceDataType = dataBindings.introspectType(source); + } + if (sourceDataType == null) { + return; + } else if (sourceDataType.equals(targetDataType)) { + return; + } + + List path = getTransformerChain(sourceDataType, targetDataType); + Object result = source; + int size = path.size(); + for (int i = 0; i < size; i++) { + Transformer transformer = path.get(i); + TransformationContext context = createTransformationContext(sourceDataType, + targetDataType, + size, + i, + transformer, + metadata); + + if (transformer instanceof PullTransformer) { + result = ((PullTransformer)transformer).transform(result, context); + } else if (transformer instanceof PushTransformer) { + DataPipe dataPipe = (i < size - 1) ? (DataPipe)path.get(++i) : null; + Object sink = dataPipe != null ? dataPipe.getSink() : target; + ((PushTransformer)transformer).transform(result, sink, context); + result = (dataPipe != null) ? dataPipe.getResult() : null; + } + } + } + + private List getTransformerChain(DataType sourceDataType, DataType targetDataType) { + String sourceId = sourceDataType.getDataBinding(); + String targetId = targetDataType.getDataBinding(); + List path = transformers.getTransformerChain(sourceId, targetId); + if (path == null) { + TransformationException ex = new TransformationException("No path found for the transformation"); + ex.setSourceDataBinding(sourceId); + ex.setTargetDataBinding(targetId); + throw ex; + } + return path; + } + + public DataBindingExtensionPoint getDataBindings() { + return dataBindings; + } + + public TransformerExtensionPoint getTransformers() { + return transformers; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/PipedTransformer.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/PipedTransformer.java new file mode 100755 index 0000000000..9a1385f193 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/PipedTransformer.java @@ -0,0 +1,66 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding.impl; + +import org.apache.tuscany.sca.databinding.DataPipe; +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.PushTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; + +/** + * A utility class to connect PushTransformer and DataPipe to create a + * PullTransformer + * + * @param Source type + * @param Intermidate type + * @param Result type + */ +public class PipedTransformer implements PullTransformer { + private PushTransformer pusher; + + private DataPipe pipe; + + /** + * @param pumper + * @param pipe + */ + public PipedTransformer(PushTransformer pumper, DataPipe pipe) { + super(); + this.pusher = pumper; + this.pipe = pipe; + } + + public R transform(S source, TransformationContext context) { + pusher.transform(source, pipe.getSink(), context); + return pipe.getResult(); + } + + public String getSourceDataBinding() { + return pusher.getSourceDataBinding(); + } + + public String getTargetDataBinding() { + return pipe.getTargetDataBinding(); + } + + public int getWeight() { + return pusher.getWeight() + pipe.getWeight(); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/SimpleType2JavaTransformer.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/SimpleType2JavaTransformer.java new file mode 100644 index 0000000000..009c7f2272 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/SimpleType2JavaTransformer.java @@ -0,0 +1,63 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding.impl; + +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.SimpleTypeMapper; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.interfacedef.util.XMLType; + +/** + * Transformer to convert data from a databinding's representation of simple + * types to Java Objects + */ +public abstract class SimpleType2JavaTransformer extends BaseTransformer implements + PullTransformer { + + protected SimpleTypeMapper mapper; + + public SimpleType2JavaTransformer() { + this.mapper = new SimpleTypeMapperImpl(); + } + + public SimpleType2JavaTransformer(SimpleTypeMapper mapper) { + this.mapper = (mapper != null) ? mapper : new SimpleTypeMapperImpl(); + } + + public Object transform(T source, TransformationContext context) { + XMLType xmlType = (XMLType) context.getSourceDataType().getLogical(); + return mapper.toJavaObject(xmlType.getTypeName(), getText(source), context); + } + + public Class getTargetType() { + return Object.class; + } + + public int getWeight() { + // Cannot be used for imtermediate + return 10000; + } + + /** + * Get the string value from the source + * @param source + * @return A string + */ + protected abstract String getText(T source); +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/SimpleTypeMapperImpl.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/SimpleTypeMapperImpl.java new file mode 100644 index 0000000000..9c23efe091 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/SimpleTypeMapperImpl.java @@ -0,0 +1,392 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.databinding.impl; + +import java.util.Date; +import java.util.GregorianCalendar; +import java.util.HashMap; +import java.util.Map; + +import javax.xml.datatype.DatatypeConfigurationException; +import javax.xml.datatype.DatatypeFactory; +import javax.xml.datatype.XMLGregorianCalendar; +import javax.xml.namespace.NamespaceContext; +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.databinding.SimpleTypeMapper; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.interfacedef.util.TypeInfo; + +public class SimpleTypeMapperImpl extends XSDDataTypeConverter implements SimpleTypeMapper { + + public static final Map JAVA2XML = new HashMap(); + + public static final String URI_2001_SCHEMA_XSD = "http://www.w3.org/2001/XMLSchema"; + + public static final Map XML2JAVA = new HashMap(); + + public static final QName XSD_ANY = new QName(URI_2001_SCHEMA_XSD, "any"); + + public static final QName XSD_ANYSIMPLETYPE = new QName(URI_2001_SCHEMA_XSD, "anySimpleType"); + + public static final QName XSD_ANYTYPE = new QName(URI_2001_SCHEMA_XSD, "anyType"); + + public static final QName XSD_ANYURI = new QName(URI_2001_SCHEMA_XSD, "anyURI"); + + public static final QName XSD_BASE64 = new QName(URI_2001_SCHEMA_XSD, "base64Binary"); + + public static final QName XSD_BOOLEAN = new QName(URI_2001_SCHEMA_XSD, "boolean"); + + public static final QName XSD_BYTE = new QName(URI_2001_SCHEMA_XSD, "byte"); + + public static final QName XSD_DATE = new QName(URI_2001_SCHEMA_XSD, "date"); + + public static final QName XSD_DATETIME = new QName(URI_2001_SCHEMA_XSD, "dateTime"); + + public static final QName XSD_DAY = new QName(URI_2001_SCHEMA_XSD, "gDay"); + + public static final QName XSD_DECIMAL = new QName(URI_2001_SCHEMA_XSD, "decimal"); + + public static final QName XSD_DOUBLE = new QName(URI_2001_SCHEMA_XSD, "double"); + + public static final QName XSD_DURATION = new QName(URI_2001_SCHEMA_XSD, "duration"); + + public static final QName XSD_ENTITIES = new QName(URI_2001_SCHEMA_XSD, "ENTITIES"); + + public static final QName XSD_ENTITY = new QName(URI_2001_SCHEMA_XSD, "ENTITY"); + + public static final QName XSD_FLOAT = new QName(URI_2001_SCHEMA_XSD, "float"); + + public static final QName XSD_HEXBIN = new QName(URI_2001_SCHEMA_XSD, "hexBinary"); + + public static final QName XSD_IDREF = new QName(URI_2001_SCHEMA_XSD, "IDREF"); + + public static final QName XSD_IDREFS = new QName(URI_2001_SCHEMA_XSD, "IDREFS"); + + public static final QName XSD_INT = new QName(URI_2001_SCHEMA_XSD, "int"); + + public static final QName XSD_INTEGER = new QName(URI_2001_SCHEMA_XSD, "integer"); + + public static final QName XSD_LONG = new QName(URI_2001_SCHEMA_XSD, "long"); + + public static final QName XSD_MONTH = new QName(URI_2001_SCHEMA_XSD, "gMonth"); + + public static final QName XSD_MONTHDAY = new QName(URI_2001_SCHEMA_XSD, "gMonthDay"); + + public static final QName XSD_NAME = new QName(URI_2001_SCHEMA_XSD, "Name"); + + public static final QName XSD_NCNAME = new QName(URI_2001_SCHEMA_XSD, "NCName"); + + public static final QName XSD_NEGATIVEINTEGER = new QName(URI_2001_SCHEMA_XSD, "negativeInteger"); + + public static final QName XSD_NMTOKEN = new QName(URI_2001_SCHEMA_XSD, "NMTOKEN"); + + public static final QName XSD_NMTOKENS = new QName(URI_2001_SCHEMA_XSD, "NMTOKENS"); + + public static final QName XSD_NONNEGATIVEINTEGER = new QName(URI_2001_SCHEMA_XSD, "nonNegativeInteger"); + + public static final QName XSD_NONPOSITIVEINTEGER = new QName(URI_2001_SCHEMA_XSD, "nonPositiveInteger"); + + public static final QName XSD_NORMALIZEDSTRING = new QName(URI_2001_SCHEMA_XSD, "normalizedString"); + + public static final QName XSD_NOTATION = new QName(URI_2001_SCHEMA_XSD, "NOTATION"); + + public static final QName XSD_POSITIVEINTEGER = new QName(URI_2001_SCHEMA_XSD, "positiveInteger"); + + public static final QName XSD_QNAME = new QName(URI_2001_SCHEMA_XSD, "QName"); + + public static final QName XSD_SHORT = new QName(URI_2001_SCHEMA_XSD, "short"); + + public static final Map XSD_SIMPLE_TYPES = new HashMap(); + + public static final QName XSD_STRING = new QName(URI_2001_SCHEMA_XSD, "string"); + + public static final QName XSD_TIME = new QName(URI_2001_SCHEMA_XSD, "time"); + + public static final QName XSD_TOKEN = new QName(URI_2001_SCHEMA_XSD, "token"); + + public static final QName XSD_UNSIGNEDBYTE = new QName(URI_2001_SCHEMA_XSD, "unsignedByte"); + + public static final QName XSD_UNSIGNEDINT = new QName(URI_2001_SCHEMA_XSD, "unsignedInt"); + + public static final QName XSD_UNSIGNEDLONG = new QName(URI_2001_SCHEMA_XSD, "unsignedLong"); + + public static final QName XSD_UNSIGNEDSHORT = new QName(URI_2001_SCHEMA_XSD, "unsignedShort"); + + public static final QName XSD_YEAR = new QName(URI_2001_SCHEMA_XSD, "gYear"); + + public static final QName XSD_YEARMONTH = new QName(URI_2001_SCHEMA_XSD, "gYearMonth"); + + private static final String[] XSD_TYPE_NAMES = + {"string", "boolean", "double", "float", "int", "integer", "long", "short", "byte", "decimal", "base64Binary", + "hexBinary", "anySimpleType", "anyType", "any", "QName", "dateTime", "date", "time", "normalizedString", + "token", "unsignedLong", "unsignedInt", "unsignedShort", "unsignedByte", "positiveInteger", "negativeInteger", + "nonNegativeInteger", "nonPositiveInteger", "gYearMonth", "gMonthDay", "gYear", "gMonth", "gDay", "duration", + "Name", "NCName", "NMTOKEN", "NMTOKENS", "NOTATION", "ENTITY", "ENTITIES", "IDREF", "IDREFS", "anyURI", + "language", "ID"}; + + static { + for (String type : XSD_TYPE_NAMES) { + TypeInfo simpleType = new TypeInfo(new QName(URI_2001_SCHEMA_XSD, type), true, null); + XSD_SIMPLE_TYPES.put(type, simpleType); + } + } + + static { + JAVA2XML.put(boolean.class, "boolean"); + JAVA2XML.put(byte.class, "byte"); + JAVA2XML.put(short.class, "short"); + JAVA2XML.put(int.class, "int"); + JAVA2XML.put(long.class, "long"); + JAVA2XML.put(float.class, "float"); + JAVA2XML.put(double.class, "double"); + JAVA2XML.put(Boolean.class, "boolean"); + JAVA2XML.put(Byte.class, "byte"); + JAVA2XML.put(Short.class, "short"); + JAVA2XML.put(Integer.class, "int"); + JAVA2XML.put(Long.class, "long"); + JAVA2XML.put(Float.class, "float"); + JAVA2XML.put(Double.class, "double"); + JAVA2XML.put(java.lang.String.class, "string"); + JAVA2XML.put(java.math.BigInteger.class, "integer"); + JAVA2XML.put(java.math.BigDecimal.class, "decimal"); + JAVA2XML.put(java.util.Calendar.class, "dateTime"); + JAVA2XML.put(java.util.Date.class, "dateTime"); + JAVA2XML.put(javax.xml.namespace.QName.class, "QName"); + JAVA2XML.put(java.net.URI.class, "string"); + JAVA2XML.put(javax.xml.datatype.XMLGregorianCalendar.class, "anySimpleType"); + JAVA2XML.put(javax.xml.datatype.Duration.class, "duration"); + JAVA2XML.put(java.lang.Object.class, "anyType"); + JAVA2XML.put(java.awt.Image.class, "base64Binary"); + JAVA2XML.put(byte[].class, "base64Binary"); + // java2XSD.put(javax.activation.DataHandler.class, "base64Binary"); + JAVA2XML.put(javax.xml.transform.Source.class, "base64Binary"); + JAVA2XML.put(java.util.UUID.class, "string"); + } + + static { + XML2JAVA.put("string", java.lang.String.class); + XML2JAVA.put("integer", java.math.BigInteger.class); + XML2JAVA.put("int", int.class); + XML2JAVA.put("long", long.class); + XML2JAVA.put("short", short.class); + XML2JAVA.put("decimal", java.math.BigDecimal.class); + XML2JAVA.put("float", float.class); + XML2JAVA.put("double", double.class); + XML2JAVA.put("boolean", boolean.class); + XML2JAVA.put("byte", byte.class); + XML2JAVA.put("QName", javax.xml.namespace.QName.class); + XML2JAVA.put("dateTime", javax.xml.datatype.XMLGregorianCalendar.class); + XML2JAVA.put("base64Binary", byte[].class); + XML2JAVA.put("hexBinary", byte[].class); + XML2JAVA.put("unsignedInt", long.class); + XML2JAVA.put("unsignedShort", int.class); + XML2JAVA.put("unsignedByte", short.class); + XML2JAVA.put("time", javax.xml.datatype.XMLGregorianCalendar.class); + XML2JAVA.put("date", javax.xml.datatype.XMLGregorianCalendar.class); + XML2JAVA.put("gDay", javax.xml.datatype.XMLGregorianCalendar.class); + XML2JAVA.put("gMonth", javax.xml.datatype.XMLGregorianCalendar.class); + XML2JAVA.put("gYear", javax.xml.datatype.XMLGregorianCalendar.class); + XML2JAVA.put("gYearMonth", javax.xml.datatype.XMLGregorianCalendar.class); + XML2JAVA.put("gMonthDay", javax.xml.datatype.XMLGregorianCalendar.class); + XML2JAVA.put("anySimpleType", java.lang.Object.class); // For elements + // XML2JAVA.put("anySimpleType", java.lang.String.class); // For + // attributes + XML2JAVA.put("duration", javax.xml.datatype.Duration.class); + XML2JAVA.put("NOTATION", javax.xml.namespace.QName.class); + } + + private DatatypeFactory factory; + + public SimpleTypeMapperImpl() { + super(); + try { + this.factory = DatatypeFactory.newInstance(); + } catch (DatatypeConfigurationException e) { + throw new IllegalArgumentException(e); + } + } + + public static Class getJavaType(QName xmlType) { + if (URI_2001_SCHEMA_XSD.equals(xmlType.getNamespaceURI())) { + return XML2JAVA.get(xmlType.getLocalPart()); + } else { + return null; + } + } + + public TypeInfo getXMLType(Class javaType) { + return XSD_SIMPLE_TYPES.get(JAVA2XML.get(javaType)); + } + + public Object toJavaObject(QName simpleType, String literal, TransformationContext context) { + /** + *
    + *
  • xsd:string --- java.lang.String + *
  • xsd:integer --- java.math.BigInteger + *
  • xsd:int --- int + *
  • xsd:long --- long + *
  • xsd:short --- short + *
  • xsd:decimal --- java.math.BigDecimal + *
  • xsd:float --- float + *
  • xsd:double --- double + *
  • xsd:boolean --- boolean + *
  • xsd:byte --- byte + *
  • xsd:QName --- javax.xml.namespace.QName + *
  • xsd:dateTime --- javax.xml.datatype.XMLGregorianCalendar + *
  • xsd:base64Binary --- byte[] + *
  • xsd:hexBinary --- byte[] + *
  • xsd:unsignedInt --- long + *
  • xsd:unsignedShort --- int + *
  • xsd:unsignedByte --- short + *
  • xsd:time --- javax.xml.datatype.XMLGregorianCalendar + *
  • xsd:date --- javax.xml.datatype.XMLGregorianCalendar + *
  • xsd:g* --- javax.xml.datatype.XMLGregorianCalendar + *
  • xsd:anySimpleType (for xsd:element of this type)a + * java.lang.Object + *
  • xsd:anySimpleType (for xsd:attribute of this type) + * java.lang.String + *
  • xsd:duration javax.xml.datatype.Duration + *
  • xsd:NOTATION javax.xml.namespace.QName + *
+ */ + + if (literal == null) { + return null; + } + String value = literal.trim(); + + QName type = simpleType; + if (type.equals(XSD_STRING)) { + return parseString(value); + } else if (type.equals(XSD_INT)) { + return parseInt(value); + } else if (type.equals(XSD_INTEGER)) { + return parseInteger(value); + } else if (type.equals(XSD_INT)) { + return parseInt(value); + } else if (type.equals(XSD_FLOAT)) { + return parseFloat(value); + } else if (type.equals(XSD_DOUBLE)) { + return parseDouble(value); + } else if (type.equals(XSD_SHORT)) { + return parseShort(value); + } else if (type.equals(XSD_DECIMAL)) { + return parseDecimal(value); + } else if (type.equals(XSD_BOOLEAN)) { + return parseBoolean(value); + } else if (type.equals(XSD_BYTE)) { + return parseByte(value); + } else if (type.equals(XSD_LONG)) { + return parseLong(value); + } else if (type.equals(XSD_UNSIGNEDBYTE)) { + return parseUnsignedShort(value); + } else if (type.equals(XSD_UNSIGNEDSHORT)) { + return parseUnsignedShort(value); + } else if (type.equals(XSD_UNSIGNEDINT)) { + return parseUnsignedInt(value); + } else if (type.equals(XSD_UNSIGNEDLONG)) { + return parseUnsignedInt(value); + } else if (type.equals(XSD_DATETIME)) { + return parseDateTime(value); + } else if (type.equals(XSD_DATE)) { + return parseDate(value); + } else if (type.equals(XSD_TIME)) { + return parseTime(value); + } else if (type.equals(XSD_DURATION)) { + return parseDuration(value); + } else if (type.equals(XSD_HEXBIN)) { + return parseHexBinary(value); + } else if (type.equals(XSD_BASE64)) { + return parseBase64Binary(value); + } else if (type.equals(XSD_QNAME)) { + NamespaceContext namespaceContext = + (NamespaceContext)((context != null) ? context.getMetadata().get(NamespaceContext.class.getName()) : null); + return parseQName(value, namespaceContext); + } else if (type.equals(XSD_NOTATION)) { + NamespaceContext namespaceContext = + (NamespaceContext)((context != null) ? context.getMetadata().get(NamespaceContext.class.getName()) : null); + return parseQName(value, namespaceContext); + } else if (type.equals(XSD_YEAR)) { + return factory.newXMLGregorianCalendar(value); + } else if (type.equals(XSD_MONTH)) { + return factory.newXMLGregorianCalendar(value); + } else if (type.equals(XSD_DAY)) { + return factory.newXMLGregorianCalendar(value); + } else if (type.equals(XSD_YEARMONTH)) { + return factory.newXMLGregorianCalendar(value); + } else if (type.equals(XSD_MONTHDAY)) { + return factory.newXMLGregorianCalendar(value); + } else { + return value; + } + } + + @SuppressWarnings("deprecation") + private XMLGregorianCalendar toXMLGregorianCalendar(Date date) { + GregorianCalendar c = + new GregorianCalendar(date.getYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), + date.getSeconds()); + return factory.newXMLGregorianCalendar(c); + } + + private XMLGregorianCalendar toXMLGregorianCalendar(GregorianCalendar calendar) { + return factory.newXMLGregorianCalendar(calendar); + } + + public String toXMLLiteral(QName simpleType, Object obj, TransformationContext context) { + if (obj instanceof Float || obj instanceof Double) { + if (obj instanceof Float) { + return printDouble(((Float)obj).floatValue()); + } else { + return printDouble(((Double)obj).doubleValue()); + } + } else if (obj instanceof GregorianCalendar) { + GregorianCalendar calendar = (GregorianCalendar)obj; + return toXMLGregorianCalendar(calendar).toXMLFormat(); + } else if (obj instanceof Date) { + return toXMLGregorianCalendar((Date)obj).toXMLFormat(); + } else if (obj instanceof XMLGregorianCalendar) { + return ((XMLGregorianCalendar)obj).toXMLFormat(); + } else if (obj instanceof byte[]) { + if (simpleType != null) { + if (simpleType.equals(XSD_BASE64)) { + return printBase64Binary((byte[])obj); + } else if (simpleType.equals(XSD_HEXBIN)) { + return printHexBinary((byte[])obj); + } + } + } else if (obj instanceof QName) { + NamespaceContext namespaceContext = + (NamespaceContext)((context != null) ? context.getMetadata().get(NamespaceContext.class.getName()) : null); + return printQName((QName)obj, namespaceContext); + } + return obj.toString(); + } + + public static boolean isSimpleXSDType(QName typeName) { + if (typeName == null) { + return false; + } + return typeName.getNamespaceURI().equals(URI_2001_SCHEMA_XSD) + && XSD_SIMPLE_TYPES.get(typeName.getLocalPart()) != null; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/TransformationContextImpl.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/TransformationContextImpl.java new file mode 100755 index 0000000000..6a11f4fcb3 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/TransformationContextImpl.java @@ -0,0 +1,112 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding.impl; + +import java.lang.ref.WeakReference; +import java.util.HashMap; +import java.util.Map; + +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.interfacedef.DataType; +import org.apache.tuscany.sca.interfacedef.Operation; + +public class TransformationContextImpl implements TransformationContext { + private DataType sourceDataType; + + private DataType targetDataType; + + private final Map metadata = new HashMap(); + + private WeakReference classLoaderRef; + + public TransformationContextImpl() { + super(); + setClassLoader(Thread.currentThread().getContextClassLoader()); + } + + public TransformationContextImpl(DataType sourceDataType, + DataType targetDataType, + ClassLoader classLoader, + Map metadata) { + super(); + this.sourceDataType = sourceDataType; + this.targetDataType = targetDataType; + setClassLoader(classLoader); + if (metadata != null) { + this.metadata.putAll(metadata); + } + } + + public DataType getSourceDataType() { + return sourceDataType; + } + + public DataType getTargetDataType() { + return targetDataType; + } + + public void setSourceDataType(DataType sourceDataType) { + this.sourceDataType = sourceDataType; + } + + public void setTargetDataType(DataType targetDataType) { + this.targetDataType = targetDataType; + } + + public final void setClassLoader(ClassLoader classLoader) { + this.classLoaderRef = new WeakReference(classLoader); + } + + public ClassLoader getClassLoader() { + return classLoaderRef.get(); + } + + public Map getMetadata() { + return metadata; + } + + /** + * @return the sourceOperation + */ + public Operation getSourceOperation() { + return (Operation) metadata.get("source.operation"); + } + + /** + * @param sourceOperation the sourceOperation to set + */ + public void setSourceOperation(Operation sourceOperation) { + this.metadata.put("source.operation", sourceOperation); + } + + /** + * @return the targetOperation + */ + public Operation getTargetOperation() { + return (Operation) metadata.get("target.operation"); + } + + /** + * @param targetOperation the targetOperation to set + */ + public void setTargetOperation(Operation targetOperation) { + this.metadata.put("target.operation", targetOperation); + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/XSDDataTypeConverter.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/XSDDataTypeConverter.java new file mode 100644 index 0000000000..7c92c365cf --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/XSDDataTypeConverter.java @@ -0,0 +1,941 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.databinding.impl; + +import java.io.IOException; +import java.io.OutputStream; +import java.io.Writer; +import java.math.BigDecimal; +import java.math.BigInteger; +import java.text.FieldPosition; +import java.text.Format; +import java.text.ParsePosition; +import java.util.Calendar; +import java.util.TimeZone; + +import javax.xml.XMLConstants; +import javax.xml.datatype.DatatypeConfigurationException; +import javax.xml.datatype.DatatypeFactory; +import javax.xml.datatype.Duration; +import javax.xml.namespace.NamespaceContext; +import javax.xml.namespace.QName; + +/** + * Utility class for XSD data type conversions + */ +public class XSDDataTypeConverter { + public static final class Base64Binary { + private static final char[] S_BASE64CHAR = + {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', + 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', + 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', + '5', '6', '7', '8', '9', '+', '/'}; + + private static final char S_BASE64PAD = '='; + + private static final byte[] S_DECODETABLE = new byte[128]; + + static { + for (int i = 0; i < S_DECODETABLE.length; i++) { + S_DECODETABLE[i] = Byte.MAX_VALUE; // 127 + } + for (int i = 0; i < S_BASE64CHAR.length; i++) { + // 0 to 63 + S_DECODETABLE[S_BASE64CHAR[i]] = (byte) i; + } + } + + private Base64Binary() { + } + + /** + * + */ + public static byte[] decode(char[] data, int off, int len) { + char[] ibuf = new char[4]; + int ibufcount = 0; + byte[] obuf = new byte[len / 4 * 3 + 3]; + int obufcount = 0; + for (int i = off; i < off + len; i++) { + char ch = data[i]; + if (ch == S_BASE64PAD || ch < S_DECODETABLE.length && S_DECODETABLE[ch] != Byte.MAX_VALUE) { + ibuf[ibufcount++] = ch; + if (ibufcount == ibuf.length) { + ibufcount = 0; + obufcount += decode0(ibuf, obuf, obufcount); + } + } + } + if (obufcount == obuf.length) { + return obuf; + } + byte[] ret = new byte[obufcount]; + System.arraycopy(obuf, 0, ret, 0, obufcount); + return ret; + } + + /** + * + */ + public static void decode(char[] data, int off, int len, OutputStream ostream) throws IOException { + char[] ibuf = new char[4]; + int ibufcount = 0; + byte[] obuf = new byte[3]; + for (int i = off; i < off + len; i++) { + char ch = data[i]; + if (ch == S_BASE64PAD || ch < S_DECODETABLE.length && S_DECODETABLE[ch] != Byte.MAX_VALUE) { + ibuf[ibufcount++] = ch; + if (ibufcount == ibuf.length) { + ibufcount = 0; + int obufcount = decode0(ibuf, obuf, 0); + ostream.write(obuf, 0, obufcount); + } + } + } + } + + /** + * + */ + public static byte[] decode(String data) { + char[] ibuf = new char[4]; + int ibufcount = 0; + byte[] obuf = new byte[data.length() / 4 * 3 + 3]; + int obufcount = 0; + for (int i = 0; i < data.length(); i++) { + char ch = data.charAt(i); + if (ch == S_BASE64PAD || ch < S_DECODETABLE.length && S_DECODETABLE[ch] != Byte.MAX_VALUE) { + ibuf[ibufcount++] = ch; + if (ibufcount == ibuf.length) { + ibufcount = 0; + obufcount += decode0(ibuf, obuf, obufcount); + } + } + } + if (obufcount == obuf.length) { + return obuf; + } + byte[] ret = new byte[obufcount]; + System.arraycopy(obuf, 0, ret, 0, obufcount); + return ret; + } + + /** + * + */ + public static void decode(String data, OutputStream ostream) throws IOException { + char[] ibuf = new char[4]; + int ibufcount = 0; + byte[] obuf = new byte[3]; + for (int i = 0; i < data.length(); i++) { + char ch = data.charAt(i); + if (ch == S_BASE64PAD || ch < S_DECODETABLE.length && S_DECODETABLE[ch] != Byte.MAX_VALUE) { + ibuf[ibufcount++] = ch; + if (ibufcount == ibuf.length) { + ibufcount = 0; + int obufcount = decode0(ibuf, obuf, 0); + ostream.write(obuf, 0, obufcount); + } + } + } + } + + private static int decode0(char[] ibuf, byte[] obuf, int index) { + int wp = index; + int outlen = 3; + if (ibuf[3] == S_BASE64PAD) { + outlen = 2; + } + if (ibuf[2] == S_BASE64PAD) { + outlen = 1; + } + int b0 = S_DECODETABLE[ibuf[0]]; + int b1 = S_DECODETABLE[ibuf[1]]; + int b2 = S_DECODETABLE[ibuf[2]]; + int b3 = S_DECODETABLE[ibuf[3]]; + switch (outlen) { + case 1: + obuf[wp] = (byte) (b0 << 2 & 0xfc | b1 >> 4 & 0x3); + return 1; + case 2: + obuf[wp++] = (byte) (b0 << 2 & 0xfc | b1 >> 4 & 0x3); + obuf[wp] = (byte) (b1 << 4 & 0xf0 | b2 >> 2 & 0xf); + return 2; + case 3: + obuf[wp++] = (byte) (b0 << 2 & 0xfc | b1 >> 4 & 0x3); + obuf[wp++] = (byte) (b1 << 4 & 0xf0 | b2 >> 2 & 0xf); + obuf[wp] = (byte) (b2 << 6 & 0xc0 | b3 & 0x3f); + return 3; + default: + throw new IllegalArgumentException("The character sequence is not base64 encoded."); + } + } + + /** + * Returns base64 representation of specified byte array. + */ + public static String encode(byte[] data) { + return encode(data, 0, data.length); + } + + /** + * Returns base64 representation of specified byte array. + */ + public static String encode(byte[] data, int off, int len) { + if (len <= 0) { + return ""; + } + char[] out = new char[len / 3 * 4 + 4]; + int rindex = off; + int windex = 0; + int rest = len - off; + while (rest >= 3) { + int i = + ((data[rindex] & 0xff) << 16) + ((data[rindex + 1] & 0xff) << 8) + + (data[rindex + 2] & 0xff); + out[windex++] = S_BASE64CHAR[i >> 18]; + out[windex++] = S_BASE64CHAR[(i >> 12) & 0x3f]; + out[windex++] = S_BASE64CHAR[(i >> 6) & 0x3f]; + out[windex++] = S_BASE64CHAR[i & 0x3f]; + rindex += 3; + rest -= 3; + } + if (rest == 1) { + int i = data[rindex] & 0xff; + out[windex++] = S_BASE64CHAR[i >> 2]; + out[windex++] = S_BASE64CHAR[(i << 4) & 0x3f]; + out[windex++] = S_BASE64PAD; + out[windex++] = S_BASE64PAD; + } else if (rest == 2) { + int i = ((data[rindex] & 0xff) << 8) + (data[rindex + 1] & 0xff); + out[windex++] = S_BASE64CHAR[i >> 10]; + out[windex++] = S_BASE64CHAR[(i >> 4) & 0x3f]; + out[windex++] = S_BASE64CHAR[(i << 2) & 0x3f]; + out[windex++] = S_BASE64PAD; + } + return new String(out, 0, windex); + } + + /** + * Outputs base64 representation of the specified byte array to a byte stream. + */ + public static void encode(byte[] data, int off, int len, OutputStream ostream) throws IOException { + if (len <= 0) { + return; + } + byte[] out = new byte[4]; + int rindex = off; + int rest = len - off; + while (rest >= 3) { + int i = + ((data[rindex] & 0xff) << 16) + ((data[rindex + 1] & 0xff) << 8) + + (data[rindex + 2] & 0xff); + out[0] = (byte) S_BASE64CHAR[i >> 18]; + out[1] = (byte) S_BASE64CHAR[(i >> 12) & 0x3f]; + out[2] = (byte) S_BASE64CHAR[(i >> 6) & 0x3f]; + out[3] = (byte) S_BASE64CHAR[i & 0x3f]; + ostream.write(out, 0, 4); + rindex += 3; + rest -= 3; + } + if (rest == 1) { + int i = data[rindex] & 0xff; + out[0] = (byte) S_BASE64CHAR[i >> 2]; + out[1] = (byte) S_BASE64CHAR[(i << 4) & 0x3f]; + out[2] = (byte) S_BASE64PAD; + out[3] = (byte) S_BASE64PAD; + ostream.write(out, 0, 4); + } else if (rest == 2) { + int i = ((data[rindex] & 0xff) << 8) + (data[rindex + 1] & 0xff); + out[0] = (byte) S_BASE64CHAR[i >> 10]; + out[1] = (byte) S_BASE64CHAR[(i >> 4) & 0x3f]; + out[2] = (byte) S_BASE64CHAR[(i << 2) & 0x3f]; + out[3] = (byte) S_BASE64PAD; + ostream.write(out, 0, 4); + } + } + + /** + * Outputs base64 representation of the specified byte array to a character stream. + */ + public static void encode(byte[] data, int off, int len, Writer writer) throws IOException { + if (len <= 0) { + return; + } + char[] out = new char[4]; + int rindex = off; + int rest = len - off; + int output = 0; + while (rest >= 3) { + int i = + ((data[rindex] & 0xff) << 16) + ((data[rindex + 1] & 0xff) << 8) + + (data[rindex + 2] & 0xff); + out[0] = S_BASE64CHAR[i >> 18]; + out[1] = S_BASE64CHAR[(i >> 12) & 0x3f]; + out[2] = S_BASE64CHAR[(i >> 6) & 0x3f]; + out[3] = S_BASE64CHAR[i & 0x3f]; + writer.write(out, 0, 4); + rindex += 3; + rest -= 3; + output += 4; + if (output % 76 == 0) { + writer.write("\n"); + } + } + if (rest == 1) { + int i = data[rindex] & 0xff; + out[0] = S_BASE64CHAR[i >> 2]; + out[1] = S_BASE64CHAR[(i << 4) & 0x3f]; + out[2] = S_BASE64PAD; + out[3] = S_BASE64PAD; + writer.write(out, 0, 4); + } else if (rest == 2) { + int i = ((data[rindex] & 0xff) << 8) + (data[rindex + 1] & 0xff); + out[0] = S_BASE64CHAR[i >> 10]; + out[1] = S_BASE64CHAR[(i >> 4) & 0x3f]; + out[2] = S_BASE64CHAR[(i << 2) & 0x3f]; + out[3] = S_BASE64PAD; + writer.write(out, 0, 4); + } + } + } + + /** + *

+ * Utility class for xs:hexbinary.

+ */ + public static final class HexBinary { + private HexBinary() { + } + + /** + * Converts the string pValue into an array of hex bytes. + */ + public static byte[] decode(String pValue) { + if ((pValue.length() % 2) != 0) { + throw new IllegalArgumentException("A HexBinary string must have even length."); + } + byte[] result = new byte[pValue.length() / 2]; + int j = 0; + int i = 0; + while (i < pValue.length()) { + byte b; + char c = pValue.charAt(i++); + char d = pValue.charAt(i++); + if (c >= '0' && c <= '9') { + b = (byte) ((c - '0') << 4); + } else if (c >= 'A' && c <= 'F') { + b = (byte) ((c - 'A' + 10) << 4); + } else if (c >= 'a' && c <= 'f') { + b = (byte) ((c - 'a' + 10) << 4); + } else { + throw new IllegalArgumentException("Invalid hex digit: " + c); + } + if (d >= '0' && d <= '9') { + b += (byte) (d - '0'); + } else if (d >= 'A' && d <= 'F') { + b += (byte) (d - 'A' + 10); + } else if (d >= 'a' && d <= 'f') { + b += (byte) (d - 'a' + 10); + } else { + throw new IllegalArgumentException("Invalid hex digit: " + d); + } + result[j++] = b; + } + return result; + } + + /** + * Converts the byte array pHexBinary into a string. + */ + public static String encode(byte[] pHexBinary) { + StringBuffer result = new StringBuffer(); + for (int i = 0; i < pHexBinary.length; i++) { + byte b = pHexBinary[i]; + byte c = (byte) ((b & 0xf0) >> 4); + if (c <= 9) { + result.append((char) ('0' + c)); + } else { + result.append((char) ('A' + c - 10)); + } + c = (byte) (b & 0x0f); + if (c <= 9) { + result.append((char) ('0' + c)); + } else { + result.append((char) ('A' + c - 10)); + } + } + return result.toString(); + } + + /** + * Creates a clone of the given byte array. + */ + public static byte[] getClone(byte[] pHexBinary) { + byte[] result = new byte[pHexBinary.length]; + System.arraycopy(pHexBinary, 0, result, 0, pHexBinary.length); + return result; + } + } + + public class XSDDateFormat extends XSDDateTimeFormat { + private static final long serialVersionUID = -1629412916827246627L; + + /** + * Creates a new instance. + */ + public XSDDateFormat() { + super(true, false); + } + } + + /** + *

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

+ */ + public static class XSDDateTimeFormat extends Format { + private static final long serialVersionUID = -1148332471737068969L; + + final boolean parseDate; + + final boolean parseTime; + + /** + * Creates a new instance. + */ + public XSDDateTimeFormat() { + this(true, true); + } + + XSDDateTimeFormat(boolean pParseDate, boolean pParseTime) { + parseDate = pParseDate; + parseTime = pParseTime; + } + + private void append(StringBuffer pBuffer, int pNum, int pMinLen) { + String s = Integer.toString(pNum); + for (int i = s.length(); i < pMinLen; i++) { + pBuffer.append('0'); + } + pBuffer.append(s); + } + + public StringBuffer format(Object pCalendar, StringBuffer pBuffer, FieldPosition pPos) { + assert pCalendar != null : "The Calendar argument must not be null."; + assert pBuffer != null : "The StringBuffer argument must not be null."; + assert pPos != null : "The FieldPosition argument must not be null."; + + Calendar cal = (Calendar) pCalendar; + if (parseDate) { + int year = cal.get(Calendar.YEAR); + if (year < 0) { + pBuffer.append('-'); + year = -year; + } + append(pBuffer, year, 4); + pBuffer.append('-'); + append(pBuffer, cal.get(Calendar.MONTH) + 1, 2); + pBuffer.append('-'); + append(pBuffer, cal.get(Calendar.DAY_OF_MONTH), 2); + if (parseTime) { + pBuffer.append('T'); + } + } + if (parseTime) { + append(pBuffer, cal.get(Calendar.HOUR_OF_DAY), 2); + pBuffer.append(':'); + append(pBuffer, cal.get(Calendar.MINUTE), 2); + pBuffer.append(':'); + append(pBuffer, cal.get(Calendar.SECOND), 2); + int millis = cal.get(Calendar.MILLISECOND); + if (millis > 0) { + pBuffer.append('.'); + append(pBuffer, millis, 3); + } + } + TimeZone tz = cal.getTimeZone(); + // JDK 1.4: int offset = tz.getOffset(cal.getTimeInMillis()); + int offset = cal.get(Calendar.ZONE_OFFSET); + if (tz.inDaylightTime(cal.getTime())) { + offset += cal.get(Calendar.DST_OFFSET); + } + if (offset == 0) { + pBuffer.append('Z'); + } else { + if (offset < 0) { + pBuffer.append('-'); + offset = -offset; + } else { + pBuffer.append('+'); + } + int minutes = offset / (60 * 1000); + int hours = minutes / 60; + minutes -= hours * 60; + append(pBuffer, hours, 2); + pBuffer.append(':'); + append(pBuffer, minutes, 2); + } + return pBuffer; + } + + private int parseInt(String pString, int offset, StringBuffer pDigits) { + int length = pString.length(); + int pOffset = offset; + pDigits.setLength(0); + while (pOffset < length) { + char c = pString.charAt(pOffset); + if (Character.isDigit(c)) { + pDigits.append(c); + ++pOffset; + } else { + break; + } + } + return pOffset; + } + + public Object parseObject(String pString, ParsePosition pParsePosition) { + assert pString != null : "The String argument must not be null."; + assert pParsePosition != null : "The ParsePosition argument must not be null."; + int offset = pParsePosition.getIndex(); + int length = pString.length(); + + boolean isMinus = false; + StringBuffer digits = new StringBuffer(); + int year = 0; + int month = 0; + int mday = 0; + if (parseDate) { + // Sign + if (offset < length) { + char c = pString.charAt(offset); + if (c == '+') { + ++offset; + } else if (c == '-') { + ++offset; + isMinus = true; + } + } + + offset = parseInt(pString, offset, digits); + if (digits.length() < 4) { + pParsePosition.setErrorIndex(offset); + return null; + } + year = Integer.parseInt(digits.toString()); + + if (offset < length && pString.charAt(offset) == '-') { + ++offset; + } else { + pParsePosition.setErrorIndex(offset); + return null; + } + + offset = parseInt(pString, offset, digits); + if (digits.length() != 2) { + pParsePosition.setErrorIndex(offset); + return null; + } + month = Integer.parseInt(digits.toString()); + + if (offset < length && pString.charAt(offset) == '-') { + ++offset; + } else { + pParsePosition.setErrorIndex(offset); + return null; + } + + offset = parseInt(pString, offset, digits); + if (digits.length() != 2) { + pParsePosition.setErrorIndex(offset); + return null; + } + mday = Integer.parseInt(digits.toString()); + + if (parseTime) { + if (offset < length && pString.charAt(offset) == 'T') { + ++offset; + } else { + pParsePosition.setErrorIndex(offset); + return null; + } + } + } else { + year = month = mday = 0; + } + + int hour = 0; + int minute = 0; + int second = 0; + int millis = 0; + if (parseTime) { + offset = parseInt(pString, offset, digits); + if (digits.length() != 2) { + pParsePosition.setErrorIndex(offset); + return null; + } + hour = Integer.parseInt(digits.toString()); + + if (offset < length && pString.charAt(offset) == ':') { + ++offset; + } else { + pParsePosition.setErrorIndex(offset); + return null; + } + + offset = parseInt(pString, offset, digits); + if (digits.length() != 2) { + pParsePosition.setErrorIndex(offset); + return null; + } + minute = Integer.parseInt(digits.toString()); + + if (offset < length && pString.charAt(offset) == ':') { + ++offset; + } else { + pParsePosition.setErrorIndex(offset); + return null; + } + + offset = parseInt(pString, offset, digits); + if (digits.length() != 2) { + pParsePosition.setErrorIndex(offset); + return null; + } + second = Integer.parseInt(digits.toString()); + + if (offset < length && pString.charAt(offset) == '.') { + ++offset; + offset = parseInt(pString, offset, digits); + if (digits.length() > 0) { + millis = Integer.parseInt(digits.toString()); + } else { + millis = 0; + } + } else { + millis = 0; + } + } else { + hour = minute = second = millis = 0; + } + + digits.setLength(0); + digits.append("GMT"); + if (offset < length) { + char c = pString.charAt(offset); + if (c == 'Z') { + // Ignore UTC, it is the default + ++offset; + } else if (c == '+' || c == '-') { + digits.append(c); + ++offset; + for (int i = 0; i < 5; i++) { + if (offset >= length) { + pParsePosition.setErrorIndex(offset); + return null; + } + c = pString.charAt(offset); + if ((i != 2 && Character.isDigit(c)) || (i == 2 && c == ':')) { + digits.append(c); + } else { + pParsePosition.setErrorIndex(offset); + return null; + } + ++offset; + } + } + } + + Calendar cal = Calendar.getInstance(TimeZone.getTimeZone(digits.toString())); + cal.set(isMinus ? -year : year, parseDate ? month - 1 : month, mday, hour, minute, second); + cal.set(Calendar.MILLISECOND, millis); + pParsePosition.setIndex(offset); + return cal; + } + } + + public static class XSDTimeFormat extends XSDDateTimeFormat { + private static final long serialVersionUID = 1346506860724640517L; + + /** + * Creates a new instance. + */ + public XSDTimeFormat() { + super(false, true); + } + } + + private static final long MAX_UNSIGNED_INT = (((long) Integer.MAX_VALUE) * 2) + 1; + + private static final int MAX_UNSIGNED_SHORT = Short.MAX_VALUE * 2 + 1; + + public String parseAnySimpleType(String value) { + return value; + } + + public byte[] parseBase64Binary(String value) { + return Base64Binary.decode(value); + } + + public boolean parseBoolean(String value) { + return Boolean.valueOf(value).booleanValue(); + } + + public byte parseByte(String value) { + return Byte.parseByte(value); + } + + public Calendar parseDate(String value) { + XSDDateFormat format = new XSDDateFormat(); + ParsePosition pos = new ParsePosition(0); + Calendar cal = (Calendar) format.parseObject(value, pos); + if (cal == null) { + throw new IllegalArgumentException("Failed to parse date " + value + " at:" + + value.substring(pos.getErrorIndex())); + } + return cal; + } + + public Calendar parseDateTime(String value) { + XSDDateTimeFormat format = new XSDDateTimeFormat(); + ParsePosition pos = new ParsePosition(0); + Calendar cal = (Calendar) format.parseObject(value, pos); + if (cal == null) { + throw new IllegalArgumentException("Failed to parse dateTime " + value + " at:" + + value.substring(pos.getErrorIndex())); + } + return cal; + } + + public BigDecimal parseDecimal(String value) { + return new BigDecimal(value); + } + + public double parseDouble(String value) { + if ("INF".equals(value)) { + return Double.POSITIVE_INFINITY; + } else if ("-INF".equals(value)) { + return Double.NEGATIVE_INFINITY; + } else if ("NaN".equals(value)) { + return Double.NaN; + } else { + return Double.parseDouble(value); + } + } + + public Duration parseDuration(String pDuration) { + try { + return DatatypeFactory.newInstance().newDuration(pDuration); + } catch (DatatypeConfigurationException e) { + throw new IllegalArgumentException(e); + } + } + + public float parseFloat(String value) { + if ("INF".equals(value)) { + return Float.POSITIVE_INFINITY; + } else if ("-INF".equals(value)) { + return Float.NEGATIVE_INFINITY; + } else if ("NaN".equals(value)) { + return Float.NaN; + } else { + return Float.parseFloat(value); + } + } + + public byte[] parseHexBinary(String value) { + return HexBinary.decode(value); + } + + public int parseInt(String value) { + return Integer.parseInt(value); + } + + public BigInteger parseInteger(String value) { + return new BigInteger(value); + } + + public long parseLong(String value) { + return Long.parseLong(value); + } + + public QName parseQName(String value, NamespaceContext context) { + int offset = value.indexOf(':'); + String uri; + String localName; + switch (offset) { + case -1: + localName = value; + uri = context.getNamespaceURI(""); + if (uri == null) { + // Should not happen, indicates an error in the + // NamespaceContext + // implementation + throw new IllegalArgumentException("The default prefix is not bound."); + } + break; + case 0: + throw new IllegalArgumentException("Default prefix must be indicated by not using a colon: " + + value); + default: + String prefix = value.substring(0, offset); + localName = value.substring(offset + 1); + uri = context.getNamespaceURI(prefix); + if (uri == null) { + throw new IllegalArgumentException("The prefix " + prefix + " is not bound."); + } + } + return new QName(uri, localName); + } + + public short parseShort(String value) { + return Short.parseShort(value); + } + + public String parseString(String value) { + return value; + } + + public Calendar parseTime(String value) { + XSDTimeFormat format = new XSDTimeFormat(); + ParsePosition pos = new ParsePosition(0); + Calendar cal = (Calendar) format.parseObject(value, pos); + if (cal == null) { + throw new IllegalArgumentException("Failed to parse time " + value + " at:" + + value.substring(pos.getErrorIndex())); + } + return cal; + } + + public long parseUnsignedInt(String value) { + long l = Long.parseLong(value); + if (l < 0) { + throw new IllegalArgumentException("Failed to parse UnsignedInt " + value + + ": result is negative"); + } + if (l > MAX_UNSIGNED_INT) { + throw new IllegalArgumentException("Failed to parse UnsignedInt " + value + + ": result exceeds maximum value " + MAX_UNSIGNED_INT); + } + return l; + } + + public int parseUnsignedShort(String value) { + int i = Integer.parseInt(value); + if (i < 0) { + throw new IllegalArgumentException("Failed to parse UnsignedShort " + value + + ": result is negative"); + } + if (i > MAX_UNSIGNED_SHORT) { + throw new IllegalArgumentException("Failed to parse UnsignedShort " + value + + ": result exceeds maximum value " + MAX_UNSIGNED_SHORT); + } + return i; + } + + public String printAnySimpleType(String value) { + return value; + } + + public String printBase64Binary(byte[] value) { + return Base64Binary.encode(value); + } + + public String printBoolean(boolean value) { + return (value ? Boolean.TRUE : Boolean.FALSE).toString(); + } + + public String printByte(byte value) { + return Byte.toString(value); + } + + public String printDate(Calendar value) { + return new XSDDateFormat().format(value); + } + + public String printDateTime(Calendar value) { + return new XSDDateTimeFormat().format(value); + } + + public String printDecimal(BigDecimal value) { + return value.toString(); + } + + public String printDouble(double value) { + return Double.toString(value); + } + + public String printDuration(Duration pDuration) { + return pDuration.toString(); + } + + public String printFloat(float value) { + return Float.toString(value); + } + + public String printHexBinary(byte[] value) { + return HexBinary.encode(value); + } + + public String printInt(int value) { + return Integer.toString(value); + } + + public String printInteger(BigInteger value) { + return value.toString(); + } + + public String printLong(long value) { + return Long.toString(value); + } + + public String printQName(QName value, NamespaceContext context) { + String prefix = context.getPrefix(value.getNamespaceURI()); + if (prefix == null) { + throw new IllegalArgumentException("The namespace URI " + value.getNamespaceURI() + + " is not bound."); + } else if (XMLConstants.DEFAULT_NS_PREFIX.equals(prefix)) { + return value.getLocalPart(); + } else { + return prefix + ":" + value.getLocalPart(); + } + } + + public String printShort(short value) { + return Short.toString(value); + } + + public String printString(String value) { + return value; + } + + public String printTime(Calendar value) { + return new XSDTimeFormat().format(value); + } + + public String printUnsignedInt(long value) { + return Long.toString(value); + } + + public String printUnsignedShort(int value) { + return Integer.toString(value); + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/DOMNode2JavaBeanTransformer.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/DOMNode2JavaBeanTransformer.java new file mode 100644 index 0000000000..34ddc4d268 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/DOMNode2JavaBeanTransformer.java @@ -0,0 +1,75 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding.javabeans; + +import java.util.ArrayList; +import java.util.List; + +import org.w3c.dom.Document; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +/** + * Transformer to convert data from DOM Node to JavaBean + */ +public class DOMNode2JavaBeanTransformer extends XML2JavaBeanTransformer { + + @Override + public Node getRootElement(Node element) throws XML2JavaMapperException { + if (element instanceof Document) { + return ((Document)element).getDocumentElement(); + } else { + return element; + } + + } + + @Override + public List getChildElements(Node parent) throws XML2JavaMapperException { + NodeList nodeList = parent.getChildNodes(); + List nodeArrayList = new ArrayList(nodeList.getLength()); + for (int count = 0; count < nodeList.getLength(); ++count) { + nodeArrayList.add(nodeList.item(count)); + } + + return nodeArrayList; + } + + @Override + public String getElementName(Node element) throws XML2JavaMapperException { + return element.getLocalName(); + } + + @Override + public String getText(Node element) throws XML2JavaMapperException { + if (element instanceof Document) { + element = ((Document)element).getDocumentElement(); + } + return element.getTextContent(); + } + + @Override + public boolean isTextElement(Node element) throws XML2JavaMapperException { + return element.getNodeType() == Node.TEXT_NODE; + } + + public Class getSourceType() { + return Node.class; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/Java2XMLMapperException.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/Java2XMLMapperException.java new file mode 100644 index 0000000000..050c4288c3 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/Java2XMLMapperException.java @@ -0,0 +1,67 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.databinding.javabeans; + +import javax.xml.namespace.QName; + +/** + * This exception is used to encapsulate and rethrow exceptions that arise out + * of converting JavaBean objects to XML + */ +public class Java2XMLMapperException extends RuntimeException { + private static final long serialVersionUID = 6811924384399578686L; + + private QName xmlElementName; + private String javaFieldName; + private Class javaType; + + public Java2XMLMapperException(String message) { + super(message); + } + + public Java2XMLMapperException(Throwable cause) { + super(cause); + } + + public String getJavaFieldName() { + return javaFieldName; + } + + public void setJavaFieldName(String javaFieldName) { + this.javaFieldName = javaFieldName; + } + + public Class getJavaType() { + return javaType; + } + + public void setJavaType(Class javaType) { + this.javaType = javaType; + } + + public QName getXmlElementName() { + return xmlElementName; + } + + public void setXmlElementName(QName xmlElementName) { + this.xmlElementName = xmlElementName; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/JavaBean2DOMNodeTransformer.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/JavaBean2DOMNodeTransformer.java new file mode 100644 index 0000000000..c363a36d95 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/JavaBean2DOMNodeTransformer.java @@ -0,0 +1,67 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding.javabeans; + +import javax.xml.namespace.QName; +import javax.xml.parsers.ParserConfigurationException; + +import org.apache.tuscany.sca.databinding.impl.DOMHelper; +import org.w3c.dom.Document; +import org.w3c.dom.Node; + +/** + * Transformer to convert data from a JavaBean object to DOM Node + */ +public class JavaBean2DOMNodeTransformer extends JavaBean2XMLTransformer { + + public static final String COLON = ":"; + private Document factory; + + public JavaBean2DOMNodeTransformer() { + super(); + try { + factory = DOMHelper.newDocument(); + } catch (ParserConfigurationException e) { + throw new Java2XMLMapperException(e); + } + } + + @Override + public void appendChild(Node parentElement, Node childElement) throws Java2XMLMapperException { + parentElement.appendChild(childElement); + } + + @Override + public Node createElement(QName qName) throws Java2XMLMapperException { + String qualifedName = + (qName.getPrefix() == null || qName.getPrefix().length() <= 0) ? qName.getLocalPart() + : qName.getPrefix() + COLON + qName.getLocalPart(); + return factory.createElementNS(qName.getNamespaceURI(), qualifedName); + } + + @Override + public Node createText(String textData) throws Java2XMLMapperException { + return factory.createTextNode(textData); + } + + public Class getTargetType() { + return Node.class; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/JavaBean2XMLStreamReader.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/JavaBean2XMLStreamReader.java new file mode 100644 index 0000000000..a41d853958 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/JavaBean2XMLStreamReader.java @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding.javabeans; + +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; +import org.apache.tuscany.sca.databinding.xml.BeanUtil; +import org.apache.tuscany.sca.databinding.xml.XMLDocumentStreamReader; + +public class JavaBean2XMLStreamReader extends BaseTransformer implements + PullTransformer { + + public XMLStreamReader transform(Object source, TransformationContext context) { + try { + return new XMLDocumentStreamReader(BeanUtil.getXMLStreamReader(source)); + } catch (Exception e) { + throw new TransformationException(e); + } + } + + public Class getSourceType() { + return Object.class; + } + + public Class getTargetType() { + return XMLStreamReader.class; + } + + public int getWeight() { + return 50; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/JavaBean2XMLTransformer.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/JavaBean2XMLTransformer.java new file mode 100644 index 0000000000..56910582c0 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/JavaBean2XMLTransformer.java @@ -0,0 +1,226 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding.javabeans; + +import java.lang.reflect.Array; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.util.Date; +import java.util.GregorianCalendar; + +import javax.xml.datatype.XMLGregorianCalendar; +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; +import org.apache.tuscany.sca.databinding.impl.SimpleTypeMapperImpl; + +/** + * Transformer to convert data from a JavaBean object to xml + */ +public abstract class JavaBean2XMLTransformer extends BaseTransformer implements + PullTransformer { + + public static final String GET = "get"; + public static final String PREFIX = "n"; + public static final String PERIOD = "."; + public static final String FWD_SLASH = "/"; + public static final String HTTP = "http://"; + private static int prefixCount = 1; + + protected SimpleTypeMapperImpl mapper; + + public JavaBean2XMLTransformer() { + this.mapper = new SimpleTypeMapperImpl(); + } + + public T transform(Object source, TransformationContext context) { + + //FIXME See how/if we still need to get the metadata here + //QName rootElementName = (QName)context.getTargetDataType().getMetadata("RootElementName"); + //if (rootElementName == null) { + QName rootElementName = new QName(resolveRootElementName(source.getClass())); + //} + + T root = createElement(rootElementName); + appendChildElements(root, + resolveElementName(source.getClass()), + source.getClass(), + source, + context); + return root; + } + + private void appendChildElements(T parent, + QName elementName, + Class javaType, + Object javaObject, + TransformationContext context) { + T element = null; + if (javaObject != null) { + if (javaType.isPrimitive() || isSimpleJavaType(javaObject)) { + appendChild(parent, createText(mapper.toXMLLiteral(null, javaObject, context))); + } else if (javaType.isArray()) { + boolean arrayDone = false; + Object arrayObject = null; + for (int count = 0; !arrayDone; ++count) { + try { + arrayObject = Array.get(javaObject, count); + element = createElement(elementName); + appendChild(parent, element); + appendChildElements(element, + elementName, + javaType.getComponentType(), + arrayObject, + context); + } catch (ArrayIndexOutOfBoundsException e1) { + arrayDone = true; + } + } + } else { + Field[] javaFields = javaType.getFields(); + for (Field aField : javaFields) { + try { + QName fieldElementName = new QName(aField.getName()); + if (!aField.getType().isArray()) { + element = createElement(fieldElementName); + appendChild(parent, element); + appendChildElements(element, + fieldElementName, + aField.getType(), + aField.get(javaObject), + context); + } else { + appendChildElements(parent, + fieldElementName, + aField.getType(), + aField.get(javaObject), + context); + } + } catch (IllegalAccessException e) { + Java2XMLMapperException java2xmlEx = new Java2XMLMapperException(e); + java2xmlEx.setJavaFieldName(aField.getName()); + java2xmlEx.setJavaType(javaType); + throw java2xmlEx; + } + } + + Method[] methods = javaType.getDeclaredMethods(); + String fieldName = null; + for (Method aMethod : methods) { + try { + if (Modifier.isPublic(aMethod.getModifiers()) && aMethod.getName().startsWith(GET) + && aMethod.getParameterTypes().length == 0) { + fieldName = resolveFieldFromMethod(aMethod.getName()); + try { + javaType.getField(fieldName); + } catch (NoSuchFieldException e) { + QName fieldElementName = new QName(fieldName); + if (aMethod.getReturnType().isArray()) { + appendChildElements(parent, fieldElementName, aMethod.getReturnType(), aMethod + .invoke(javaObject, new Object[0]), context); + } else { + element = createElement(fieldElementName); + appendChild(parent, element); + appendChildElements(element, fieldElementName, aMethod.getReturnType(), aMethod + .invoke(javaObject, new Object[0]), context); + } + } + } + } catch (IllegalAccessException e) { + Java2XMLMapperException java2xmlEx = new Java2XMLMapperException(e); + java2xmlEx.setJavaFieldName(fieldName); + java2xmlEx.setJavaType(javaType); + throw java2xmlEx; + } catch (InvocationTargetException e) { + Java2XMLMapperException java2xmlEx = new Java2XMLMapperException(e); + java2xmlEx.setJavaFieldName(fieldName); + java2xmlEx.setJavaType(javaType); + throw java2xmlEx; + } + } + } + } + } + + public Class getSourceType() { + return Object.class; + } + + private boolean isSimpleJavaType(Object javaObject) { + if (javaObject instanceof String) { + return true; + } + if (javaObject instanceof Byte || javaObject instanceof Character + || javaObject instanceof Short + || javaObject instanceof Integer + || javaObject instanceof Long + || javaObject instanceof Float + || javaObject instanceof Double) { + return true; + } + if (javaObject instanceof GregorianCalendar || javaObject instanceof Date + || javaObject instanceof XMLGregorianCalendar + || javaObject instanceof byte[] + || javaObject instanceof QName) { + return true; + } + return false; + } + + private String resolveRootElementName(Class javaType) { + if (javaType.isArray()) { + return javaType.getComponentType().getSimpleName() + "_collection"; + } else { + return javaType.getSimpleName() + "_instance"; + } + } + + + private QName resolveElementName(Class javaType) { + if (javaType.isArray()) { + return new QName(javaType.getComponentType().getSimpleName()); + } else { + return new QName(javaType.getSimpleName()); + } + } + + private String resolveFieldFromMethod(String methodName) { + StringBuffer fieldName = new StringBuffer(); + fieldName.append(Character.toLowerCase(methodName.charAt(GET.length()))); + fieldName.append(methodName.substring(GET.length() + 1)); + return fieldName.toString(); + } + + public String getNexPrefix() { + return PREFIX + prefixCount++; + } + + @Override + public int getWeight() { + return JavaBeansDataBinding.HEAVY_WEIGHT; + } + + public abstract T createElement(QName qName) throws Java2XMLMapperException; + public abstract T createText(String textData) throws Java2XMLMapperException; + public abstract void appendChild(T parentElement, T childElement) throws Java2XMLMapperException; +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/JavaBeansDataBinding.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/JavaBeansDataBinding.java new file mode 100644 index 0000000000..966fc48bb8 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/JavaBeansDataBinding.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.databinding.javabeans; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.ObjectStreamClass; +import java.io.OutputStream; +import java.io.Serializable; + +import org.apache.tuscany.sca.databinding.impl.BaseDataBinding; + +/** + * DataBinding for JavaBeans + */ +public class JavaBeansDataBinding extends BaseDataBinding { + /** + * Defining a weight to a very high number so that the transformer won't be picked + * up by other paths unless it's the only available path + */ + public static final int HEAVY_WEIGHT = 10000; + public static final String NAME = Object.class.getName(); + + public JavaBeansDataBinding() { + super(NAME, Object.class); + } + + public Object copy(Object arg) { + if (arg == null) { + return null; + } + final Class clazz = arg.getClass(); + if (String.class == clazz || clazz.isPrimitive() + || Number.class.isAssignableFrom(clazz) + || Boolean.class.isAssignableFrom(clazz) + || Character.class.isAssignableFrom(clazz) + || Byte.class.isAssignableFrom(clazz)) { + // Immutable classes + return arg; + } + try { + if (arg instanceof Serializable) { + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + ObjectOutputStream oos = getObjectOutputStream(bos); + oos.writeObject(arg); + oos.close(); + bos.close(); + + ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray()); + ObjectInputStream ois = getObjectInputStream(bis, clazz.getClassLoader()); + Object objectCopy = ois.readObject(); + ois.close(); + bis.close(); + return objectCopy; + } else { + // return arg; + throw new IllegalArgumentException("Pass-by-value is not supported for the given object"); + } + } catch (Exception e) { + throw new IllegalArgumentException("Pass-by-value is not supported for the given object", e); + } + } + + protected ObjectOutputStream getObjectOutputStream(OutputStream os) throws IOException { + return new ObjectOutputStream(os); + } + + protected ObjectInputStream getObjectInputStream(InputStream is, final ClassLoader cl) throws IOException { + ObjectInputStream ois = new ObjectInputStream(is) { + @Override + protected Class resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException { + try { + return Class.forName(desc.getName(), false, cl); + } catch (ClassNotFoundException e) { + return super.resolveClass(desc); + } + } + + }; + return ois; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/XML2JavaBeanTransformer.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/XML2JavaBeanTransformer.java new file mode 100644 index 0000000000..2bf16a5b86 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/XML2JavaBeanTransformer.java @@ -0,0 +1,295 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding.javabeans; + +import java.lang.reflect.Array; +import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.Hashtable; +import java.util.List; +import java.util.Map; + +import javax.xml.namespace.QName; + +import org.apache.tuscany.sca.databinding.PullTransformer; +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.impl.BaseTransformer; +import org.apache.tuscany.sca.databinding.impl.SimpleTypeMapperImpl; +import org.apache.tuscany.sca.interfacedef.util.XMLType; + +/** + * Transformer to convert data from XML to JavaBean + */ +public abstract class XML2JavaBeanTransformer extends BaseTransformer implements + PullTransformer { + + public static final String SET = "set"; + + protected SimpleTypeMapperImpl mapper; + + public XML2JavaBeanTransformer() { + this.mapper = new SimpleTypeMapperImpl(); + } + + @Override + public int getWeight() { + return JavaBeansDataBinding.HEAVY_WEIGHT; + } + + public Object transform(T source, TransformationContext context) { + XMLType xmlType = (XMLType) context.getSourceDataType().getLogical(); + return toJavaObject(xmlType.getTypeName(), getRootElement(source), context); + } + + public Object toJavaObject(QName xmlType, T xmlElement, TransformationContext context) { + if (SimpleTypeMapperImpl.isSimpleXSDType(xmlType)) { + return mapper.toJavaObject(xmlType, getText(xmlElement), context); + } else { + Class javaType = (Class)context.getTargetDataType().getPhysical(); + return createJavaObject(xmlElement, javaType, context); + } + } + + @SuppressWarnings("unchecked") + private L createJavaObject(T element, Class javaType, TransformationContext context) + throws XML2JavaMapperException { + List childElements = getChildElements(element); + if (childElements.size() == 1 && isTextElement(childElements.get(0))) { + return (L) mapper.toJavaObject(mapper.getXMLType(javaType).getQName(), + getText(childElements.get(0)), + context); + } else { + String fieldName = null; + try { + L javaInstance = javaType.newInstance(); + Map> arrayFields = new Hashtable>(); + Map> arraySetters = new Hashtable>(); + for (int count = 0; count < childElements.size(); ++count) { + if (!isTextElement(childElements.get(count))) { + fieldName = getElementName(childElements.get(count)); + try { + Field javaField = javaType.getField(fieldName); + setFieldValue(javaInstance, + javaField, + childElements.get(count), + arrayFields, + context); + + } catch (NoSuchFieldException e1) { + setFieldValueUsingSetter(javaType, + javaInstance, + fieldName, + childElements.get(count), + arraySetters, + context); + } + } + } + + setArrayValues(javaInstance, arrayFields, arraySetters); + return javaInstance; + } catch (Exception e2) { + XML2JavaMapperException xml2JavaEx = new XML2JavaMapperException(e2); + xml2JavaEx.setJavaType(javaType); + xml2JavaEx.setJavaFieldName(fieldName); + throw xml2JavaEx; + } + } + } + + private void setFieldValue(Object javaInstance, + Field javaField, + T fieldValue, + Map> arrayFields, + TransformationContext context) throws IllegalAccessException { + Class javaFieldType = (Class) javaField.getType(); + + if (javaFieldType.isArray()) { + Class componentType = javaFieldType.getComponentType(); + List fldValueArray = arrayFields.get(javaField); + if (fldValueArray == null) { + fldValueArray = new ArrayList(); + arrayFields.put(javaField, fldValueArray); + } + fldValueArray.add(createJavaObject(fieldValue, componentType, context)); + } else { + javaField.setAccessible(true); + javaField.set(javaInstance, createJavaObject(fieldValue, javaFieldType, context)); + } + } + + private void setFieldValueUsingSetter(Class javaType, + Object javaInstance, + String fieldName, + T fieldValue, + Map> arraySetters, + TransformationContext context) throws IllegalAccessException, + InvocationTargetException { + char firstChar = Character.toUpperCase(fieldName.charAt(0)); + StringBuilder methodName = new StringBuilder(SET + fieldName); + methodName.setCharAt(SET.length(), firstChar); + boolean methodNotFound = true; + + for (int methodCount = 0; methodNotFound && methodCount < javaType.getMethods().length; ++methodCount) { + Method aMethod = javaType.getMethods()[methodCount]; + if (aMethod.getName().equals(methodName.toString()) + && aMethod.getParameterTypes().length == 1) { + Class paramType = aMethod.getParameterTypes()[0]; + + if (paramType.isArray()) { + Class componentType = paramType.getComponentType(); + List setterValueArray = arraySetters.get(aMethod); + if (setterValueArray == null) { + setterValueArray = new ArrayList(); + arraySetters.put(aMethod, setterValueArray); + } + setterValueArray.add(createJavaObject(fieldValue, componentType, context)); + } else { + aMethod.invoke(javaInstance, new Object[] {createJavaObject(fieldValue, + paramType, + context)}); + } + methodNotFound = false; + } + } + + if (methodNotFound) { + XML2JavaMapperException xml2JavaEx = + new XML2JavaMapperException("No field or setter method to configure xml data"); + xml2JavaEx.setJavaFieldName(fieldName); + xml2JavaEx.setJavaType(javaType); + throw xml2JavaEx; + } + } + + private void setArrayValues(Object javaInstance, + Map> arrayFields, + Map> arraySetters) throws IllegalAccessException, + InvocationTargetException { + if (arrayFields.size() > 0) { + for (Field javaField : arrayFields.keySet()) { + javaField.setAccessible(true); + + if (javaField.getType().getComponentType().isPrimitive()) { + javaField.set(javaInstance, createPrimitiveArray(javaField.getType() + .getComponentType(), + arrayFields.get(javaField))); + } else { + javaField.set(javaInstance, + createNonPrimitiveArray(javaField.getType().getComponentType(), + arrayFields.get(javaField))); + } + } + } + + if (arraySetters.size() > 0) { + for (Method aMethod : arraySetters.keySet()) { + Class paramType = aMethod.getParameterTypes()[0]; + if (paramType.getComponentType().isPrimitive()) { + aMethod.invoke(javaInstance, + new Object[] {createPrimitiveArray(paramType.getComponentType(), + arraySetters.get(aMethod))}); + } else { + aMethod.invoke(javaInstance, + new Object[] {createNonPrimitiveArray(paramType.getComponentType(), + arraySetters.get(aMethod))}); + } + } + } + } + + private Object createNonPrimitiveArray(Class fieldType, List values) { + Object objectArray = Array.newInstance(fieldType, values.size()); + for (int count = 0; count < values.size(); ++count) { + Array.set(objectArray, count, values.get(count)); + } + return objectArray; + } + + private Object createPrimitiveArray(Class fieldType, List values) { + if (fieldType.isPrimitive()) { + if (fieldType.getName().equals("int")) { + int[] primitiveValues = new int[values.size()]; + for (int count = 0; count < values.size(); ++count) { + primitiveValues[count] = ((Integer) values.get(count)).intValue(); + } + return primitiveValues; + } else if (fieldType.getName().equals("float")) { + float[] primitiveValues = new float[values.size()]; + for (int count = 0; count < values.size(); ++count) { + primitiveValues[count] = ((Float) values.get(count)).floatValue(); + } + return primitiveValues; + } else if (fieldType.getName().equals("boolean")) { + boolean[] primitiveValues = new boolean[values.size()]; + for (int count = 0; count < values.size(); ++count) { + primitiveValues[count] = ((Boolean) values.get(count)).booleanValue(); + } + return primitiveValues; + } else if (fieldType.getName().equals("char")) { + char[] primitiveValues = new char[values.size()]; + for (int count = 0; count < values.size(); ++count) { + primitiveValues[count] = ((Character) values.get(count)).charValue(); + } + return primitiveValues; + } else if (fieldType.getName().equals("byte")) { + byte[] primitiveValues = new byte[values.size()]; + for (int count = 0; count < values.size(); ++count) { + primitiveValues[count] = ((Byte) values.get(count)).byteValue(); + } + return primitiveValues; + } else if (fieldType.getName().equals("short")) { + short[] primitiveValues = new short[values.size()]; + for (int count = 0; count < values.size(); ++count) { + primitiveValues[count] = ((Short) values.get(count)).shortValue(); + } + return primitiveValues; + } else if (fieldType.getName().equals("long")) { + long[] primitiveValues = new long[values.size()]; + for (int count = 0; count < values.size(); ++count) { + primitiveValues[count] = ((Long) values.get(count)).longValue(); + } + return primitiveValues; + } else if (fieldType.getName().equals("double")) { + double[] primitiveValues = new double[values.size()]; + for (int count = 0; count < values.size(); ++count) { + primitiveValues[count] = ((Double) values.get(count)).doubleValue(); + } + return primitiveValues; + } + } + return values; + } + + public abstract String getText(T source) throws XML2JavaMapperException; + + public abstract List getChildElements(T parent) throws XML2JavaMapperException; + + public abstract String getElementName(T element) throws XML2JavaMapperException; + + public abstract boolean isTextElement(T element) throws XML2JavaMapperException; + + public abstract T getRootElement(T element) throws XML2JavaMapperException; + + public Class getTargetType() { + return Object.class; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/XML2JavaMapperException.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/XML2JavaMapperException.java new file mode 100644 index 0000000000..b7dee262c0 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/XML2JavaMapperException.java @@ -0,0 +1,74 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.databinding.javabeans; + +import javax.xml.namespace.QName; + +/** + * This exception is used to encapsulate and rethrow exceptions that arise out + * of converting XML Data to Java Objects. + */ +public class XML2JavaMapperException extends RuntimeException { + private static final long serialVersionUID = 6596530102591630642L; + + private QName xmlElementName; + private String javaFieldName; + private Class javaType; + + public XML2JavaMapperException(String message) { + super(message); + } + + public XML2JavaMapperException(Throwable cause) { + super(cause); + } + + public QName getXmlElementName() { + return xmlElementName; + } + + public void setXmlElementName(QName xmlElementName) { + this.xmlElementName = xmlElementName; + } + + public String getJavaFieldName() { + return javaFieldName; + } + + public void setJavaFieldName(String javaFieldName) { + this.javaFieldName = javaFieldName; + } + + public Class getJavaType() { + return javaType; + } + + public void setJavaType(Class javaType) { + this.javaType = javaType; + } + + @Override + public String getMessage() { + return super.getMessage() + " <" + getJavaFieldName() + "> " + " in <" + getJavaType() + ">"; + } + + + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/BeanUtil.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/BeanUtil.java new file mode 100644 index 0000000000..3ada634375 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/BeanUtil.java @@ -0,0 +1,196 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding.xml; + +import java.beans.BeanInfo; +import java.beans.Introspector; +import java.beans.PropertyDescriptor; +import java.lang.reflect.Array; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.sca.databinding.impl.SimpleTypeMapperImpl; +import org.apache.tuscany.sca.interfacedef.util.TypeInfo; + +public final class BeanUtil { + private static final Object[] NULL = (Object[])null; + private static int nsCount = 1; + + private static final SimpleTypeMapperImpl MAPPER = new SimpleTypeMapperImpl(); + + private BeanUtil() { + } + + private static boolean isSimpleType(Class javaType) { + return MAPPER.getXMLType(javaType) != null; + } + + private static String getStringValue(Object o) { + if (o == null) { + return null; + } + TypeInfo info = MAPPER.getXMLType(o.getClass()); + if (info != null) { + return MAPPER.toXMLLiteral(info.getQName(), o, null); + } else { + return String.valueOf(o); + } + } + + /** + * To Serilize Bean object this method is used, this will create an object + * array using given bean object + * + * @param beanObject + * @param beanName + */ + public static XMLStreamReader getXMLStreamReader(Object beanObject, QName beanName) { + try { + ClassLoader cl = beanObject.getClass().getClassLoader(); + if (cl == null) { + cl = ClassLoader.getSystemClassLoader(); + } + String beanNS = beanName.getNamespaceURI(); + String beanPrefix = beanName.getPrefix(); + BeanInfo beanInfo = Introspector.getBeanInfo(beanObject.getClass()); + PropertyDescriptor[] propDescs = beanInfo.getPropertyDescriptors(); + Map propertMap = new HashMap(); + for (int i = 0; i < propDescs.length; i++) { + PropertyDescriptor propDesc = propDescs[i]; + propertMap.put(propDesc.getName(), propDesc); + } + List properties = new ArrayList(propertMap.keySet()); + Collections.sort(properties); + List props = new ArrayList(); + for (int i = 0; i < properties.size(); i++) { + String property = properties.get(i); + PropertyDescriptor propDesc = (PropertyDescriptor)propertMap.get(property); + if (propDesc == null) { + // JAM does bad thing so I need to add this + continue; + } + Class ptype = propDesc.getPropertyType(); + if ("class".equals(property)) { + continue; + } + if (isSimpleType(ptype)) { + Object value = propDesc.getReadMethod().invoke(beanObject, NULL); + NamedProperty prop = + new NamedProperty(new QName(beanNS, property, beanPrefix), getStringValue(value)); + props.add(prop); + } else if (ptype.isArray()) { + if (isSimpleType(ptype.getComponentType())) { + Object value = propDesc.getReadMethod().invoke(beanObject, NULL); + if (value != null) { + int i1 = Array.getLength(value); + for (int j = 0; j < i1; j++) { + Object o = Array.get(value, j); + NamedProperty prop = + new NamedProperty(new QName(beanNS, property, beanPrefix), getStringValue(o)); + props.add(prop); + } + } else { + NamedProperty prop = new NamedProperty(new QName(beanNS, property, beanPrefix), value); + props.add(prop); + } + + } else { + Object value[] = (Object[])propDesc.getReadMethod().invoke(beanObject, NULL); + if (value != null) { + for (int j = 0; j < value.length; j++) { + Object o = value[j]; + NamedProperty prop = + new NamedProperty(new QName(beanNS, property, beanPrefix), getStringValue(o)); + props.add(prop); + } + } else { + NamedProperty prop = new NamedProperty(new QName(beanNS, property, beanPrefix), value); + props.add(prop); + } + } + } else if (Collection.class.isAssignableFrom(ptype)) { + Object value = propDesc.getReadMethod().invoke(beanObject, NULL); + Collection objList = (Collection)value; + if (objList != null && objList.size() > 0) { + // this was given error , when the array.size = 0 + // and if the array contain simple type , then the + // ADBPullParser asked + // PullParser from That simpel type + for (Iterator j = objList.iterator(); j.hasNext();) { + Object o = j.next(); + if (isSimpleType(o.getClass())) { + NamedProperty prop = + new NamedProperty(new QName(beanNS, property, beanPrefix), getStringValue(o)); + props.add(prop); + } else { + NamedProperty prop = new NamedProperty(new QName(beanNS, property, beanPrefix), o); + props.add(prop); + } + } + + } else { + NamedProperty prop = new NamedProperty(new QName(beanNS, property, beanPrefix), value); + props.add(prop); + } + } else { + Object value = propDesc.getReadMethod().invoke(beanObject, NULL); + NamedProperty prop = new NamedProperty(new QName(beanNS, property, beanPrefix), value); + props.add(prop); + } + } + NamedProperty[] elements = new NamedProperty[props.size()]; + props.toArray(elements); + return new XMLFragmentStreamReaderImpl(beanName, elements, null); + } catch (Exception e) { + throw new IllegalArgumentException(e); + } + } + + /** + * to get the pull parser for a given bean object , generate the wrpper + * element using class name + * + * @param beanObject + */ + public static XMLStreamReader getXMLStreamReader(Object beanObject) { + String className = beanObject.getClass().getName(); + if (className.indexOf(".") > 0) { + className = className.substring(className.lastIndexOf('.') + 1, className.length()); + } + return getXMLStreamReader(beanObject, new QName(className)); + } + + /** + * increments the namespace counter and returns a new prefix + * + * @return unique prefix + */ + public static String getUniquePrefix() { + return "s" + nsCount++; + } + +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/DOMDataBinding.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/DOMDataBinding.java new file mode 100644 index 0000000000..605d769fda --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/DOMDataBinding.java @@ -0,0 +1,51 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding.xml; + + +import org.apache.tuscany.sca.databinding.WrapperHandler; +import org.apache.tuscany.sca.databinding.impl.BaseDataBinding; +import org.w3c.dom.Node; + +/** + * DOM DataBinding + * + * @version $Rev$ $Date$ + */ +public class DOMDataBinding extends BaseDataBinding { + public static final String NAME = Node.class.getName(); + public static final String[] ALIASES = new String[] {"dom"}; + + public DOMDataBinding() { + super(NAME, ALIASES, Node.class); + } + + @Override + public WrapperHandler getWrapperHandler() { + return new DOMWrapperHandler(); + } + + public Object copy(Object source) { + if (Node.class.isAssignableFrom(source.getClass())) { + Node nodeSource = (Node) source; + return nodeSource.cloneNode(true); + } + return super.copy(source); + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/DOMWrapperHandler.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/DOMWrapperHandler.java new file mode 100644 index 0000000000..1bb6277934 --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/DOMWrapperHandler.java @@ -0,0 +1,78 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.databinding.xml; + +import java.util.ArrayList; +import java.util.List; + +import javax.xml.namespace.QName; +import javax.xml.parsers.ParserConfigurationException; + +import org.apache.tuscany.sca.databinding.TransformationContext; +import org.apache.tuscany.sca.databinding.TransformationException; +import org.apache.tuscany.sca.databinding.WrapperHandler; +import org.apache.tuscany.sca.databinding.impl.DOMHelper; +import org.apache.tuscany.sca.interfacedef.util.ElementInfo; +import org.w3c.dom.Document; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +public class DOMWrapperHandler implements WrapperHandler { + + private Document document; + + public DOMWrapperHandler() { + super(); + try { + this.document = DOMHelper.newDocument(); + } catch (ParserConfigurationException e) { + throw new TransformationException(e); + } + } + + public Node create(ElementInfo element, TransformationContext context) { + QName name = element.getQName(); + return DOMHelper.createElement(document, name); + } + + public void setChild(Node wrapper, int i, ElementInfo childElement, Object value) { + Node node = (Node) value; + if (node.getNodeType() == Node.DOCUMENT_NODE) { + node = ((Document) node).getDocumentElement(); + } + wrapper.appendChild(wrapper.getOwnerDocument().importNode(node, true)); + } + + public List getChildren(Node wrapper) { + assert wrapper != null; + if (wrapper.getNodeType() == Node.DOCUMENT_NODE) { + wrapper = ((Document) wrapper).getDocumentElement(); + } + List elements = new ArrayList(); + NodeList nodes = wrapper.getChildNodes(); + for (int j = 0; j < nodes.getLength(); j++) { + Node node = nodes.item(j); + if (node.getNodeType() == Node.ELEMENT_NODE) { + elements.add(node); + } + } + return elements; + } +} \ No newline at end of file diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/DOMXMLStreamReader.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/DOMXMLStreamReader.java new file mode 100644 index 0000000000..e377dd1d8b --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/DOMXMLStreamReader.java @@ -0,0 +1,129 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding.xml; + +import static javax.xml.XMLConstants.DEFAULT_NS_PREFIX; +import static javax.xml.XMLConstants.XMLNS_ATTRIBUTE_NS_URI; + +import java.util.ArrayList; +import java.util.List; + +import javax.xml.namespace.QName; + +import org.w3c.dom.Attr; +import org.w3c.dom.CharacterData; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NamedNodeMap; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +public class DOMXMLStreamReader extends XMLFragmentStreamReaderImpl { + private Element rootElement; + + public DOMXMLStreamReader(Node node) { + super(null); + switch (node.getNodeType()) { + case Node.DOCUMENT_NODE: + this.rootElement = ((Document)node).getDocumentElement(); + break; + case Node.ELEMENT_NODE: + this.rootElement = (Element)node; + break; + default: + throw new IllegalArgumentException("Illegal Node"); + } + String ns = rootElement.getNamespaceURI(); + String prefix = rootElement.getPrefix(); + String name = rootElement.getLocalName(); + elementQName = new QName(ns == null ? "" : ns, name, prefix == null ? "" : prefix); + } + + @Override + protected final NamedProperty[] getAttributes() { + if (attributes == null) { + List attributeList = new ArrayList(); + NamedNodeMap nodeMap = rootElement.getAttributes(); + for (int i = 0; i < nodeMap.getLength(); i++) { + Attr attr = (Attr)nodeMap.item(i); + String ns = attr.getNamespaceURI(); + String prefix = attr.getPrefix(); + if (!XMLNS_ATTRIBUTE_NS_URI.equals(ns)) { + QName attrName = new QName(ns == null ? "" : ns, attr.getLocalName(), prefix != null ? prefix : ""); + NamedProperty pair = new NamedProperty(attrName, attr.getValue()); + attributeList.add(pair); + } + } + attributes = new NamedProperty[attributeList.size()]; + attributeList.toArray(attributes); + } + return attributes; + } + + @Override + protected QName[] getNamespaces() { + List nsList = new ArrayList(); + NamedNodeMap nodeMap = rootElement.getAttributes(); + for (int i = 0; i < nodeMap.getLength(); i++) { + Attr attr = (Attr)nodeMap.item(i); + String ns = attr.getNamespaceURI(); + if (XMLNS_ATTRIBUTE_NS_URI.equals(ns)) { + String prefix = attr.getPrefix(); + if (prefix == null) { + // xmlns="http://ns" + nsList.add(new QName(attr.getValue(), "", DEFAULT_NS_PREFIX)); + } else { + // xmlns:ns="http://ns" + nsList.add(new QName(attr.getValue(), "", attr.getLocalName())); + } + } + } + QName[] nss = new QName[nsList.size()]; + nsList.toArray(nss); + return nss; + } + + @Override + protected NamedProperty[] getElements() { + if (elements == null) { + List elementList = new ArrayList(); + NodeList nodeList = rootElement.getChildNodes(); + for (int i = 0; i < nodeList.getLength(); i++) { + Node node = nodeList.item(i); + switch (node.getNodeType()) { + case Node.TEXT_NODE: + case Node.CDATA_SECTION_NODE: + NamedProperty pair = new NamedProperty(ELEMENT_TEXT, ((CharacterData)node).getData()); + elementList.add(pair); + break; + + case Node.ELEMENT_NODE: + Element element = (Element)node; + QName elementName = new QName(element.getNamespaceURI(), element.getLocalName()); + pair = new NamedProperty(elementName, new DOMXMLStreamReader(element)); + elementList.add(pair); + break; + } + } + elements = new NamedProperty[elementList.size()]; + elementList.toArray(elements); + } + return elements; + } +} diff --git a/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/DelegatingNamespaceContext.java b/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/DelegatingNamespaceContext.java new file mode 100644 index 0000000000..2f63f932ea --- /dev/null +++ b/sca-java-1.x/branches/sca-java-0.91/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/DelegatingNamespaceContext.java @@ -0,0 +1,310 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.sca.databinding.xml; + +import java.util.ArrayList; +import java.util.EmptyStackException; +import java.util.Iterator; +import java.util.List; + +import javax.xml.namespace.NamespaceContext; + +public class DelegatingNamespaceContext implements NamespaceContext { + private static int count; + + private class WrappingIterator implements Iterator { + + private Iterator containedIterator; + + public WrappingIterator(Iterator containedIterator) { + this.containedIterator = containedIterator; + } + + public Iterator getContainedIterator() { + return containedIterator; + } + + public boolean hasNext() { + return containedIterator.hasNext(); + } + + public Object next() { + return containedIterator.next(); + } + + /** + * As per the contract on the API of Namespace context the returned iterator should be immutable + */ + public void remove() { + throw new UnsupportedOperationException(); + } + + public void setContainedIterator(Iterator containedIterator) { + this.containedIterator = containedIterator; + } + } + + private NamespaceContext parentNsContext; + + private FastStack prefixStack = new FastStack(); + + // Keep two arraylists for the prefixes and namespaces. They should be in + // sync + // since the index of the entry will be used to relate them + // use the minimum initial capacity to let things handle memory better + + private FastStack uriStack = new FastStack(); + + /** + * Generates a unique namespace prefix that is not in the scope of the NamespaceContext + * + * @return string + */ + public String generateUniquePrefix() { + String prefix = "p" + count++; + // null should be returned if the prefix is not bound! + while (getNamespaceURI(prefix) != null) { + prefix = "p" + count++; + } + + return prefix; + } + + public String getNamespaceURI(String prefix) { + // do the corrections as per the javadoc + int index = prefixStack.search(prefix); + if (index != -1) { + return (String)uriStack.get(index); + } + if (parentNsContext != null) { + return parentNsContext.getPrefix(prefix); + } + return null; + } + + public NamespaceContext getParentNsContext() { + return parentNsContext; + } + + public String getPrefix(String uri) { + // do the corrections as per the javadoc + int index = uriStack.search(uri); + if (index != -1) { + return (String)prefixStack.get(index); + } + + if (parentNsContext != null) { + return parentNsContext.getPrefix(uri); + } + return null; + } + + public Iterator getPrefixes(String uri) { + // create an arraylist that contains the relevant prefixes + String[] uris = (String[])uriStack.toArray(new String[uriStack.size()]); + List tempList = new ArrayList(); + for (int i = uris.length - 1; i >= 0; i--) { + if (uris[i].equals(uri)) { + tempList.add(prefixStack.get(i)); + // we assume that array conversion preserves the order + } + } + // by now all the relevant prefixes are collected + // make a new iterator and provide a wrapper iterator to + // obey the contract on the API + return new WrappingIterator(tempList.iterator()); + } + + /** + * Pop a namespace + */ + public void popNamespace() { + prefixStack.pop(); + uriStack.pop(); + } + + /** + * Register a namespace in this context + * + * @param prefix + * @param uri + */ + public void pushNamespace(String prefix, String uri) { + prefixStack.push(prefix); + uriStack.push(uri); + + } + + public void setParentNsContext(NamespaceContext parentNsContext) { + this.parentNsContext = parentNsContext; + } + + /** + * An implementation of the {@link java.util.Stack} API that is based on an ArrayList instead of a + * Vector, so it is not synchronized to protect against multi-threaded access. The implementation is + * therefore operates faster in environments where you do not need to worry about multiple thread contention. + *

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

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

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